Write a native test for a module that creates an encrypted S3 bucket.
IntermediateScenarioTesting Upgrades and Large-Scale Operations
Answer
Situation read → Use terraform test at plan level for fast feedback.
What I'd do →
# tests/bucket.tftest.hcl
variables {
name = "acme-test-bucket"
}
run "bucket_is_encrypted" {
command = plan
assert {
condition = aws_s3_bucket_server_side_encryption_configuration.this.rule[0].apply_server_side_encryption_by_default[0].sse_algorithm == "aws:kms"
error_message = "Bucket must use KMS encryption."
}
}
Run with terraform test.
Why → Plan-mode tests don't create anything, so they run on every PR without cost.
Interview tip → Use mock_provider (1.7+) to avoid needing credentials.
More on Testing Upgrades and Large-Scale Operations
What does each of `terraform validate`, `plan` and `terraform test` actually check?BeginnerCompare Terratest with `terraform test`.IntermediateReal-cloud integration tests leave orphaned resources when they fail midway. How do you handle that?AdvancedHow do you upgrade from Terraform 1.5 to 1.9 safely?IntermediateMajor AWS provider upgrade from v4 to v5 (or v5 to v6) across many stacks. How do you plan it?AdvancedA stack is still on Terraform 0.12 syntax and old providers. What upgrade path do you follow?Advanced