Tuesday, February 22, 2022

Reverse engineering an existing GCP project with terraformer

It can be tough to try to reverse engineer an existing project that has never used terraform. Terraformer can look at an existing project and generate the corresponding terraform code for you. 

I tried it out on an existing legacy project which used Google Cloud Storage, BigQuery and various service accounts. The setup was a little tricky so I put together a script to simply things. The script assumes you have gcloud setup or a service account key/impersonation and you may need to adjust the --resources parameter.



You may be in for a shock when you examine the generated code. Terraform works well when you think of you application are modules. A module that groups together a variety of resources (gcs bucket + service account + compute engine) that forms part of the application is far more valuable then simply considering each resource by itself. Terraformer has no idea how these resources are used or grouped. So you might need to consider refactoring the generated code into more manageable modules.

I would definitely use the tool again on projects where there is no Terraform or where there has been significant infrastructure drift. There's also Pulumi, maybe for another day.