Menu

Terraform Workflow

Terraform Workflow

Understanding the Terraform Execution Lifecycle

•  1. Write the configuration: Describe the required resources in .tf files.

•  2. Initialize: Run terraform init to install providers and prepare the working directory.

•  3. Format and validate: Run terraform fmt and terraform validate.

•  4. Create a plan: Run terraform plan and inspect all proposed changes.

•  5. Approve deliberately: Confirm the correct account, region, resource names, permissions and cost.

•  6. Apply: Run terraform apply and approve only the reviewed plan.

•  7. Verify: Check the created resources and Terraform outputs.

•  8. Clean up: For a disposable lab, run terraform plan -destroy, review it, then run terraform destroy.

Use this sequence every time you make an infrastructure change. The plan is the review point: do not apply a change until you understand every proposed addition, update or deletion.

Working with Terraform Init, Plan and Apply Commands

  • Run `terraform init` when starting a project or changing provider or module requirements. Run `terraform plan` to inspect proposed additions, updates and deletions.
  • A saved plan can contain sensitive values, so protect it like a secret and do not commit it to a public repository.
  • Run `terraform apply` to review and approve a fresh plan interactively. In automated workflows, create a saved plan with `terraform plan -out=tfplan` and apply that exact plan using `terraform apply tfplan`.

Managing Infrastructure Using Terraform CLI Commands

  • Useful commands include `terraform fmt` to format files, `terraform validate` to check configuration structure, `terraform show` to inspect a plan or state, `terraform output` to display outputs and `terraform providers` to inspect provider requirements. `terraform state list` displays tracked addresses. 
  • Avoid editing state files manually. `terraform destroy` removes resources managed by the current configuration and state, so inspect the plan and confirm the target workspace before proceeding.

Terraform Tutorial

HA

Harini A



Learn via Video Course

undefined Logo

NaN hrs



Get in Touch For Details