Terraform Associate Exam QuestionsBrowse all questions from this exam

Terraform Associate Exam - Question 138


You have modified your Terraform configuration to fix a typo in the Terraform ID of a resource from aws_security_group.http to aws_security_group.http

Which of the following commands would you run to update the ID in state without destroying the resource?

Show Answer
Correct Answer: A

The correct command to update the Terraform state without destroying the resource is 'terraform mv aws_security_group.htp aws_security_group.http'. The 'terraform mv' command is specifically designed to rename resources in the Terraform state file. It does not recreate or destroy resources, instead, it simply updates the state file to reflect the new name.

Discussion

9 comments
Sign in to comment
BurakkoOption: A
Mar 2, 2023

I guess it had to be terraform state mv ..... The terraform state mv command changes which resource address in your configuration is associated with a particular real-world object. Use this to preserve an object when renaming a resource, or when moving a resource into or out of a child module.

adoubanOption: A
Jun 13, 2023

A is correct but the command is wrong it should be terraform state mv <old_name> <new_name>

shopkittyOption: A
Mar 8, 2023

if use the apply then it will destroy and re-create the resource, only terraform state mv allows to update the state file without destroying resources.

bizimunda
May 17, 2024

there is no such command as of 2023. The correct command is terraform state mv

campsOption: A
Sep 30, 2023

A. terraform mv aws_security_group.htp aws_security_group.http. The terraform mv command is used to rename a resource in your Terraform state without destroying it. In this case, you have fixed a typo in the Terraform ID of a resource, so you can use the terraform mv command to update the ID in the state without destroying the resource.

RVivekOption: A
Mar 26, 2023

Terraform apply will delete the security group htp and create a new scurity group with the name http

samimshaikhOption: A
Jun 29, 2024

options are wrong and it terraform state mv oldid newid

ravi135
Aug 8, 2024

A is correct

YesPleaseOption: A
Feb 3, 2025

Answer is technically "A" from the options provided...however, the correct command should include "state" before the "mv" TERRAFORM COMMAND: terraform state mv aws_security_group.htp aws_security_group.http