How does the terraform plan command works?

In the infrastructure provisioning and management realm, Terraform has emerged as a popular tool for automating the deployment and configuration of resources across various cloud providers. One of the key commands in the Terraform workflow is terraform plan. This Answer aims to elucidate the terraform plan command's purpose, functionality, and benefits.

The terraform plan command

The terraform plan command is a crucial part of the Terraform workflow. It is used to generate an execution plan that outlines the changes that will be applied to the infrastructure when the terraform apply command is executed. The purpose of the terraform plan command is to provide visibility into the intended modifications to the infrastructure, allowing users to review and validate these changes before actually applying them.

Code

We have created a directory named plan with a main.tf file. We have executed terraform init command to initialize the Terraform module. Click the "run" button for the terraform plan command.

resource "local_file" "planning_with_terrafoem" {
  content = "Planning with TERRAFORM"
  filename = "${path.module}/plan.txt"
}
Sample code

Explanation

  • Line 1: We create a resource block.

  • Line 2: We add content to the content variable.

  • Line 3: We set the file name to plan.txt.

Note: The plan.txt file will not be created when executing terraform plan command. This command generates a plan of action that allows us to preview the modifications that Terraform intends to apply to our infrastructure.

Free Resources

Copyright ©2025 Educative, Inc. All rights reserved