A plan file saves a Terraform execution plan so planning and applying can happen in separate steps. This lets someone review proposed resource changes before an automated workflow applies them. If no file is supplied, `terraform apply` creates a new plan instead. section 5.5.2 section 5.5.1
Save, review, and apply
Run `terraform plan -out=create.tfplan`, review the resulting plan, then run `terraform apply create.tfplan`. The file is an optional argument to `apply`; `tfplan` is a convention, not a required extension. When given a plan file, Terraform does not ask for approval again—it assumes review happened earlier. section 5.2.2 section 5.5.2
Applying the file runs the actions defined during planning, such as creating, updating, or deleting resources in the planned order. By contrast, running `terraform plan` and later `terraform apply -auto-approve` without saving a file does not guarantee that the earlier review matches what gets applied: changes outside the workflow may occur between commands. section 1.4.4 section 5.5.1
For tooling that needs to inspect more than the command log, `terraform show` can read a saved plan to obtain its plan data structure. That structure includes plan metadata, prior state, planned values, and resource and output changes. A saved file can also feed `terraform graph -type=apply -plan=create.tfplan` to visualize how Terraform will apply the plan. section 11.1.8 section 5.2.2
Listing 1.3 Changing infrastructure with terraform apply
$ terraform apply tfplan #1 aws_instance.hello_world: Creating... #2 aws_instance.hello_world: Still creating... [10s elapsed] #3 aws_instance.hello_world: Creation complete after 12s [id=i-01792587739c8e453] #4 Apply complete! Resources: 1 added, 0 changed, 0 destroyed. #5 Outputs: aws_instance_arn = "arn:aws:ec2:us-east-2:966612157092:instance/i- 01792587739c8e453" #6 #1 Here we run the apply subcommand while passing through the plan file we created earlier. #2 While Terraform runs through the apply it will update you on what it is doing. #3 Some resources can take awhile to create. #4 Once created, resources will have a unique ID associated with them. #5 The apply command also has a summary, just like the plan command. #6 Now that the resource exists the output has been updated.
See a saved plan passed to `terraform apply`, followed by resource creation messages and an apply summary. section 1.4.4
