This repository showcases different levels of testing for Infrastructure as Code using Terraform. Within the test directories, there are examples of Unit, Integration, and End-To-End tests employing both Terraform's built-in testing feature and the Terratest tool.
Tests are conducted on a module serving as an illustrative example. This module represents an Azure Container App and is based after Microsoft's examples:
- Azure Container Apps overview | Microsoft Learn.
- Example in Azure/terraform-azure-container-apps: A Terraform module to deploy a container app in Azure (github.com)
- This example uses workflows and scripts from tfmod-scaffold/scripts at main · Azure/tfmod-scaffold (github.com)
- Official documentation: Write Terraform Tests | Terraform | HashiCorp Developer
- Code directory: tests
- Workflow file: terraform_tests.yaml
Example output from GitHub Actions:
- Official documentation:
- Code directory: terratest
- Workflow file: terratest.yaml
Example output from GitHub Actions:
In certain scenarios, it could be beneficial to maintain a record of the test outcomes for each example whenever new releases occur. This practice becomes particularly relevant in cases where there might be bugs in the Terraform provider or certain edge cases that are safe to ignore but they should be tracked. For instance, this can be done by adding the file examples_cases/acr/TestRecord.md
that includes the date, release version, indication of test success, and any encountered errors, if applicable.
This documentation can be supplemented by a docs/CHANGELOG.md
file outlining the modifications made in each release version, providing insight into the reasons behind the changes and test results.
export ARM_CLIENT_ID="00000000-0000-0000-0000-000000000000"
export ARM_CLIENT_SECRET="0000000000000000000000000000000000000000000"
export ARM_TENANT_ID="00000000-0000-0000-0000-000000000000"
export ARM_SUBSCRIPTION_ID="00000000-0000-0000-0000-000000000000"
cd examples_config/deployment
terraform init
terraform plan -var-file="../configurations/default.tfvars"
terraform apply -var-file="../configurations/default.tfvars"
terraform output
terraform destroy -var-file="../configurations/default.tfvars"
cd examples_cases/startup
terraform init
terraform plan
terraform apply -auto-approve
terraform output
terraform destroy