google-cloud-platformterraformterraform-provider-gcpterraform-template-file

Provision multiple environment of infrastructure reusing Terraform code


Im new to Terraform and I have this doubt. I've created a set of multiple resources for GCP (instances, vpc, subnet, secret manager, etc), so far so good, but the requirement is to re-use the same code for multiple future deployments (not environments). That means, this week I'll deploy the whole set for an specific region with specific names, next week I might need to deploy the same set for another region with different names and two weeks later another (but the previous ones won't be deleted), the resources will always remain the same and will be used for PROD activities.

What would be the best way to achieve this? Thanks.


Solution

  • I solved this by using workspaces, simple creating a new workspace for each deployment with terraform workspace new and deploying from that workspace in particular. If another set of infra needed to be deploy, I create a new one, change and re-deploy again, using the same code for all deploys.