Skip to Content

What Is Terraform Plan?

Terraform, developed by HashiCorp, is a widely used infrastructure-as-code (IaC) tool that allows users to define and provision software infrastructure using a high-level configuration language. As organizations increasingly adopt cloud-based infrastructures, Terraform has become essential for managing and automating the deployment of infrastructure resources. One of the core commands in Terraform is terraform plan, a critical step in the deployment process that ensures changes to the infrastructure are safe, predictable, and efficient.

In this article, we’ll take a closer look at this command, what it does, and how to interpret its output for your Terraform configurations.

What Is Terraform Plan?

The terraform plan command is a vital part of the Terraform workflow that serves as a dry run or preview of the changes that Terraform will make to your infrastructure. It compares the current state of your infrastructure with the desired state defined in your Terraform configuration files and shows the specific actions Terraform will take to bridge the gap. This includes additions, deletions, and modifications of resources, such as creating new virtual machines, scaling up existing databases, or removing unused storage volumes.

Benefits of Terraform Plan

Having the ability to preview what change your configuration code will cause to your infrastructure is beneficial in many ways, including:

  • Transparency: Terraform plan provides a detailed overview of the upcoming changes, offering a clear picture of what will be created, modified, or deleted in your infrastructure. This transparency helps minimize errors and ensures everyone involved in the deployment process is on the same page.
  • Risk mitigation: By previewing the changes beforehand, users can identify and address potential issues before they disrupt services. Terraform plan can help uncover resource conflicts (e.g., creating a VM with a duplicate name), missing dependencies (e.g., a database requiring a specific security group that isn't configured), or unintended modifications due to typos in configuration files.
  • Collaboration: Terraform plan integrates seamlessly with version control systems like Git, facilitating team collaboration. Sharing the plan output with team members allows for reviewing changes within the context of code commits, promoting transparency and accountability before changes are implemented.
  • Efficiency: Terraform plan helps users plan and execute infrastructure changes methodically. Analyzing the plan allows you to identify potential bottlenecks or inefficiencies before applying the changes.
  • Safety: Terraform plan acts as a safety net by allowing you to review and validate changes before they’re applied to your production infrastructure. This safeguard helps prevent accidental modifications and ensures the stability and reliability of your cloud environment.

How to Execute Terraform Plan

To execute terraform plan, first ensure that you have Terraform installed on your local machine. You can download and install the appropriate version from the official HashiCorp website.

Before running the plan command, you'll need to create a basic Terraform configuration file named main.tf in your working directory. Below is an example of a simple configuration that creates a virtual machine resource in a cloud provider:

# Configure the cloud provider (replace with your provider details)
 provider "aws" {
   region = "us-east-1"
 }
 
 # Define a virtual machine resource
 resource "aws_instance" "my_vm" {
   ami           = "ami-0f78f7e824d9499e0"  # Replace with the desired AMI ID
   instance_type = "t2.micro"
 }

1. Initialize the Terraform directory

Navigate to your working directory containing the main.tf file and run the following command in your terminal:

$ terraform init

This command initializes the Terraform directory, downloads any required plugins or modules mentioned in your configuration, and prepares the environment for working with Terraform.

2. Run Terraform plan

Once the initialization is complete, execute the following command to generate the execution plan:

$ terraform plan

This command analyzes your Terraform configuration and compares it with the current state of your infrastructure (if any). It then displays a detailed plan outlining the actions Terraform will take to achieve the desired state defined in your configuration. The plan will typically show the resources that will be created, modified, or deleted

3. Save the plan output

If you want to save the plan for future reference or share it with team members, you can optionally use the -out flag with the plan command. For example, the following command saves the plan to a file named plan.tfplan:

$ terraform plan -out=plan.tfplan

The terraform plan command only previews the changes. It doesn't make any modifications to your infrastructure. After reviewing and approving the plan, you can use the $ terraform apply command to execute the planned changes.

Understanding and Analyzing Terraform Plan Output

The terraform plan output is typically divided into several sections, each offering valuable insights into the planned actions:

Resource Actions

This section lists the specific actions Terraform intends to perform on your infrastructure resources. These actions are categorized into three main types:

  • Create (+): This symbol indicates that Terraform will create new resources based on your configuration.
  • Read (~): This symbol signifies that Terraform will read the state of existing resources to determine if any changes are necessary. This symbol is less frequent in the plan output as Terraform typically determines the required actions during the planning phase.
  • Delete (-): This symbol indicates that Terraform will delete existing resources that are no longer defined in your configuration.

Resource Details

This section provides in-depth information about each resource that will be affected by the plan. Here's a breakdown of the details you can typically find:

  • Resource type: This specifies the type of infrastructure resource that Terraform manages (e.g., aws_instance, azurerm_resource_group).
  • Resource name: This identifies the unique name assigned to the resource within your Terraform configuration.

Planned Changes

This section details the specific changes that will be applied to the resource. For resources being created (denoted by +), it will list the attributes and their corresponding values that will be defined. For resources being modified, it will show the changes to existing attributes.

Summary

The plan output often concludes with a summary section that provides a high-level overview of the planned actions. This summary typically breaks down the total number of resources into the following categories:

  • To be added: The number of new resources that will be created

  • To be changed: The number of existing resources that will be modified

  • To be destroyed: The number of existing resources that will be deleted

When you run terraform plan with the sample configuration we created earlier, you’ll get results similar to the following:

# $ terraform plan
 
 Terraform used the selected providers to generate the following execution plan. Resource actions are indicated with the following symbols:
   + create
 
 Terraform will perform the following actions:
 
   # aws_instance.my_vm will be created
   resource "aws_instance" "my_vm" {
     + ami           = "ami-0f78f7e824d9499e0"
     + instance_type = "t2.micro"
     + tags = {
       + Name = "sample-tag"
     }
   }

1. Resource actions: The first line indicates that Terraform will perform creation actions (+) during this plan.

2. Resource details: The subsequent section dives into the details of a single resource, aws_instance.my_vm. This signifies that Terraform will create a new AWS EC2 instance named my_vm in your AWS environment. The details further specify the AMI ID (ami-0f78f7e824d9499e0), instance type (t2.micro), and a tag (Name = "sample-tag") that Terraform will apply to the new instance.

3. Summary (implicit): While not explicitly shown in this example, a summary might be displayed at the end of a more complex plan output, indicating the total number of resources to be created.

Best Practices for Using Terraform Plan

The terraform plan command is your safety net before applying infrastructure changes. The following are some essential practices to maximize its benefits:

Scrutinize Resource Changes:

  • Focus on resources marked for creation (+) or deletion (-).
  • Verify attribute values for new resources align with your intent (e.g., AMI ID, storage size).
  • Double-check modifications to existing resources for accuracy.

Spot Potential Issues:

  • Look for resource conflicts (e.g., duplicate names, missing dependencies).
  • Ensure all required dependencies (e.g., security groups) are defined.
  • Be cautious of unexpected resource deletions that might disrupt services.

Leveraging the Output:

  • Validate if the planned changes match your infrastructure goals.
  • Consider potential cost implications associated with resource modifications. You can also share the plan output for team review and communication.

Conclusion

Terraform plan is a powerful tool in the Terraform workflow. It offers a safe and transparent method to preview and validate infrastructure changes before applying them. By understanding and effectively using Terraform plan, you can ensure your deployments are efficient, predictable, and free of unintended consequences.

Pure Storage offers the best persistent block storage solutions for your Terraform deployments. Portworx® provides a comprehensive data platform for all your container and Kubernetes Terraform workloads. With Pure Cloud Block Store™, you can run any database or container workloads on the cloud, just as you can on on-premises infrastructure.

03/2025
Rancher Kubernetes Engine 2 on VMware with Portworx
Gain consistent experience across public cloud, on- premises, hybrid cloud, or edge architecture with Rancher Kubernetes Engine (RKE2) on VMware with Portworx.
Reference Architecture
33 pages

Browse key resources and events

RESORTS WORLD LAS VEGAS | JUNE 17 - 19
Pure//Accelerate® 2025

Join us June 17 - 19 and level up your data success.

Register Now
THOUGHT LEADERSHIP
Betting against Data Gravity: A Fool's Errand

Dive into global namespaces and the history of related buzzwords that appear as a response to data gravity.

Read the Article
PURE360 DEMOS
Explore, Learn, and Experience

Access on-demand videos and demos to see what Pure Storage can do.

Watch Demos
ANALYST REPORT
Stop Buying Storage, Embrace Platforms Instead

Explore the requirements, components, and selection process for new enterprise storage platforms.

Get the Report
CONTACT US
Contact PureInfo icon
Calendar icon
Meet with an Expert

Let’s talk. Book a 1:1 meeting with one of our experts to discuss your specific needs.

Chat icon
Questions, Comments?

Have a question or comment about Pure products or certifications?  We’re here to help.

Key icon
Schedule a Demo

Schedule a live demo and see for yourself how Pure can help transform your data into powerful outcomes. 

Call Sales: 800-976-6494

Mediapr@purestorage.com

 

Pure Storage, Inc.

2555 Augustine Dr.

Santa Clara, CA 95054

800-379-7873 (general info)

info@purestorage.com

CLOSE
CloseClose X icon
Your Browser Is No Longer Supported!

Older browsers often represent security risks. In order to deliver the best possible experience when using our site, please update to any of these latest browsers.