norboten · cheat sheet

Terraform knows your resources by their address — cheat sheet

terraform, users-permissions
$ terraform plan                                   # refresh, compare, propose
$ terraform plan -detailed-exitcode                # 0 nothing to do, 2 changes, 1 error
$ terraform plan -refresh-only                     # only the drift between state and reality
$ terraform state list                             # addresses in state
$ terraform state show random_password.session_key # one object's recorded attributes
$ terraform state mv OLD NEW                       # one-off move in one state (writes a backup)
$ terraform apply -auto-approve                    # in automation, apply a reviewed plan instead
$ jq '.resources[].type' terraform.tfstate         # what the state holds (it is JSON)
$ chmod 600 terraform.tfstate terraform.tfstate.backup
moved {
  from = random_password.key          # old address
  to   = random_password.session_key  # new address
}
Plan says Meaning
will be destroyed (because … is not in configuration) an address exists only in state
will be created an address exists only in configuration — or the object vanished or drifted (provider-specific)
has moved to a moved block matched; no destroy
must be replaced / forces replacement an argument that cannot change in place differs
~ update in-place an attribute differs and can be changed