๐Ÿš€ Terraform Apply: Executing Plans and Creating Real Infrastructure

If terraform plan is like a blueprint for infrastructure, then terraform apply is the construction crew that brings the blueprint to life.

The Terraform Apply command executes the changes defined in your configuration files (.tf) and creates, updates, or deletes cloud resources as per the plan.

๐Ÿ‘‰ In other words:

  • terraform plan = What Terraform will do.
  • terraform apply = Actually doing it.

Without terraform apply, no infrastructure would ever be deployed. Itโ€™s the command that turns Infrastructure as Code (IaC) into real-world infrastructure.


โš™๏ธ What Does Terraform Apply Do?

When you run:

Terminal window
terraform apply

Terraform performs:

  1. Reads Configurations (.tf files)

    • Analyzes what resources are requested.
  2. Loads State File (terraform.tfstate)

    • Compares current infrastructure with desired state.
  3. Creates Execution Plan

    • Proposes changes (like terraform plan).
  4. User Approval (unless auto-approved)

    • Prompts:

      Do you want to perform these actions?
      Only 'yes' will be accepted to approve.
  5. Applies Changes

    • Creates, updates, or deletes resources.
  6. Updates State File

    • Saves the new state of the infrastructure.

๐Ÿ›  Terraform Apply Syntax & Options

Basic usage:

Terminal window
terraform apply

Useful flags:

  • terraform apply -auto-approve Skip approval prompt (use carefully in CI/CD).

  • terraform apply plan.out Apply a previously saved plan for consistent deployments.

  • terraform apply -refresh=false Skip refreshing state before apply.

  • terraform apply -var or -var-file Inject variables when applying.


๐Ÿ›  3 Unique Real-World Examples of Terraform Apply


โœ… Example 1: Deploying an AWS S3 Bucket

main.tf

provider "aws" {
region = "us-east-1"
}
resource "aws_s3_bucket" "example" {
bucket = "terraform-apply-example-bucket"
acl = "private"
}

Run Commands:

Terminal window
terraform init
terraform plan
terraform apply

Expected Output:

aws_s3_bucket.example: Creating...
aws_s3_bucket.example: Creation complete after 3s
Apply complete! Resources: 1 added, 0 changed, 0 destroyed.

๐Ÿ‘‰ The bucket is now live in AWS.


โœ… Example 2: Updating an Existing Resource

Modify bucket ACL:

resource "aws_s3_bucket" "example" {
bucket = "terraform-apply-example-bucket"
acl = "public-read"
}

Run Apply:

Terminal window
terraform apply

Output:

aws_s3_bucket.example: Modifying...
~ acl: "private" โ†’ "public-read"
Apply complete! Resources: 0 added, 1 changed, 0 destroyed.

๐Ÿ‘‰ terraform apply updated the ACL without recreating the bucket.


โœ… Example 3: Destroying Resources

Remove S3 bucket block from main.tf.

Run Apply:

Terminal window
terraform apply

Output:

aws_s3_bucket.example: Destroying...
aws_s3_bucket.example: Destruction complete after 2s
Apply complete! Resources: 0 added, 0 changed, 1 destroyed.

๐Ÿ‘‰ Deleting the block in code + running terraform apply removes the resource from AWS.


๐ŸŽฏ Why is Terraform Apply Important?

  1. Turns Code into Reality

    • Converts .tf code into running infrastructure.
  2. Ensures Consistency

    • Keeps infrastructure aligned with code (no drift).
  3. Automates Infrastructure Deployment

    • Eliminates manual provisioning steps.
  4. Supports Continuous Delivery

    • Easily integrated with CI/CD pipelines.
  5. Auditable & Predictable

    • Execution is logged and state files maintain history.

๐Ÿง  How to Remember Terraform Apply (Exam & Interview)

Mnemonic: A.C.E

  • A โ†’ Apply changes
  • C โ†’ Create/update/destroy resources
  • E โ†’ Execute the plan

๐Ÿ‘‰ Interview Answer: โ€œTerraform apply takes the execution plan and applies it, creating, modifying, or deleting resources as needed. Itโ€™s the command that executes Infrastructure as Code.โ€


๐Ÿ“š Best Practices for Terraform Apply

  • Always run terraform plan first.
  • Use -auto-approve only in CI/CD pipelines, never manually.
  • Apply saved plans (plan.out) for reproducibility.
  • Use remote backends (S3, Azure Blob, GCS) for collaborative apply.
  • Review apply logs carefully, especially in production.

๐Ÿ”ฎ Future Enhancements of Terraform Apply

  • Policy enforcement โ†’ Built-in compliance checks before apply.
  • AI-based warnings โ†’ Detect potentially risky actions.
  • Visual apply previews โ†’ Show graphical representation of resource changes.
  • Rollback capability โ†’ Undo failed applies more easily.

๐Ÿ“ Summary

  • terraform apply is the command that executes your infrastructure plan.

  • It creates, updates, or destroys resources to match .tf files.

  • Steps:

    • Reads config โ†’ Compares state โ†’ Proposes changes โ†’ Awaits approval โ†’ Executes.
  • Symbols:

    • + Resource created
    • ~ Resource updated
    • - Resource destroyed
  • Remember with A.C.E โ†’ Apply, Create, Execute.


โœ… Final Takeaway

Without terraform apply, Terraform would be just a planning tool. Itโ€™s the command that transforms your code into infrastructure reality.

  • For beginners, itโ€™s how you bring your first S3 bucket, VM, or network to life.
  • For DevOps engineers, itโ€™s the backbone of automated pipelines.
  • For enterprises, it ensures scalable, predictable, and secure deployments.

๐Ÿ‘‰ In short: Terraform Apply = Infrastructure Creation in Action.