Converting to Terraform

Amit Pancholia
3 min readJul 2, 2021

Azure-AWS-OCI-GCP-Kubernetes Converted to Terraform format files

As Terraform popularity is increasing many companies want to use Terraform to get all its benefits. Also Multi-cloud is the new normal now, Terraform stands tall as it can be used & integrated with multiple cloud provider and its counting too.

Biggest Challenge for anyone is they have pre-existing Infrastructure created on Cloud and now that needs to be converted to manage via terraform. Just to mention here is as of now Infrastructure created via terraform can be manage & maintain via terraform. So basically reverse terraform !!!

Terraform import is basically the key through which you can bring the existing resource under terraform umbrella. Wow !!! So there is a way !!! Lets see that :

$terraform import <resource-id>

Wait !!!! Is it just this straight forward ? Then why so much buzz around it ? Yes so lets see closer on this. Import command will be executed once you have added the resource in the configuration file first and then run it. So then your resource will be in the state file. You know, Terraform works on the State files, most integral part of Terraform automation.

Hmmm okay so is it a big deal ? …..So if your infrastructure is small …its not.. but think if it is big and complicated with many Subnets and Firewall rules and authentication and integrated and ….lot of dependency …..yes then it is big deal …..so definitely you think if something can be done so we can have Configuration files automatically and then we can import it ….or even that can be done for us.

There are tools which can do that. I am putting it together here so all can be here at one place for reference …I know all you work in multi-cloud :-)

Here is the list :

Terraforming — For AWS Its Ruby based tool minimum version needed Ruby 2.3 and minimum terraform supported version 0.9.3. Works as :

  1. Export Resource to Terraform — terraforming <resource>

2. Export Terraform State — terraforming <resource> --tfstate

Transformer — For GCP — CLI Tool that generates tf or json config file and tfstate. Remote state file can be stored in the gcp bucket.

Supports AWS, Azure, Kubernetes as well along with GCP.

A2tf — For Azure — written in Python is now supporting terraform v0.12. This tool reads an Azure Subscription and generates all the required terraform configuration files (.tf) from each of the composite Azure Resource Groups. Also imports the terraform state using terraform import and runs plan command.

k2tf — For Kubernetes — Kubernetes YAML to Terraform HCL converter. Convert a single YAML file and write generated Terraform config to tf files.

k2tf -f test-fixtures/service.yaml terraform.tf

Oracle OCI — Resource Manager

Resource Manager helps you install, configure, and manage resources using terraform. While creating resource it gives option to create the stack. Allows you to share and manage infrastructure configurations and state files across multiple teams and platforms.

Share tools which you are using. Lets make the learning repository here.

Reach me out at :

--

--

Amit Pancholia

Passionate about Technology, Learning and Sharing Knowledge. Connecting, Conversing, Collaborating with People !!!!!