dumitrux / terraform-testing

Terratest and Terraform Tests for automating tests on the infrastructure as code developed with Terraform

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Terraform Testing

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.

Table of Contents

Module Container App

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:

Testing tools

Terraform Tests

Example output from GitHub Actions: terraform-tests-output.png

Terratest

Example output from GitHub Actions: terratest-output.png

Recording test results

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.

Deploy examples

Workflows Approve deployments (TO-DO)

Manually deploy examples

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"

Examples configurations

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"

Examples cases

cd examples_cases/startup

terraform init
terraform plan

terraform apply -auto-approve
terraform output

terraform destroy 

About

Terratest and Terraform Tests for automating tests on the infrastructure as code developed with Terraform


Languages

Language:HCL 88.7%Language:Go 11.3%