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

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
Catalina
3 days 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