Under active development Content is continuously updated and improved

Terraform

by HashiCorp

Infrastructure as Code (IaC) tool for provisioning and managing cloud resources with state management and secrets handling

Official Docs

Under Construction: This guidance is being actively developed and verified. Content may change.

Authoritative Sources

Key guidance documents from authoritative organizations. Click to view the original source.

NIST SSDF PS.3.1: "Store all forms of code—including source code, executable code, and configuration-as-code—based on the principle of least privilege so that only authorized personnel, tools, services, etc. have access." PO.3.2: "Collect, safeguard, maintain, and share provenance data for all components of each software release." PW.6.1: "Create secure configurations for software development processes, tools, and infrastructure, including at least secure configuration of source code repository, security features of the development IDEs, and secrets management." Terraform state files should be secured following SSDF PS.3.1 principles.

Configuration Examples(2)

·

Official HashiCorp guidance: "Terraform state and plan files contain detailed information about your infrastructure, including resource attributes and metadata that can contain sensitive values. Treat your state file as sensitive data by excluding it from Git workflows and following security recommendations."

Configuration Examples(4)

·

CIS provides benchmarks for cloud platforms (AWS, Azure, GCP) that can be enforced through Terraform configurations. Terraform enables consistent deployment of CIS-compliant infrastructure.

Configuration Examples(2)

·

SOC 2 CC8.1: "The entity authorizes, designs, develops or acquires, configures, documents, tests, approves, and implements changes to infrastructure, data, software, and procedures to meet its objectives." Terraform provides Infrastructure as Code with version control, plan/apply workflows, and state management that directly support CC8.1 change management requirements. Source: AICPA Trust Services Criteria.

ISO 27001:2022 A.8.9: "Configurations, including security configurations, of hardware, software, services and networks shall be established, documented, implemented, monitored and reviewed." Terraform enables declarative infrastructure configuration management with version control and drift detection, implementing A.8.9 requirements. Source: ISO/IEC 27001:2022 Annex A.

Verification Commands

Commands and queries for testing and verifying security configurations.

Initialize Terraform with backend CLI
terraform init -backend-config="backend.hcl"
Validate configuration syntax CLI
terraform validate
Plan with variable file (don't commit tfvars with secrets) CLI
terraform plan -var-file="secrets.tfvars" -out=plan.tfplan
Apply with auto-approve (use in CI/CD only) CLI
terraform apply -auto-approve plan.tfplan
Check state for sensitive values CLI
terraform show -json | jq ".values.root_module.resources[].values | keys"
List state resources CLI
terraform state list
Run tfsec security scanner CLI
tfsec . --format json
Run Checkov IaC security scan CLI
checkov -d . --framework terraform --output json
Run Trivy IaC misconfiguration scan CLI
trivy config --severity HIGH,CRITICAL .
Detect drift from state CLI
terraform plan -detailed-exitcode
Remove sensitive resource from state CLI
terraform state rm aws_db_instance.sensitive
Import existing resource into state CLI
terraform import aws_s3_bucket.example bucket-name

Related Controls

Security controls from various frameworks that relate to Terraform.

Related Technologies