Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Is `terraform init` compulsory before every `terraform plan`?

Tags:

terraform

Just wondering if terraform init is compulsory before every terraform plan?

i.e. if I've already done a terraform init but are about to do a second terraform plan based on some changed Terraform code would you need to do a second terraform init?

like image 366
Snowcrash Avatar asked Feb 05 '23 06:02

Snowcrash


2 Answers

It depends.

Depending on exactly what the Terraform code is you've changed, you may need to re-run init. For instance, if you've made changes to a configured backend, you'll need to rerun terraform init to re-initialise with those changes. If the changes are to non-terraform configuration parts of your script, terraform plan and terraform apply should be fine to use by themselves.

One further note is that if you're using modules, and you make a change in a module, you will need to re-run terraform get -update to get those changes before running plan or apply.

like image 128
James Thorpe Avatar answered Feb 06 '23 19:02

James Thorpe


Agree with all the above answers, but something to add here is that it is safe to run terraform init many times even if nothing changed, its not going to affect anything.

like image 38
Ahmed IG Avatar answered Feb 06 '23 19:02

Ahmed IG