Skip to content

Lesson 2 of 9 · 23m

Reading Plans as Contracts, Not Diff Noise

Interpret creates, updates, replacements, dependency edges, unknown values, and refresh effects before allowing any apply to run.

A Terraform plan is a promise you are being asked to sign. The promise is not 'Terraform will do approximately this.' It is 'Terraform believes these actions are necessary to move the remembered world toward the configured world.' If you do not understand why an action appears, the correct answer is not apply. The correct answer is stop.

The four action verbs matter

Terraform will perform the following actions:

  # aws_instance.api will be updated in-place
  ~ resource "aws_instance" "api" {
      ~ instance_type = "t3.small" -> "t3.large"
    }

  # aws_lb_listener.https will be replaced
-/+ resource "aws_lb_listener" "https" {
      ~ certificate_arn = old -> new # forces replacement
    }

+ creates, ~ updates, - destroys, and -/+ replaces. Replacement is the dangerous one because the old object may disappear before the new object is healthy. Some providers support create-before-destroy, but many cloud resources cannot overlap because names, addresses, or physical identities conflict.

Unknown values are normal until they are not

During plan, values produced by resources that do not yet exist appear as (known after apply):

output "database_endpoint" {
  value = aws_db_instance.main.endpoint
}

Unknown values are not automatically dangerous. They become dangerous when they hide count, for_each keys, or conditional resource creation. If Terraform cannot determine whether a resource exists until apply, review the design. Dynamic existence is hard to review and easy to mis-automate.

Read the dependency story

Terraform builds a graph from references and explicit dependencies:

resource "aws_iam_role_policy_attachment" "app" {
  role       = aws_iam_role.app.name
  policy_arn = aws_iam_policy.app.arn
}

resource "aws_lambda_function" "worker" {
  role = aws_iam_role.app.arn
  depends_on = [aws_iam_role_policy_attachment.app]
}

Normal references usually create enough ordering. depends_on is a blunt instrument for side effects Terraform cannot infer, such as IAM propagation or provider resources that are technically independent but operationally ordered. Overusing it makes plans brittle and hard to reason about.

Plan output is input to review

Use machine-readable plans in automation:

terraform plan -out=tfplan
terraform show -json tfplan > tfplan.json
jq '.resource_changes[] | select(.change.actions | index("delete")) | .address' tfplan.json

Human-readable output is for humans. JSON is for policy checks, change summaries, and audit trails. Keep the exact plan artifact through apply; terraform apply tfplan applies the reviewed actions rather than recomputing a potentially different world.

Targeted plans are exceptions, not workflow

-target=aws_instance.api tells Terraform to concentrate on a subset, but it can skip dependency updates and produce state that does not match the full configuration. Use targets for incident recovery or awkward provider edge cases, then run a normal plan immediately afterward.

Field notes

  • A replacement is not automatically bad. Ask what downtime, data migration, or identity change replacement implies.
  • No changes after manual edits is not proof of health; inspect whether refresh ran and whether the resource is under Terraform management at all.
  • Plan output can include secrets when sensitive attributes change. Treat saved plans as sensitive artifacts.
  • If module version, provider version, variables, or branch differ between plan and apply, you did not apply the thing you reviewed.
  • Large noisy plans usually mean weak ownership boundaries or generated configuration, not superior automation.

Was this lesson helpful?

Sign in to rate