How do import blocks improve on the CLI command?
IntermediateConceptState Internals
Answer
Since Terraform 1.5 you declare import { to = ..., id = ... } in code, so imports appear in plan, can be reviewed in PRs and run through CI. terraform plan -generate-config-out=generated.tf drafts the resource configuration for you.
import {
to = aws_s3_bucket.logs
id = "acme-logs"
}
Remove the import block after apply (or leave it; it is idempotent).
More on State Internals
What does the state file contain?BeginnerWhat is the difference between local and remote state?BeginnerHow do you configure the S3 backend?BeginnerWhat is state locking and why does it matter?IntermediateHow does S3-native locking work and how does it replace DynamoDB?AdvancedHow do you inspect resources in state?Beginner