0
0
Terraformcloud~5 mins

Plan output reading in Terraform - Commands & Configuration

Choose your learning style9 modes available
Introduction
When you make changes to your infrastructure code, you want to see what will happen before applying them. Terraform's plan command shows you the changes it will make without actually changing anything. This helps avoid surprises and mistakes.
When you want to check what resources will be created, changed, or deleted before applying changes.
When you want to review infrastructure updates with your team before making them live.
When you want to verify that your code changes will not accidentally remove important resources.
When you want to understand the impact of a configuration change on your cloud environment.
When you want to catch errors or unexpected changes early in your deployment process.
Config File - main.tf
main.tf
terraform {
  required_version = ">= 1.0"
  required_providers {
    aws = {
      source  = "hashicorp/aws"
      version = "~> 4.0"
    }
  }
}

provider "aws" {
  region = "us-east-1"
}

resource "aws_s3_bucket" "example_bucket" {
  bucket = "example-terraform-bucket-123456"
  acl    = "private"
}

This file configures Terraform to use AWS as the cloud provider in the us-east-1 region. It defines a simple S3 bucket resource named example_bucket with private access. This setup is used to demonstrate how Terraform plans changes before applying them.

Commands
This command initializes the Terraform working directory. It downloads the required provider plugins and prepares the environment for running Terraform commands.
Terminal
terraform init
Expected OutputExpected
Initializing the backend... Initializing provider plugins... - Finding hashicorp/aws versions matching "~> 4.0"... - Installing hashicorp/aws v4.0.0... - Installed hashicorp/aws v4.0.0 (signed by HashiCorp) Terraform has been successfully initialized! You may now begin working with Terraform. Try running "terraform plan" to see any changes that are required for your infrastructure.
This command shows what Terraform will do when you apply your changes. It lists resources to be added, changed, or destroyed without making any actual changes.
Terminal
terraform plan
Expected OutputExpected
Refreshing Terraform state in-memory prior to plan... An execution plan has been generated and is shown below. Resource actions are indicated with the following symbols: + create Terraform will perform the following actions: # aws_s3_bucket.example_bucket will be created + resource "aws_s3_bucket" "example_bucket" { + acl = "private" + bucket = "example-terraform-bucket-123456" + force_destroy = false + id = (known after apply) + region = (known after apply) + tags = (known after apply) } Plan: 1 to add, 0 to change, 0 to destroy. ───────────────────────────────────────────────────────────────────────────── Note: You didn't specify an "-out" parameter to save this plan, so Terraform can't guarantee to take exactly these actions if you run "terraform apply" now.
-out=planfile - Saves the plan to a file for later apply
This command applies the planned changes to your infrastructure. The -auto-approve flag skips the confirmation prompt to apply immediately.
Terminal
terraform apply -auto-approve
Expected OutputExpected
aws_s3_bucket.example_bucket: Creating... aws_s3_bucket.example_bucket: Creation complete after 2s [id=example-terraform-bucket-123456] Apply complete! Resources: 1 added, 0 changed, 0 destroyed.
-auto-approve - Automatically approves the apply without asking for confirmation
Run plan again after apply to confirm no changes are pending. This shows that the infrastructure matches the code.
Terminal
terraform plan
Expected OutputExpected
Refreshing Terraform state in-memory prior to plan... No changes. Infrastructure is up-to-date. This means that Terraform did not detect any differences between your configuration and real physical resources that exist. Your infrastructure matches the configuration.
Key Concept

If you remember nothing else from this pattern, remember: terraform plan shows exactly what changes will happen before you make them, helping you avoid surprises.

Common Mistakes
Running terraform apply without running terraform plan first
You might apply unintended changes or delete resources by accident without reviewing the plan.
Always run terraform plan first to review the planned changes before applying.
Ignoring the plan output and applying blindly
You miss the chance to catch errors or unexpected resource changes that could cause downtime or data loss.
Carefully read the plan output to understand what Terraform will do.
Not initializing Terraform with terraform init before planning
Terraform will fail to run plan or apply because providers are not downloaded and configured.
Run terraform init once before any plan or apply commands in a new working directory.
Summary
terraform init prepares your working directory and downloads providers.
terraform plan shows what changes Terraform will make without applying them.
terraform apply makes the changes to your infrastructure.
Running terraform plan after apply confirms your infrastructure matches your code.