Unified, automated, and ready to turn data into intelligence.
Discover how to unlock the true value of your data.
March 16-19 | Booth #935
San Jose McEnery Convention Center
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.
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.
Having the ability to preview what change your configuration code will cause to your infrastructure is beneficial in many ways, including:
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.
The terraform plan output is typically divided into several sections, each offering valuable insights into the planned actions:
This section lists the specific actions Terraform intends to perform on your infrastructure resources. These actions are categorized into three main types:
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:
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.
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.
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:
Spot Potential Issues:
Leveraging the Output:
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.
Everpure 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 Everpure Cloud Dedicated, you can run any database or container workloads on the cloud, just as you can on on-premises infrastructure.
Mark your calendars. Registration opens in February.
Access on-demand videos and demos to see what Everpure can do.
Charlie Giancarlo on why managing data—not storage—is the future. Discover how a unified approach transforms enterprise IT operations.
Modern workloads demand AI-ready speed, security, and scale. Is your stack ready?