Skip to content

Instantly share code, notes, and snippets.

What would you like to do?
Importing AWS resources to terraform.txt
1. Install Terraform on mac
brew install hashicorp/tap/terraform
brew install terraform
2. Install the awscli
brew install awscli
3. Configure the credentials
aws configure
It will create 2 files
4. Install terraformer tool
To import the existing resources from (AWS, Google cloud,AZURE)
brew install terraformer
5. Create a file with the following content
mkdir -p test
cd test
provider "aws" {
region = "ap-south-1"
terraform init
6. To import all the existing resources from your AWS account
terraformer import aws --resources="*" --connect=true --regions=ap-south-1
terraformer import aws --resources=aws_instance --connect=true --regions=ap-south-1
7. This will generate Terraform files for the existing resources (instance)
├── generated
│   └── aws
│   └── ec2_instance
│   ├──
│   ├──
│   ├──
│   └── terraform.tfstate
8. Now we can control the exisitng resources
cd generated/aws/ec2_instance/
terraform state replace-provider -auto-approve "" "hashicorp/aws"
terraform init
terraform refresh
To change the setting of a resource after editing the respective resource tf file
terraform plan
terraform apply
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment