Google Cloud: Importing resources from the Gcloud to IaaC in Terraform

Updated: Apr 22

Managing resources in the cloud can be frustrating if the infrastructure is too big or too complex.

That’s why we suggest having the resources expressed as Infrastructure as a Code(IaaC), like Terraform among others. But what IF our infrastructure was already created manually? How can we get those resources imported into Terraform? Well, our prayers were heard: Google brings us a pretty easy solution with the help of the command-line interface, with just one single command:

Gcloud alpha resource-config bulk-export --resource-format=terraform >> <file.tf>

You just need 3 things to make this command work:

  • You must have installed the google-cloud-SDK-config-connector package in your system

  • Make sure you have your google cloud credentials configured.

  • Cloud Asset API enabled

Then just run:

❯ gcloud alpha resource-config bulk-export --resource-format=terraform >> test.tf

And let the magic happen:

Exporting resource configurations…

And that’s all, all your Google Cloud infrastructure will be imported as IaaC from the cloud with just one command!


 
Hope this tip helps you! We will continue posting valuable content that will help you with your daily work and tasks.


 
You may be interested in reading

https://www.teracloud.io/single-post/2019/10/24/my-experience-with-aws-china

Leandro Mansilla

DevOps Engineer

Teracloud

    0