Terraform Compliance is a static code analysis tool that tests Terraform plans against Behavior Driven Development (BDD) Features and Scenarios. The language is based on Gherkin. However, terraform-compliance differs from Gherkin in that it interprets whole Gherkin phrases instead of just the "Given", "When", and "Then" statements.
This Proof of Concept (PoC) verifies the ability of Terraform Compliance to validate terraform code using a feature file.
(base) ralph@Alienware17r3L:~/Projects/terraform/terraform-docker-demo-2$ tree . ├── docker.tf ├── features │ └── ports_external.feature └── versions.tf 1 directory, 4 files |
File | Description |
---|---|
docker.tf | Terraform file to create wordpress and mysql interconnected microservices. |
features/ports_external.feature | Terraform Compliance feature file which validates that the Wordpress external port is set to 8081 |
versions.tf | Terraform file for initializing the provider |
Go to the working directory for this project
cd terraform-docker-demo-2/ |
Initialize Terraform
terraform init |
Run a Terraform plan, saving the output file
terraform plan -out wordpress.out |
Run terraform-compliance to validate that the Wordpress service has an external port set to 8081
terraform-compliance --features features --planfile wordpress.out |
In docker.tf, change the default port to 8081