Misc Terraform Notes
Code RecipeJuly 31, 20221 min read
terraforminfrastructure-as-codeawsdevops
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:
terraform import aws_s3_bucket.bucket www.johnsosoka.comFor CloudFront distributions:
terraform import aws_cloudfront_distribution.www_distribution <Distribution ID>For DynamoDB tables:
terraform import aws_dynamodb_table.terraform-state terraform-stateReading a Hidden Terraform Variable
Variables marked as sensitive are obscured in output. To access a masked variable after running terraform apply, execute:
terraform output -raw github_deployer_user_access_key_secretThis command will display the previously hidden value in the terminal.