TA-002-P · Question #166
Which of the below commands will rename a EC2 instance without destroying and recreating it?
The correct answer is A. terraform state mv. terraform state mv renames a resource's address in the state file, allowing infrastructure to be tracked under a new name without triggering a destroy and recreate cycle.
Question
Which of the below commands will rename a EC2 instance without destroying and recreating it?
Options
- Aterraform state mv
- Bterraform mv
- Cterraform plan
- Dterraform plan mv
How the community answered
(25 responses)- A96% (24)
- D4% (1)
Why each option
terraform state mv renames a resource's address in the state file, allowing infrastructure to be tracked under a new name without triggering a destroy and recreate cycle.
The terraform state mv command updates the state file to map an existing real-world resource to a new resource address - for example, renaming aws_instance.old_ec2 to aws_instance.new_ec2. Because only the state mapping changes and no API calls are made to modify the actual EC2 instance, the infrastructure remains intact with zero downtime.
terraform mv is not a valid Terraform CLI command - the correct command for moving state entries is the state subcommand terraform state mv.
terraform plan only computes and displays a proposed execution plan showing what would change - it does not modify the state file or any infrastructure.
terraform plan mv is not a valid Terraform CLI command - no such combined subcommand exists in the Terraform toolchain.
Concept tested: Terraform state mv for renaming resources without recreation
Source: https://developer.hashicorp.com/terraform/cli/commands/state/mv
Topics
Community Discussion
No community discussion yet for this question.