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, 6 months agoG__
Highly Voted 2 years, 6 months agoLabman32
Most Recent 1 week agoerif
1 month, 2 weeks agonss373
1 month, 3 weeks agoakkam89
1 month, 4 weeks agoravk2321
1 month, 4 weeks agofasaleAkshay
1 month, 4 weeks agoMattt
2 months, 1 week agobora4motion
3 months agoenklau
4 months agocallmegio
5 months, 1 week agostarkonbullet
6 months, 1 week agodeepakpamban
6 months, 3 weeks agoDarrylNg
7 months agodizzy_monkey
9 months agoDeva2596
10 months, 2 weeks ago