Testing the Terraform configuration using Python
In the previous recipe, we learned how to write Terraform tests using a PowerShell script and the Pester framework.
In this recipe, we will learn the same concept for Terraform tests by using the Python language and pytest
framework.
With pytest
, the tests are executed just after the terraform plan
command and before terraform apply
, so that if the tests are failing, apply
will not continue.
Let’s get started!
Getting ready
To complete this recipe, you’ll need to know some basic knowledge of Python.
We need to have Python already installed with pip. The installation documentation for Python is available here: https://www.python.org/downloads/. And pip’s installation documentation is available here: https://pip.pypa.io/en/stable/installation/.
We also install the pytest
Python test framework by using pip with the pip install pytest
command.
For more information about pytest...