Bringing Brownfield AWS Infrastructure Deployment into Terraform managed control

It is easy to raise a AWS infrastructure using Terraform IaC in case of greenfield deployments.

But how about the existing infrastructure in AWS that lets’ say was spawned either using cloud formation templates or even manually.

Spotlight, terraform import.

The import option of terraform command line, can help you create state file that adds the AWS deployed resource as terraform managed resource. There is some work involved though. You will need to create the main.tf file, defining your infrastructure resources as they exist using their resource names as you have created them.

For instance, a resource named EgressVPC and its subnet, Egress-Public-AZ2, will need to have following entries in main.tf entered by author,

Likewise all your AWS resources will need to be mentioned manually or through some manually crafted intelligent automation scripting that generates your main.tf file, along side the existing AWS resource id, to be used with terraform import command.

Once you have your resources defined in main.tf, run import option for each resources, like below:

# terraform import aws_vpc.EgressVPC vpc-051f9b4xxxxxxxx

# terraform import aws_subnet.Egress-Public-AZ2 subnet-01a35b6bxxxxxxx

This creates and appends your terraform.tfstates file with imported resources under its managed control. 

And yes you will need to have the resource type, resource name and resource id handy to run the import command, in the fromat above as 

<resource_type >.<resource_name> <resource_id>

Comments

Popular posts from this blog

VLAN External Network in Openshift using NMState Operators and Multus

Migrating from OpenshiftSDN to OVNKubernetes CNI

Updating Z-stream of version in Openshift Container Platform