0

Since terraform apply seems to show everything it is supposed to do and I still need to enter yes I see little use for terraform plan outside of using it in non-interactive environments (for example to run terraform on jenkins with manual confirmation step between plan and apply).

Are there any advantages of using terraform plan+terraform apply <plan_file> when one is running commands from command line?

1

The separate terraform plan command has two different but related purposes:

  • When you are working on a change in an environment where the workflow is to go through code review before applying, terraform plan (with no arguments) allows you to test as thoroughly as possible without making any changes to infrastructure. This use-case is sometimes called "speculative plan" because there is no intent to ever actually apply the plan generated this way: we just run it to get feedback from Terraform before submitting a change for review.

  • You are running Terraform in automation then terraform plan -out=tfplan is useful for running plan and apply as entirely separate steps with an interactive approval UI provided outside of Terraform CLI.

If you are using Terraform just locally and are intending to apply what you planned, indeed there is no benefit to running separate plan and apply vs. just terraform apply with its interactive approval. The terraform apply command with no arguments is the primary way to use Terraform to apply changes when you are running it directly from the command line, rather than in automation.

0

If you want to version control, plan may be useful for keeping an archive along with a tfstate file. BTW, you could use -auto-approve to avoid typing 'yes'

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.