Search code examples
google-cloud-platformterraformterraform-provider-gcp

Create a new project using outputs from Terraformer


Currently trying out a tool called Terraformer (it's a reverse Terraform) - https://github.com/GoogleCloudPlatform/terraformer.

I have a simple GCP project called test-one which only has one resource, vm_instance (google_compute_instance). I ran Terraformer and managed to get the outputs:

$ generated/google/test-one/instances/us-central1
.
├── compute_instance.tf
├── outputs.tf
├── provider.tf
└── terraform.tfstate

My question is - What should I do next if say I want to have the same exact configuration but for a new group that I'm going to name as test-two?

Should I go to each file, replace anything that has the string "test-one" to "test-two", and then perform terraform plan and terraform apply?


Solution

  • You need to create a terraform module which will deploy whatever enviroment you want and will take as few parameters as possible, only name (e.g: "test-two") if possible.

    Converting your current state to use module is not the easiest , but is usually possible without destroying any resource when using terraform import

    I would also recommend watching this video