Importing AWS resources to terraform.txt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 | |
/Users/kiran_chavala/.aws/config | |
/Users/kiran_chavala/.aws/credentials | |
4. Install terraformer tool | |
To import the existing resources from (AWS, Google cloud,AZURE) | |
https://github.com/GoogleCloudPlatform/terraformer | |
brew install terraformer | |
5. Create a provider.tf file with the following content | |
mkdir -p test | |
cd test | |
vi provider.tf | |
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 | |
│ ├── instance.tf | |
│ ├── outputs.tf | |
│ ├── provider.tf | |
│ └── terraform.tfstate | |
└── main.tf | |
8. Now we can control the exisitng resources | |
cd generated/aws/ec2_instance/ | |
terraform state replace-provider -auto-approve "registry.terraform.io/-/aws" "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