Terraform & IaC
Security — Shift Left Controls
Comprehensive reference for securing Infrastructure-as-Code pipelines. Covers top Terraform misconfigurations, tfsec and Checkov rule mapping, secure HCL patterns, and CI/CD security gate implementation for AWS, Azure, and GCP.
Missing aws_s3_bucket_public_access_block resource or block_public_acls set to false allows public read/write access to S3 buckets.
Ingress rule with cidr_blocks = ["0.0.0.0/0"] on SSH (22), RDP (3389), or all ports exposes instances to the internet.
Managed disks, RDS instances, and block storage without explicit encryption configuration rely on default settings which may not use CMK.
Setting publicly_accessible = true on RDS exposes the database endpoint to the internet. Always use private subnets with security group access only from application tier.
Missing CloudTrail resource or enable_logging = false disables API call logging — attackers' first action after gaining access.
enable_https_traffic_only = false allows unencrypted HTTP access to Azure storage. Always enforce HTTPS for all storage accounts.
Assigning roles/editor or roles/owner to a service account violates least privilege. Stolen key = project-wide access.
Secrets in .tf files or terraform.tfvars get committed to git. State files also capture secrets in plain text — use remote state with encryption.
tfsec (now part of Trivy) is the most popular Terraform-specific static analysis tool. Run it locally or in CI/CD to catch misconfigurations before apply.
| Rule ID | Description | Severity | Provider |
|---|---|---|---|
| aws-s3-block-public-acls | S3 bucket should have public access block configured | Critical | AWS |
| aws-s3-enable-bucket-encryption | S3 bucket should have encryption at rest enabled | High | AWS |
| aws-s3-enable-bucket-logging | S3 bucket should have logging enabled | Medium | AWS |
| aws-ec2-no-public-ingress-sgr | Security group rule should not permit ingress from 0.0.0.0/0 | Critical | AWS |
| aws-ec2-require-vpc-flow-logs-for-all-vpcs | VPC Flow Logs should be enabled for all VPCs | High | AWS |
| aws-cloudtrail-enable-all-regions | CloudTrail should be enabled in all regions | High | AWS |
| aws-cloudtrail-enable-log-validation | CloudTrail log file validation should be enabled | High | AWS |
| aws-rds-no-public-db-access | RDS should not be publicly accessible | Critical | AWS |
| aws-kms-auto-rotate-keys | KMS keys should be set to rotate automatically | Medium | AWS |
| azure-storage-enforce-https | Storage account HTTPS-only traffic should be enforced | High | Azure |
| azure-storage-no-public-access | Storage container should not be publicly exposed | Critical | Azure |
| azure-keyvault-ensure-secret-expiry | Key Vault secrets should have expiry dates | Medium | Azure |
| azure-network-no-public-ingress | NSG inbound rule should not allow ALL inbound | Critical | Azure |
| google-storage-no-public-access | Cloud Storage bucket should not be publicly accessible | Critical | GCP |
| google-compute-no-public-ingress | Firewall rule should not allow ingress from 0.0.0.0/0 | Critical | GCP |
| google-iam-no-project-level-service-account-impersonation | SA should not have project-level actAs permission | High | GCP |
Checkov by Prisma Cloud scans Terraform, CloudFormation, Kubernetes, Dockerfile, and ARM templates. 1000+ built-in checks, extensible with Python custom policies.
| Check ID | What It Checks | Resource |
|---|---|---|
| CKV_AWS_18 | Ensure S3 bucket has access logging enabled | aws_s3_bucket |
| CKV_AWS_19 | Ensure S3 bucket has server-side encryption enabled | aws_s3_bucket |
| CKV_AWS_20 | Ensure S3 bucket ACL does not allow public read | aws_s3_bucket |
| CKV_AWS_21 | Ensure S3 bucket has versioning enabled | aws_s3_bucket |
| CKV_AWS_25 | Ensure no security groups allow ingress from 0.0.0.0/0 to port 3389 | aws_security_group |
| CKV_AWS_24 | Ensure no security groups allow ingress from 0.0.0.0/0 to port 22 | aws_security_group |
| CKV_AWS_8 | Ensure AWS instances are not publicly exposed | aws_instance |
| CKV_AWS_17 | Ensure RDS database is not publicly accessible | aws_db_instance |
| CKV_AWS_16 | Ensure RDS database has encryption enabled at-rest | aws_db_instance |
| CKV_AWS_67 | Ensure CloudTrail multi-region is enabled | aws_cloudtrail |
| CKV_AWS_36 | Ensure CloudTrail log file validation is enabled | aws_cloudtrail |
| CKV_AZURE_3 | Ensure Azure storage account allows HTTPS traffic only | azurerm_storage_account |
| CKV_AZURE_6 | Ensure Azure SQL server enables AuditingPolicy | azurerm_sql_server |
| CKV_AZURE_35 | Ensure Azure Key Vault is recoverable | azurerm_key_vault |
| CKV_GCP_28 | Ensure GCS bucket does not allow public access | google_storage_bucket |
| CKV_GCP_62 | Ensure Cloud Audit Logging is configured for all services | google_project_iam_audit_config |
| CKV2_GCP_5 | Ensure GCP default service account not used at project level | google_project_iam_binding |
Remote State with Encryption
Variables — No Secrets in .tfvars
Least Privilege IAM Role Pattern
Pre-commit Hook — tfsec + Checkov
🔍 IaC Security Findings Generator
Select your cloud provider and Terraform resources. Get simulated findings with severity ratings, tfsec/Checkov rule IDs, and fix recommendations.