1
votes

I am getting to grips with Terraform, primarily for deploying Azure resources.

My question is, let's say I use Azure to create a resource group, and some resources like a web app with some settings. Now if I change a setting in the tf file, e.g. the app service plan or whatever, on the next time I run terraform, does it check settings and remediate to what is in the file?

E.g. an app service is deployed with a plan (say X), the plan is changed to Y, perhaps an unauthorised change, now when the tf file runs again, with the file specifying an app service with X, would Terraform update the app service to plan X?

Thanks!

2

2 Answers

0
votes

Yes, probably. Terraform remembers the state of your environment so if you change something manually it will want to change it back or recreate the resources if it finds they are missing.

0
votes

Terraform is infrastructure as code for immutable infrastructure.

So if you change something in your codes, terraform will compare the changes and show you the differences.

The terraform resource states are saved in *.tfstate files, which you need to guarantee the safety of it and keep it updated. That's why we use aws s3 backend and enable version control to save tfstate files always. You should do the same in Azure.

You can use terraform plan to dry-run your codes. With that, terraform will report the difference with the state from an exist tfstate file before you terraform apply the changes.

You can also run terraform refresh to get the latest resource states if there are any setting drift.