Terraform configurations
Encyclopedia home · Search machine-readable catalog
CF-046
Terraform required version
Copy to versions.tf.
terraform {
required_version = ">= 1.10, < 2.0"
}Verification. Run terraform version and ensure CI uses an approved version in this range.
Validation untested. Official reference
CF-047
Terraform provider constraint
Copy to providers.tf.
terraform {
required_providers {
aws = {
source = "hashicorp/aws"
version = "~> 5.0"
}
}
}Verification. Commit provider lockfile after init. Verify approved registry and hashes.
Validation untested. Official reference
CF-048
Use a validated deployment variable
Copy to variables.tf.
variable "environment" {
type = string
validation {
condition = contains(["sandbox", "staging"], var.environment)
error_message = "Choose sandbox or staging."
}
}Verification. Prove an unexpected environment fails terraform plan.
Validation untested. Official reference
CF-049
Cloud owner tags
Copy to main.tf fragment.
locals {
common_tags = { ManagedBy = "terraform", Environment = var.environment }
}Verification. Merge local.common_tags into resources and test tags in the plan.
Validation untested. Official reference
CF-050
Locking remote state
Copy to backend.tf.
terraform {
backend "s3" {
bucket = "replace-dedicated-state-bucket"
region = "eu-west-2"
key = "sandbox/web.tfstate"
encrypt = true
use_lockfile = true
}
}Verification. Pre-provision bucket with restricted IAM and versioning. Use a compatible Terraform release.
Validation untested. Official reference
CF-051
State-free fixture resource
Copy to main.tf.
resource "terraform_data" "fixture" {
input = { service = "web", port = 8000 }
}Verification. Plan in a local temp directory without provider credentials. Use it for module test examples.
Validation untested. Official reference
CF-052
Plan-only Terraform test
Copy to tests/infra.tftest.hcl.
run "fixture_plan" {
command = plan
assert {
condition = terraform_data.fixture.input.port == 8000
error_message = "Fixture port must be 8000."
}
}Verification. Pair with the state-free fixture resource and run terraform test.
Validation untested. Official reference
CF-053
Sensitive string contract
Copy to variables.tf fragment.
variable "bootstrap_token" {
type = string
sensitive = true
nullable = false
}Verification. Sensitive values can still appear in plan and state. Restrict both to authorized roles.
Validation untested. Official reference
CF-054
Expose a safe service output
Copy to outputs.tf.
output "service_port" {
value = terraform_data.fixture.input.port
}Verification. Pair with the fixture resource and verify terraform output -json after isolated apply.
Validation untested. Official reference
CF-055
Version a local module input
Copy to main.tf.
module "service" {
source = "./modules/service"
name = "web"
}Verification. Supply a module with declared name and tests. Review its version along with the caller commit.
Validation untested. Official reference