Hitesh Sahu
Hitesh SahuHitesh Sahu
  1. Home
  2. ›
  3. posts
  4. ›
  5. …

  6. ›
  7. 3 Workflow

Loading ⏳
Fetching content, this won’t take long…


💡 Did you know?

🤯 Your stomach gets a new lining every 3–4 days.

🍪 This website uses cookies

No personal data is stored on our servers however third party tools Google Analytics cookies to measure traffic and improve your website experience. Learn more

Cover Image for Terraform Core Workflow & Commands ⚡

Terraform Core Workflow & Commands ⚡

Learn how to plan, apply, and manage your Terraform infrastructure efficiently.

Hitesh Sahu
Written by Hitesh Sahu, a passionate developer and blogger.

Mon Sep 29 2025

Share This on

Use Terraform outside the core workflow - 14%

  • 4a Describe when to use terraform import to import existing infrastructure into your Terraform state
  • 4b Use terraform state to view Terraform state
  • 4c Describe when to enable verbose logging and what the outcome/value is

Core Terraform workflow - 14%

  • 6a Describe Terraform workflow ( Write -> Plan -> Create )
  • 6b Initialize a Terraform working directory (terraform init)
  • 6c Validate a Terraform configuration (terraform validate)
  • 6d Generate and review an execution plan for Terraform (terraform plan)
  • 6e Execute changes to infrastructure with Terraform (terraform apply)
  • 6f Destroy Terraform managed infrastructure (terraform destroy)
  • 6g Apply formatting and style adjustments to a configuration (terraform fmt)

Initialize your Terraform working directory

commanduse
terraform initinitialize directory, pull down providers
terraform init -get-plugins=falseinitialize directory, do not download plugins
terraform init -verify-plugins=falseinitialize directory, do not verify plugins for Hashicorp signature

Format and Validate Terraform code

commanduse
terraform fmtformat code per HCL canonical standard
terraform fmt -diffdisplay diffs of formatting changes
terraform fmt -check -recursiveprocess files in subdirectories
terraform validatevalidate code for syntax
terraform validate -jsonproduce validation results in JSON format to allow using the validation result for tool integrations,
terraform validate -backend=falsevalidate code skip backend validation

Plan, Deploy and Cleanup Infrastructure

commanduse
terraform plan -out plan.outoutput the deployment plan to plan.out
terraform apply plan.outuse the plan.out plan file to deploy infrastructure
terraform apply --auto-approveapply changes without being prompted to enter "yes"
terraform plan -destroyoutputs a destroy plan
terraform destroy --auto-approvedestroy/cleanup deployment without being prompted for “yes”
terraform apply -target=aws_instance.my_ec2only apply/deploy changes to the targeted resource
terraform apply -var my_region_variable=us-east-1pass a variable via command-line while applying a configuration
terraform apply -lock=true lock the state file so it can't be modified by any other Terraform apply or modification action(possible only where backend allows locking)
terraform force-unlock LOCK_IDunlock state file
terraform apply refresh=false do not reconcile state file with real-world resources(helpful with large complex deployments for saving deployment time)
terraform apply --parallelism=5number of simultaneous resource operations (Defualt 10)
terraform refreshreconcile the state in Terraform state file with real-world resources
terraform providersget information about providers used in current configuration

Terraform Import And Outputs

commanduse
terraform import aws_instance.new_ec2_instance i-abcd1234import EC2 instance with id i-abcd1234 into the Terraform resource named "new_ec2_instance" of type "aws_instance"
terraform import 'aws_instance.new_ec2_instance[0]' i-abcd1234same as above, imports a real-world resource into an instance of Terraform resource
terraform outputlist all outputs as stated in code
terraform output instance_public_iplist out a specific declared output
terraform output -json list all outputs in JSON format

Terraform workflow

TF workflow is 3 Steps

  1. Write: write IaC
  2. Plan: Preview changes before applying
  3. Apply: Provision Infrastructure

Terraform/3-Workflow
Let's work together
+49 176-2019-2523
hiteshkrsahu@gmail.com
WhatsApp
Skype
Munich 🥨, Germany 🇩🇪, EU
Playstore
Hitesh Sahu's apps on Google Play Store
Need Help?
Let's Connect
Navigation
  Home/About
  Skills
  Work/Projects
  Lab/Experiments
  Contribution
  Awards
  Art/Sketches
  Thoughts
  Contact
Links
  Sitemap
  Legal Notice
  Privacy Policy

Made with

NextJS logo

NextJS by

hitesh Sahu

| © 2025 All rights reserved.