Terraform Workspaces and State Cheat Sheet/Import with config generation

Generate configuration while importing supported resources.

Section: Import, Move, Remove

Import with config generation

bash
bash
terraform import -generate-config-out=generated.tf aws_s3_bucket.logs my-logs-bucket
Explanation

Generate configuration while importing supported resources.

Learn the surrounding workflow

Compare similar commands or jump into common fixes when this command is part of a bigger troubleshooting path.

Related commands

Same sheet · prioritizing Import, Move, Remove
Import existing object
Associate an existing infrastructure object with a resource address in state.
OpenIn sheetbashsame section
Move state address
Rename or move a resource address in state.
OpenIn sheetbashsame section
Remove resource from state
Stop tracking a resource without destroying the remote object.
OpenIn sheetbashsame section
Replace provider source in state
Update provider source addresses recorded in state.
OpenIn sheetbashsame section
List workspaces
Show available Terraform CLI workspaces for the current configuration.
OpenIn sheetbash1 tag match
Pull raw state JSON
Download the latest state and write it to a local file.
OpenIn sheetbash1 tag match