Skip to content

Instantly share code, notes, and snippets.

@lmayorga1980
Last active March 26, 2022 12:06
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save lmayorga1980/7cac12743ae37c0c3460b135a99021c1 to your computer and use it in GitHub Desktop.
Save lmayorga1980/7cac12743ae37c0c3460b135a99021c1 to your computer and use it in GitHub Desktop.
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