My Digital Garden

Manual import of AWS Resources to Terraform

Manual import of Azure Resources to Terraform Cloud

Steps

This approach is precise but time-consuming.

  1. Ensure you have AWS CLI installed and working on your machine
  2. Ensure you have current version of Terraform CLI installed and working locally
  3. Change directory to your Terraform plan working directory
  4. Assuming you are using remote state in Terraform cloud, terraform login
  5. Ensure your local Terraform plan has a correct cloud block to define the backend (docs)
  6. If this is the first time you have imported to this plan, run terraform init
  7. If there are essential variables defined in the cloud, replicate them in a local tfvars file in your working directory - remember to add this to .gitignore.
  8. For each resource to import, add the relevant statements to your Terraform plan
  9. For each resource get the relevant name or Id from the AWS console
  10. For each resource import to the Terraform state (see examples below)
  11. If you have used a tfvars file, modify the command: terraform import -var-file="tfvars.tfvars" REST OF COMMAND
  12. As a final test, push any changes to the plan, and watch the next run in Terraform Cloud - there should be no changes

Example import statements

S3 bucket : terraform import aws_s3_bucket.RESOURCENAME BUCKETNAME

S3 bucket acl : terraform import aws_s3_bucket_acl.RESOURCENAME BUCKETNAME

See also