Deal of The Day! Hurry Up, Grab the Special Discount - Save 25% - Ends In 00:00:00 Coupon code: SAVE25
Welcome to Pass4Success

- Free Preparation Discussions

HashiCorp Terraform-Associate-004 Exam - Topic 7 Question 9 Discussion

You corrected a typo in a resource name, changing it from aws_s3_bucket.photoes to aws_s3_bucket.photos. You want to update the Terraform state so that the existing resource is recognized under the new name, without destroying and recreating it. Which configuration should you use?
D) Add a moved block to your configuration.
A) Remove the old resource from your configuration and re-import it.
B) Run terraform apply -refresh-only.
C) Do nothing --- Terraform will automatically update the state.

HashiCorp Terraform-Associate-004 Exam - Topic 7 Question 9 Discussion

Actual exam question for HashiCorp's Terraform-Associate-004 exam
Question #: 9
Topic #: 7
[All Terraform-Associate-004 Questions]

You corrected a typo in a resource name, changing it from aws_s3_bucket.photoes to aws_s3_bucket.photos. You want to update the Terraform state so that the existing resource is recognized under the new name, without destroying and recreating it. Which configuration should you use?

Show Suggested Answer Hide Answer
Suggested Answer: D

Rationale for Correct Answer: A moved block tells Terraform that an object's address in state has changed (renamed/refactored) and it should move the state from the old address to the new address. This preserves the existing real resource and prevents unnecessary destroy/recreate.

Analysis of Incorrect Options (Distractors):

A: Works but is unnecessarily risky/extra work; moved is the intended refactoring mechanism for renames.

B: Incorrect---refresh-only updates state to match real infrastructure, but it does not remap an object from one address to another.

C: Incorrect---Terraform will treat the new name as a new resource address and the old one as removed unless you explicitly move/rename state.

Key Concept: Refactoring addresses safely using moved blocks (state address migration).


====================

Contribute your Thoughts:

0/2000 characters
Pete
2 days ago
Yeah, I agree. The moved block keeps everything organized.
upvoted 0 times
...
Jean
7 days ago
I think option D is the best choice. It clearly indicates the resource has moved.
upvoted 0 times
...
Corazon
12 days ago
B won't help with the name change, just saying.
upvoted 0 times
...
Refugia
17 days ago
Wait, does D really work without issues?
upvoted 0 times
...
Zana
23 days ago
A is too much hassle, just use D!
upvoted 0 times
...
France
28 days ago
I thought Terraform auto-updated states?
upvoted 0 times
...
Mohammad
1 month ago
D is the way to go!
upvoted 0 times
...
Laurel
1 month ago
I recall that removing the old resource and re-importing it could lead to issues, so I’d lean towards option D.
upvoted 0 times
...
Asuncion
3 months ago
I thought Terraform automatically updates the state, but I guess that might not apply in this case?
upvoted 0 times
...
Daniel
3 months ago
I’m not entirely sure, but I feel like option D sounds familiar from a practice question about moving resources.
upvoted 0 times
...
Catalina
3 months ago
I think I remember that when you rename a resource, you might need to tell Terraform about the change explicitly.
upvoted 0 times
...

Save Cancel