Skip to main content

Terraformer - reverse Terraform

· One min read

What it does​

https://github.com/GoogleCloudPlatform/terraformer

Terraformer turns existing cloud resources into Terraform code. It's useful when you're learning AWS and Terraform and want to export resources you created in the console for a course. It's also handy when bringing existing infrastructure under IaC.

Usage​

info

Here's what worked for me. I wouldn't call it best practice.

Export the AWS API credentials.

export AWS_DEFAULT_PROFILE=my-profile # ~/.aws/credentials
export AWS_ACCESS_KEY_ID=id
export AWS_SECRET_ACCESS_KEY=key

You'll also need the Terraform aws provider:

terraform {
required_version = ">= 1.3.0"

required_providers {
aws = {
source = "hashicorp/aws"
version = "4.42.0"
}
}
}

Initialize the provider, then run Terraformer against the AWS resource you want to import.

terraform init # Initialize the provider in ./.terraform
terraformer import aws --resources=route53 --regions=us-east-1 --profile my-profile
terraformer import aws --resources=route53 --regions=us-east-1 --profile my-profile --filter="Type=route53_zone;Name=tags.Name;Value=my.example.com"

Comments and reactions