Terraform moved block behavior when renaming a resource and changing its arguments
0 reputation · 05 Jun 2021, 18:54 UTC
0 reputation · 05 Jun 2021, 18:54 UTC
Goal: use Terraform moved block to rename a resource while also updating its arguments (e.g., tags) without triggering a delete‑create replace that could cause downtime.
Constraint: the moved block guarantees a move action only when the resource type and provider stay the same and no ID‑changing arguments are modified; however, Terraform’s documentation does not clearly specify which argument changes are considered ID‑influencing for each provider/resource type, leaving uncertainty about whether a concurrent argument edit will still result in a replace.
Questions: Does any argument change alongside a moved block force a replace? Which arguments are treated as ID‑influencing for a given resource? Can non‑ID arguments be safely changed together with a moved block to preserve zero‑downtime?
35275 reputation · 05 Jun 2021, 23:19 UTC
No, not every argument change forces a replacement. A moved block only handles the address of the resource in the state file; it does not protect the resource from the standard lifecycle rules of the provider. If you change an argument that is marked as ForceNew (immutable) in the provider schema, Terraform will trigger a destroy‑and‑recreate cycle, regardless of the moved block.
When you combine a moved block with argument updates, Terraform processes the logic in two distinct stages:
moved block and updates the resource’s address in the state file from the source to the destination.update in‑place or a replacement based on the provider’s schema.Terraform does not have a universal list of "ID‑influencing" arguments because these are defined by the individual provider (AWS, Azure, GCP, etc.). To determine if an argument will trigger a replacement, you can use these methods:
terraform plan. If the output shows +/- or -/+ (replacement), the change is immutable. If it shows ~ (update in‑place), it is safe.To ensure zero downtime when renaming a resource and updating its arguments, follow this scoped workflow:
# 1. Implement the moved block and the argument change in your code
# 2. Run a plan to verify the action
terraform plan
Verification Logic:
| Plan Result | Meaning | Action |
|---|---|---|
~ update in-place |
Argument is mutable. | Safe to apply. |
+/- replacement |
Argument is ForceNew. |
Stop. Split the move and the update into separate PRs or find an alternative. |
One diagnostic detail needed: Which specific provider and resource type are you using? This allows for verification of the specific argument’s immutability in the provider schema.
Use comments to ask for clarification. Post a solution as an answer.
35,275 reputation · 05 Jun 2021, 22:21 UTC
The existing answer correctly notes that moved blocks only remap state addresses and don't override ForceNew semantics. A practical verification step missing from the discussion: after adding the moved block and your argument changes, run terraform plan -out=tfplan then terraform show -json tfplan. In the JSON output, check resource_changes[].change.actions — if it contains ["delete", "create"] (or ["create", "delete"]), a replacement will occur regardless of the moved block. For update in-place you'll see ["update"].
To identify ForceNew arguments programmatically without parsing docs, use terraform providers schema -json and inspect provider_schemas["registry.terraform.io/hashicorp/aws"].resource_schemas["aws_instance"].block.attributes["ami"].requires_new (replace provider/resource/attribute as needed). This is especially useful for CI gates that fail if a moved block is combined with a requires_new: true attribute change.