terraform
The atago project wrote these specs on its own initiative and runs them in its own CI, to exercise atago against a real program. They are not terraform’s official test suite, and the terraform project is not affiliated with atago.
Summary #
1 suite · 6 scenarios
Contents #
terraform (offline via the builtin terraform_data resource) #
Terraform’s exit codes are not a detail — they are the interface CI
pipelines are built on. terraform plan -detailed-exitcode answers with 0
for “nothing to do”, 2 for “there are changes”, and 1 for “it failed”, and a
pipeline that confuses 2 with 1 either blocks on every change or deploys
through every error.
That three-way contract is what this suite pins, alongside the ordinary path through init, validate, plan, and apply.
It stays entirely offline by using only Terraform’s builtin
terraform_data resource, so init downloads no providers and no network
access is needed to run any of it.
Source: test/e2e/thirdparty/terraform/terraform.atago.yaml
Scenario: init downloads nothing and validate reports valid #
only when terraform version succeeds
Given #
- Fixture file
main.tfis created.
Inputs #
Fixture main.tf:
resource "terraform_data" "greeting" {
input = "hello from atago"
}
output "message" {
value = terraform_data.greeting.output
}
When #
terraform init
terraform validate -json
Then #
- after
terraform init:- exit code is
0 - stdout does not contain
Downloading
- exit code is
- after
terraform validate -json:- exit code is
0 - stdout at
$.validequalstrue
- exit code is
Scenario: plan -detailed-exitcode reports the change contract #
only when terraform version succeeds
Given #
- Fixture file
main.tfis created.
Inputs #
Fixture main.tf:
resource "terraform_data" "greeting" {
input = "hello from atago"
}
output "message" {
value = terraform_data.greeting.output
}
When #
terraform init
terraform plan -detailed-exitcode
terraform apply -auto-approve
terraform plan -detailed-exitcode
Then #
- after
terraform init:- exit code is
0
- exit code is
- after
terraform plan -detailed-exitcode:- exit code is one of
2
- exit code is one of
- after
terraform apply -auto-approve:- exit code is
0
- exit code is
- after
terraform plan -detailed-exitcode:- exit code is
0
- exit code is
Scenario: apply exposes state JSON and a captured output #
only when terraform version succeeds
Given #
- Fixture file
main.tfis created.
Inputs #
Fixture main.tf:
resource "terraform_data" "greeting" {
input = "hello from atago"
}
output "message" {
value = terraform_data.greeting.output
}
When #
terraform init
terraform apply -auto-approve
terraform show -json
terraform output -raw message
# capture ${message} from stdout
echo captured: ${message}
Then #
- after
terraform init:- exit code is
0
- exit code is
- after
terraform apply -auto-approve:- exit code is
0
- exit code is
- after
terraform show -json:- exit code is
0 - stdout at
$.values.root_module.resources[0].addressequalsterraform_data.greeting
- exit code is
- after
echo captured: ${message}:- exit code is
0 - stdout contains
captured: hello from atago
- exit code is
Scenario: destroy empties the state #
only when terraform version succeeds
Given #
- Fixture file
main.tfis created.
Inputs #
Fixture main.tf:
resource "terraform_data" "greeting" {
input = "hello from atago"
}
When #
terraform init
terraform apply -auto-approve
terraform destroy -auto-approve
terraform show -json
Then #
- after
terraform init:- exit code is
0
- exit code is
- after
terraform apply -auto-approve:- exit code is
0
- exit code is
- after
terraform destroy -auto-approve:- exit code is
0
- exit code is
- after
terraform show -json:- exit code is
0 - stdout does not contain
terraform_data.greeting
- exit code is
Scenario: fmt -check exits 3 on a misformatted file #
only when terraform version succeeds
Given #
- Fixture file
messy.tfis created.
Inputs #
Fixture messy.tf:
output "x" {
value="terraform_data"
}
When #
terraform fmt -check messy.tf
Then #
- exit code is one of
3
Scenario: a broken configuration is rejected #
only when terraform version succeeds
Given #
- Fixture file
main.tfis created.
Inputs #
Fixture main.tf:
resource "terraform_data" "broken" {
input =
}
When #
terraform plan
Then #
- exit code is one of
1 - stderr contains
Error: