5 Terraform Anti-Patterns That Still Bite Teams in 2026
Five Terraform anti-patterns still common in 2026, from hardcoded values to missing drift detection, and how to fix each with current Terraform features.
By VVVHQ Team ·
Infrastructure as code promised reproducible, version-controlled infrastructure. Plenty of teams still lose time to the same Terraform mistakes early adopters made. In the codebases we review, these five come up most often, and each one has a fix that is built into Terraform today.
1. Hardcoded values instead of variables and locals
Hardcoded AMI IDs, subnet IDs, instance sizes and tags spread across files mean that a region change or a new tagging rule turns into a search through the whole repository.
The problem:
resource "aws_instance" "web" {
ami = "ami-0c55b159cbfafe1f0"
instance_type = "t3.medium"
subnet_id = "subnet-0bb1c79de3EXAMPLE"
tags = {
Environment = "production"
Team = "platform"
}
}
The fix:
variable "instance_type" {
description = "EC2 instance type for the web tier"
type = string
default = "t3.medium"
validation {
condition = can(regex("^t3\\.", var.instance_type))
error_message = "Only t3 instance types are approved for this workload."
}
}
locals {
common_tags = {
Environment = var.environment
Team = var.team_name
ManagedBy = "terraform"
}
}
resource "aws_instance" "web" {
ami = data.aws_ami.ubuntu.id
instance_type = var.instance_type
subnet_id = var.subnet_id
tags = local.common_tags
}
Validation blocks turn a bad value into an error at plan time, before anything is applied. For tags that every resource needs, the AWS provider's default_tags setting does the same job as the local, without repeating it on each resource.
2. One large configuration instead of composable modules
A single root that defines networking, compute, databases and monitoring cannot be tested in parts or reused, and every plan touches everything. A 2,000-line main.tf is hard to review, and one bad change can affect the whole estate.
Split it into modules with clear inputs and outputs, and into separate root modules with separate state, so a change to monitoring cannot touch the database:
module "networking" {
source = "app.terraform.io/acme/networking/aws"
version = "~> 3.2"
vpc_cidr = var.vpc_cidr
environment = var.environment
}
module "database" {
source = "app.terraform.io/acme/rds-postgres/aws"
version = "~> 3.2.0"
subnet_ids = module.networking.private_subnet_ids
environment = var.environment
}
Publish modules to a private registry (HCP Terraform, Spacelift or another registry implementation) with semantic versioning. Know what the constraint allows: ~> 3.2 accepts any 3.x release from 3.2 upward, while ~> 3.2.0 accepts only patch releases of 3.2. Version constraints work only with registry sources. For modules pulled from Git, pin a tag with ?ref=v3.2.1.
Splitting an existing monolith is mostly state work, and moved blocks make it reviewable. On one engagement we split a Terraform monolith into 10 roots and moved 457 resources without destroying one.
3. Careless state management
State maps your configuration to real resources. Committing terraform.tfstate to Git, applying without a lock, or keeping state unencrypted leads to lost changes, race conditions and leaked secrets.
The problem:
# .gitignore does not exclude terraform.tfstate
# two people run terraform apply at the same time
# the state file holds database passwords in plain text
git add terraform.tfstate
git commit -m "update infra"
The fix:
terraform {
backend "s3" {
bucket = "acme-terraform-state"
key = "prod/networking/terraform.tfstate"
region = "us-east-1"
encrypt = true
kms_key_id = "alias/terraform-state"
use_lockfile = true # S3 native locking, Terraform 1.10+
}
}
The S3 backend now locks with a file in the bucket, and Terraform 1.11 deprecated the DynamoDB lock table.
Refactor state with configuration blocks instead of terraform state commands, so each change is reviewed in a pull request and shown in the plan. moved blocks (Terraform 1.1) rename or relocate resources, import blocks (1.5) bring existing resources under management, and removed blocks (1.7) stop managing a resource without destroying it:
import {
to = aws_s3_bucket.logs
id = "acme-access-logs-prod"
}
moved {
from = aws_instance.web
to = module.compute.aws_instance.web
}
4. Secrets in plain text
Database passwords in terraform.tfvars, API keys as variable defaults, and secrets in plan output all end up in Git history, CI logs, state files and laptops.
The problem:
variable "db_password" {
default = "SuperSecret123!" # committed to Git
}
resource "aws_db_instance" "primary" {
password = var.db_password
}
Reading the password from Secrets Manager with a data source is better than a default, but the value still lands in state. Keep it out of Terraform entirely where the provider allows it:
resource "aws_db_instance" "primary" {
# RDS creates the master password and keeps it in Secrets Manager.
# Terraform never sees it, so it is not in plan output or state.
manage_master_user_password = true
# other arguments omitted
}
Where a provider has no managed option, Terraform 1.11 write-only arguments (password_wo on aws_db_instance, for example) accept a value without storing it in state. Mark any remaining secret variables sensitive = true, which hides them from plan output but not from state. For encrypted variable files, use SOPS with age or KMS keys, and for runtime secrets, Vault through the vault provider.
The stakes are real: IBM's 2025 Cost of a Data Breach report puts the global average cost of a breach at $4.44 million.
5. No CI validation or drift detection
Someone changes a security group in the console, a script edits a resource, or a teammate applies without reviewing a plan. Without CI checks and drift detection, the code and the real infrastructure drift apart until the next apply shows a frightening diff.
The problem:
terraform apply -auto-approve
The fix is a pipeline that validates and plans every pull request and runs the same plan on a schedule to catch drift:
# .github/workflows/terraform.yml
on:
pull_request:
schedule:
- cron: "0 6 * * *" # daily drift check, 06:00 UTC
jobs:
plan:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- uses: hashicorp/setup-terraform@v3
# configure cloud credentials with OIDC here
- run: terraform init -input=false
- run: terraform validate
- id: plan
run: terraform plan -input=false -detailed-exitcode -out=plan.tfplan
continue-on-error: true # exit code 2 means changes, not failure
- run: terraform show -json plan.tfplan > plan.json
- run: conftest test plan.json --policy policies/
- name: Alert on drift
if: github.event_name == 'schedule' && steps.plan.outputs.exitcode == '2'
run: ./scripts/notify-drift.sh
On a scheduled run, exit code 2 means the infrastructure no longer matches the code. HCP Terraform and Spacelift offer drift detection as a built-in feature, and Atlantis runs plan and apply from pull request comments; our typical setup has Atlantis on every repository. Policies in OPA (through Conftest) or Sentinel enforce the guardrails: no public S3 buckets, no wildcard IAM, no untagged resources. Our post on Terraform drift detection in CI/CD covers the drift side in detail.
Where to start
Start with three checks: search the code for hardcoded AMI and subnet IDs, confirm the state backend is encrypted and locked, and verify that every pull request gets a terraform plan in CI. Those usually surface the most urgent gaps.
For a second opinion on your Terraform codebase, from module layout to state and CI, reach out.