Importing Existing Resources
An S3 bucket acme-logs-prod was created by hand in the console. You want Terraform to manage it without recreating it, and you would like Terraform to draft the resource code for you. What do you do?
acme-logs-prod
Choose one answer
Write a matching resource block and run terraform apply; Terraform adopts the existing bucket.
resource
terraform apply
Run terraform refresh so the bucket appears in state.
terraform refresh
Add an import block with to = aws_s3_bucket.logs and id = "acme-logs-prod", then run terraform plan -generate-config-out=generated.tf.
import
to = aws_s3_bucket.logs
id = "acme-logs-prod"
terraform plan -generate-config-out=generated.tf
Add a data "aws_s3_bucket" block, which makes Terraform manage the bucket.
data "aws_s3_bucket"