Terraform configuration · 13 min read · Reviewed 2026-11-01

Terraform Lifecycle Meta-Arguments: Safe Use Cases

Terraform lifecycle meta-arguments change how Terraform plans a resource transition. They are powerful because they affect replacement, deletion, and change detection, which is exactly why they need a specific reason and a careful plan review. Treat them as narrowly scoped safety controls, not default boilerplate.

Start with this example

resource "aws_instance" "app" {
  ami           = var.ami_id
  instance_type = "t3.micro"

  lifecycle {
    create_before_destroy = true
    prevent_destroy       = true
  }
}

Lifecycle rules change the plan, not the cloud service limits

create_before_destroy asks Terraform to create a replacement before it destroys the existing resource when a change requires replacement. This can reduce disruption, but it only works when the provider and resource allow both objects to exist at once. Globally unique names, quota limits, IP addresses, and attached dependencies can make a parallel replacement impossible.

prevent_destroy makes Terraform reject a plan that would destroy the protected resource. It is useful for high-value data or foundational infrastructure, but it can also block legitimate decommissioning. Teams need a deliberate process for temporarily removing the guard when a reviewed deletion is genuinely intended.

Use ignore_changes with particular caution

ignore_changes tells Terraform not to act on selected attributes after a resource has been created. It can be appropriate when another authorised system manages a narrow field, such as an autoscaling capacity value. The ownership boundary must be explicit: Terraform should not keep trying to override a value that another controller intentionally owns.

It is not a general drift fix. Ignoring a security group rule, tag, encryption setting, or access control simply makes a mismatch less visible to Terraform. Before adding ignore_changes, decide who owns the field, why, and how unexpected values will still be monitored.

Replacement triggers should be explainable

replace_triggered_by can make an otherwise in-place resource replacement follow a related change. It is useful when a real service dependency requires a fresh resource, but it should not be used as a shortcut for an unclear dependency graph.

Lifecycle choices deserve the same review as any destructive action. Read the before-and-after plan, note data and traffic risk, verify backups or migration paths, and test the transition in a lower-risk environment where possible.

Put it into practice

Take one resource that has a name, attached dependency, and stored data. Decide whether create_before_destroy is possible, what prevent_destroy would protect, and which attributes Terraform must never silently ignore.

  1. Start by identifying why Terraform proposes a replacement or deletion.
  2. Use the smallest lifecycle rule that addresses that real risk.
  3. Confirm the provider can create a replacement alongside the old resource.
  4. Review the plan and document why the rule exists.

Frequently asked questions

Does create_before_destroy guarantee zero downtime?

No. It asks Terraform to create a replacement before destroying the existing resource, but service limits, unique names, traffic cutover, attached dependencies, data migration, and application behaviour still determine whether downtime occurs.

When should I use prevent_destroy in Terraform?

Use it for resources where an accidental deletion would have significant impact, such as important data or foundational infrastructure. It should be paired with backups and a documented process for legitimate, reviewed deletion.

Is ignore_changes a good way to fix Terraform drift?

Usually no. It is appropriate only for a deliberately shared attribute with a clear owner. Using it to hide unexplained infrastructure differences can leave important access, security, or configuration changes unmanaged.

Continue with Terraform Architect