Terraform Associate Exam QuestionsBrowse all questions from this exam

Terraform Associate Exam - Question 14


If you manually destroy infrastructure, what is the best practice reflecting this change in Terraform?

Show Answer
Correct Answer: A

When you manually destroy infrastructure, the best practice to reflect this change in Terraform is to run 'terraform refresh'. This command reads the current settings from all managed remote objects and updates the Terraform state to match. Note that while 'terraform refresh' is deprecated, it still serves the purpose of updating Terraform's state to reflect the manual changes made to the infrastructure. You should avoid manually updating the state file as it can introduce errors, and the changes won't happen automatically without running 'terraform refresh' or similar commands.

Discussion

17 comments
Sign in to comment
tf181Option: A
Apr 27, 2022

How could change reflect in terraform without doing anything? I think A is right answer. any thoughts?

g_Option: A
Apr 27, 2022

Wouldn't it be A?

Tyler2023Option: B
Oct 21, 2023

The should be B Wherever possible, avoid using 'terraform refresh' explicitly and instead rely on Terraform's behavior of automatically refreshing existing objects as part of creating a normal plan. If you don't want to automatically refresh, you can use the 'terraform apply -refresh-only' without the -auto-approve option terraform refresh is deprecated https://developer.hashicorp.com/terraform/cli/commands/refresh

Tyler2023
Oct 21, 2023

unless, you are using old version of TF that doesn't support the refresh-only but you shouldn't typically need to use this command, because Terraform automatically performs the same refreshing actions as a part of creating a plan in both the 'terraform plan' and ' terraform apply' commands.

TigerInTheCloud
Dec 19, 2023

Read the document carefully :-) The document mentions the reason for the deprecation and recommends alternatives. "A" is not the best practice in the real world, but is the best answer available here. "B" it won't automatically happen unless run some command.

dizzy_monkeyOption: A
Feb 22, 2024

you can do terraform refresh which is a alias for terraform apply -refresh-only -auto-approve

akkam89Option: B
Feb 26, 2024

```The terraform refresh command reads the current settings from all managed remote objects and updates the Terraform state to match. Warning: This command is deprecated, because its default behavior is unsafe if you have misconfigured credentials for any of your providers. See below for more information and recommended alternatives.```

ravk2321Option: B
Mar 8, 2024

"The Terraform refresh command reads the current settings from all managed remote objects and updates the Terraform state to match." Warning: This command is deprecated because its default behaviour is unsafe if you have misconfigured credentials for any of your providers. See below for more information and recommended alternatives. This won't modify your real remote objects, but it will modify the Terraform state. "You shouldn't typically need to use this command, because Terraform automatically performs the same refreshing actions as a part of creating a plan in both the Terraform plan and Terraform apply commands. This command is here primarily for backward compatibility, but we don't recommend using it because it provides no opportunity to review the effects of the operation before updating the state." Link:https://developer.hashicorp.com/terraform/cli/commands/refresh

BadiiOption: A
Oct 2, 2023

A. Run terraform refresh

IIIIIIIIIlllllOption: B
Nov 6, 2023

Due to changes in terraform versions, the answer was previously A, but is now B.

Rtech75Option: A
Nov 21, 2023

The wordings on B very unclear, while A is the closest possible answer. I would choose A over B for lack option and clarity on answers given

TigerInTheCloudOption: A
Dec 19, 2023

A is the best answer here terraform plan -refresh-only or terraform apply -refresh-only is best practice, but not mentioned here.

samimshaikhOption: A
Dec 29, 2023

there are two ways to do this manually remove the resource using "terraform rm" from the state management and the other way is to refresh the state. Since the option given in this question is not clear enough as to run "terraform rm" or not in option C, I will go with option A is the best suited. terraform refresh

samimshaikh
Dec 29, 2023

in the context of question resource is deleted manually mean we can just refresh the state while terrafrom rm command or manually updating state file updated than resources will be still there so I will go with a TERRAFORM REFRESH

Deva2596Option: A
Jan 12, 2024

-------------------------------

DarrylNgOption: A
Apr 23, 2024

https://developer.hashicorp.com/terraform/cli/commands/refresh. A should be the answer Need to run terraform plan or apply with refresh tag

deepakpambanOption: A
May 3, 2024

terraform refresh is not depricated. Answer is A

starkonbulletOption: A
May 17, 2024

The command had been deprecated already. Use -refresh-only option along with terraform plan or terraform apply for the same operation.

callmegioOption: A
Jun 17, 2024

A is the correct answer. Terraform says Warning: This command is deprecated, because its default behavior is unsafe if you have misconfigured credentials for any of your providers. You shouldn't typically need to use this command, because Terraform automatically performs the same refreshing actions as a part of creating a plan in both the terraform plan and terraform apply commands.

enklauOption: A
Jul 18, 2024

A is correct, but now as a best practice the correct way should be running terraform apply with the -refresh-only flag