A. is correct
but now as a best practice the correct way should be running terraform apply with the -refresh-only, this way you will get a prompt when it compares and see's that the deleted infrastructure is missing and will show you during your plan.
The best practice when infrastructure is manually destroyed is to manually update the state file (option C). This means the need to update Terraform's state file to reflect that the resource has been destroyed outside of Terraform.
Specifically:
You can use the terraform state rm command to remove the resource from the state file, as it no longer exists.
Alternatively, you could manually edit the state file, but this is risky and generally not recommended.
Other options like terraform refresh will only update the state based on the existing infrastructure, but if the resource was destroyed outside of Terraform, it will still appear in the state file unless manually removed.
```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.```
"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
terraform refresh is used to reconcile the Terraform state with the real-world infrastructure. If you manually destroy infrastructure, the Terraform state will still show that the resource exists. Running terraform refresh updates the state to reflect the current state of the infrastructure, marking resources that were manually destroyed as no longer existing.
B. It will happen automatically: No, Terraform does not automatically update its state when infrastructure is changed outside of Terraform. You need to run a command like terraform refresh.
he terraform refresh command : 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.
I'd say it's A but the question is weird and I got tricked. By manually I thought it'd be "terraform destroy" but it seems like manually mean go into the cloud and delete stuff, therefore you need to refresh the file.
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.
A voting comment increases the vote count for the chosen answer by one.
Upvoting a comment with a selected answer will also increase the vote count towards that answer by one.
So if you see a comment that you already agree with, you can upvote it instead of posting a new comment.
tf181
Highly Voted 2 years, 8 months agoG__
Highly Voted 2 years, 8 months agoLabman32
Most Recent 1 month, 2 weeks agoerif
2 months, 3 weeks agonss373
3 months agoakkam89
3 months agoravk2321
3 months agofasaleAkshay
3 months, 1 week agoMattt
3 months, 2 weeks agobora4motion
4 months, 1 week agoenklau
5 months, 1 week agocallmegio
6 months, 2 weeks agostarkonbullet
7 months, 2 weeks agodeepakpamban
7 months, 4 weeks agoDarrylNg
8 months, 1 week agodizzy_monkey
10 months, 1 week agoDeva2596
11 months, 3 weeks ago