"If the code looks right, apply it." Read the plan first. A one-line edit in Terraform can quietly destroy a resource and recreate it: change a database's engine, or a property that cannot be updated in place, and Terraform plans a replacement. The plan tells you. Skipping it is how production databases disappear.
What Terraform is
Terraform, from HashiCorp, is an infrastructure as code tool that works with AWS and many other platforms. You write configuration in HCL (HashiCorp Configuration Language). Like CloudFormation it is declarative: you describe what you want and Terraform works out the order. Unlike CloudFormation, it is not an AWS service; it runs wherever you run it, on a laptop or in a CI pipeline. HashiCorp changed Terraform's license to the Business Source License in 2023, and the community fork OpenTofu remains open source; both work with AWS.
The AWS provider
Terraform talks to AWS through the AWS provider. Each resource block, such as aws_s3_bucket or aws_db_instance, becomes AWS API calls. You describe the bucket; the provider makes the calls to create, update or delete it.
State, and keeping it safe
Terraform keeps a state file: its record of which real resources belong to which blocks in your code. Without it, Terraform cannot tell what it already built. Two rules:
- Store state remotely, typically in an S3 bucket with versioning and encryption, never only on one laptop. State can contain secrets, so restrict who can read it.
- Lock it. Since Terraform 1.10 the S3 backend supports native locking with
use_lockfile = true, which writes a lock file next to the state so two runs cannot change it at once. The older DynamoDB-based locking is deprecated and will be removed in a future version.
Plan, then apply
terraform plan refreshes what is really deployed, compares it with your code and state, and lists every change:
+create,~update in place,-destroy,-/+destroy and then create (a replacement),- and a summary like "Plan: 2 to add, 1 to change, 1 to destroy."
terraform apply makes those changes. It is the same idea as executing a CloudFormation change set: preview, then act. In CI, save the plan with -out and apply exactly that saved plan, so what was reviewed is what runs.
A common mistake is fixing things in the console. The next plan will try to undo the manual change, which is drift showing up. Put the fix in the code.
Where AI fits
Assistants write HCL well, and HashiCorp publishes a Terraform MCP server that gives them current provider and module documentation from the registry. That helps with correct syntax, but it does not make the change safe. Always read the plan, especially every destroy and replace line. One - next to aws_db_instance.prod is the line that matters. Add prevent_destroy to critical resources as a second guard.
Quick recap
- Code, state, plan, apply: Terraform's whole loop.
- Keep state in S3 with native locking; DynamoDB locking is deprecated.
- Always read the plan, whoever (or whatever) wrote the code.