The following repository is a showcase how Terraform infrastructure code can be verified using unit and integration tests backed by Terratest.
Both unit and integration test examples are presented in the repository.
The way unit tests are working is to inspect output generated by the terraform plan
command.
On the other hand integration one is based on terraform apply
execution and real resource creation on an AWS account configured in the AWS CLI.
The demo code have been tested using the following versions of tools:
- Terraform 1.0.8
- Go 1.17.5
The required tools have to be installed along to their corresponding instructions:
- Terraform - https://learn.hashicorp.com/tutorials/terraform/install-cli
- Go - https://go.dev/doc/install
AWS CLI has to be configured in a current terminal session where Terratest tests will be performed (CLI related variables AWS_ACCESS_KEY_ID
, AWS_SECRET_ACCESS_KEY
and AWS_REGION
have to be properly set).
To execute an example unit test run the following command from the <repository_root>/test
directory:
go test -v example_infrastructure_unit_test.go
To execute an example integration test run the following command from the <repository_root>/test
directory:
go test -v example_infrastructure_integration_test.go