Manual import of AWS Resources to Terraform
Manual import of Azure Resources to Terraform Cloud
Steps
This approach is precise but time-consuming.
- Ensure you have AWS CLI installed and working on your machine
- Ensure you have current version of Terraform CLI installed and working locally
- Change directory to your Terraform plan working directory
- Assuming you are using remote state in Terraform cloud,
terraform login
- Ensure your local Terraform plan has a correct
cloud
block to define the backend (docs) - If this is the first time you have imported to this plan, run
terraform init
- 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
. - For each resource to import, add the relevant statements to your Terraform plan
- For each resource get the relevant name or Id from the AWS console
- For each resource import to the Terraform state (see examples below)
- If you have used a
tfvars
file, modify the command:terraform import -var-file="tfvars.tfvars" REST OF COMMAND
- 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