Skip to content

Instantly share code, notes, and snippets.

Last active March 26, 2022 12:06
What would you like to do?
Terraform Notes

Terraform Apply

  • terraform apply -auto-approve

Terraform Plan

  • terraform plan -out plan.out -> save the plan
  • terraform show -json plan.out > plan.json -> write the plan as json

Terraform State

  • terraform show -json | jq -C | less -R -> show the state with pretty colors
  • terraform state list -> show resources in the state
  • terraform plan -replace="<resource_name>" -> replaces resources from the state file (v0.15.2+ - older versions taint/untaint)
  • terraform state mv -> move states
  • terraform plan -refresh-only -> configuration drift between infra and the state(check changes)
  • terraform apply -refresh-only -> apply changes from infra to the state file.
  • Resource Lifecycle
    • reate_before_destroy = true
    • prevent_destroy = true
    • ignore_changes - For changes outside the Terraform workflow that should not impact Terraform operations

Terraform Import

  • terraform import -var-file <vars>.tfvars <resource> <resource_id>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment