0
votes

Hey I started migrating infrastructure to terraform and came across few questions that are hard for me to answer

  1. How to easily swap between different projects, assuming I have same resources in few projects separated by environments. Do I store it all in one tfstate - or do I have multiple ones ? Is it stored in one bucket or few buckets or somewhere else entirely

  2. Can you create a new project with some random number at the end and automatically deploy resources to it

  3. If you can create new project and deploy to it - how do you enable the API for terraform to work - like iam.googleapis.com etc.

1
I know this lecture helped me when I started migrating to terraform: youtube.com/watch?v=wgzgVm7Sqlk. It's useful to some of your questions - ofirule

1 Answers

0
votes

Here, some pieces of answer to your questions

  1. If you use only one terraform, you use only 1 tfstate. By the way, when you would like to update a project, you have to take into account all the dependencies in all project (and you risk to break other projects), the file are bigger and harder to maintain... I recommend you to have 1 terraform per project, and 1 TF state per project. If you use common pattern (IP naming, VM settings,...) you can create modules to import in the terraform of each project.
  2. (and 3) Yes, you can create and deploy then. But I don't recommend it for a separation of concern. Use a terraform to manage your ressources' organisation (projects, folders, ....) Another one to manage your infrastructure.

A good way to think is: Build once, maintain a lot! So the build phase is not the hardest, but having something maintainable, easy to read, concise is hard!!