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
Della
11 hours ago
But it won't update the name properly, right?
upvoted 0 times
...
Tracey
6 days ago
True, but option B seems like a safe bet too.
upvoted 0 times
...
Shawnta
11 days ago
I feel like option A is risky. Re-importing can cause issues.
upvoted 0 times
...
Carma
16 days ago
Yeah, adding a moved block makes sense.
upvoted 0 times
...
Della
21 days ago
I think option D is the best choice.
upvoted 0 times
...
Moon
26 days ago
Right? Better to be explicit with D.
upvoted 0 times
...
Ming
1 month ago
I feel like C is too optimistic. Terraform doesn't always auto-update.
upvoted 0 times
...
Eileen
1 month ago
Exactly! We want to avoid destruction. D is safer.
upvoted 0 times
...
Alton
1 month ago
Option A seems risky. Removing the resource could lead to issues.
upvoted 0 times
...
Pete
2 months ago
Yeah, I agree. The moved block keeps everything organized.
upvoted 0 times
...
Jean
2 months ago
I think option D is the best choice. It clearly indicates the resource has moved.
upvoted 0 times
...
Corazon
2 months ago
B won't help with the name change, just saying.
upvoted 0 times
...
Refugia
2 months ago
Wait, does D really work without issues?
upvoted 0 times
...
Zana
2 months ago
A is too much hassle, just use D!
upvoted 0 times
...
France
2 months ago
I thought Terraform auto-updated states?
upvoted 0 times
...
Mohammad
3 months ago
D is the way to go!
upvoted 0 times
...
Laurel
3 months 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
4 months ago
I thought Terraform automatically updates the state, but I guess that might not apply in this case?
upvoted 0 times
...
Daniel
5 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
5 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