Terraform – Generate files based on existing infrastructure

To create Terraform files based on the existing infrastructure, we will use Terraformer

 

In this example, the macOS system will be used, so we install terraformer using homebrew:

brew install terraformer

 

Installation for other OSs can be found on the project page.

 

Create a directory for storing plugins (for working with providers)

mkdir -p ~/.terraform.d/plugins/darwin_amd64

 

 

Terraform file generation examples

AWS

We find the most current version of the darwin version, download, unzip and move the contents of the archive to the previously created directory
https://releases.hashicorp.com/terraform-provider-aws/

 

Create Terraform files for all S3 buckets and EC2 instances in the region: us-east-1

terraformer import aws --resources=s3,ec2_instance --regions=us-east-1

 

 

Kubernetes

 

kubectl must be installed and configured

 

We find the most current version of the darwin version, download, unzip and move the contents of the archive to the previously created directory

https://releases.hashicorp.com/terraform-provider-kubernetes/

 

Create Terraform files for all deployments, services and storageclasses

terraformer import kubernetes --resources=deployments,services,storageclasses

 

 

Lists of supported providers and resources can be found in more detail here.

Tagged: Tags

Subscribe
Notify of
guest

0 Comments
Inline Feedbacks
View all comments