Terraform 1 cheatsheet

Terraform 1: State

7 common Terraform 1 tasks.

List resources in state

Show every resource Terraform tracks.

terraform state list

Show a resource in state

Print the recorded attributes of one resource.

terraform state show aws_instance.web

Rename a resource in state

Move a resource to a new address, for example after renaming it in code.

terraform state mv aws_instance.web aws_instance.app

Forget a resource

Stop tracking a resource without destroying it.

terraform state rm aws_instance.web

Caution: Terraform will no longer manage the resource, and a later apply may try to create a duplicate.

Import an existing resource

Bring a resource that already exists under Terraform's management, here an S3 bucket.

terraform import aws_s3_bucket.logs my-log-bucket

Sync state with reality

Update the state to match real infrastructure without changing anything.

terraform apply -refresh-only

Release a stuck state lock

Remove a lock that a crashed run left behind, using the lock ID from the error.

terraform force-unlock LOCK_ID

Caution: Only unlock if you are sure no other run is using the state.

Was this page helpful?