Terraform Cheat SheetEdit Cheat Sheet
Terraform Cheat SheetEdit Cheat Sheet
CLI Commands
terraform plan # dry run
terraform apply
terraform refresh # sync state with remote resources
terraform show
terraform destroy
export TF_LOG=INFO
Workspace Management
Terraform workspaces allow for the management of
two or more different environments i.e. Dev or Prod
separately without affecting the state of either
environment.
terraform workspace new dev
# for example
terraform import aws_instance.myec2instance i-075c8d21cc91308dc
as import only imports into a local state file, even if you have an S3 bucket defined for keeping
state!
To avoid this use S3 bucket with versioning enabled for keeping state.
Drift Management
Terraform doesn't really do much drift management. Only some resource attributes are
checked. All detected drift is fixed by "apply".
Prevent auto-destroy:
lifecycle {
prevent_destroy = true
}
Bulk Imports
Check out https://github.com/jmcgill/formation