Exam Terraform Associate All QuestionsBrowse all questions from this 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?

    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
BurakkoOption: A

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

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

shopkittyOption: A

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

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

campsOption: A

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.

ravi135Option: A

A is correct

samimshaikhOption: A

options are wrong and it terraform state mv oldid newid

RVivekOption: A

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