skip to content
JS John Sosoka

Misc Terraform Notes

Recovering from Lost/Deleted Remote State

When reinitializing a backend and encountering errors during terraform apply, use the terraform import command to restore resources.

For S3 buckets:

Terminal window
terraform import aws_s3_bucket.bucket www.johnsosoka.com

For CloudFront distributions:

Terminal window
terraform import aws_cloudfront_distribution.www_distribution <Distribution ID>

For DynamoDB tables:

Terminal window
terraform import aws_dynamodb_table.terraform-state terraform-state

Reading a Hidden Terraform Variable

Variables marked as sensitive are obscured in output. To access a masked variable after running terraform apply, execute:

Terminal window
terraform output -raw github_deployer_user_access_key_secret

This command will display the previously hidden value in the terminal.