Struggling to understand the basics — How to write 1 config and apply it to multiple GCP projects

I'm very much at the "you don't know what you don't know" phase of things right now so it's proving difficult to even Google since I don't know what terms to even look for.

We're trying to launch our product on GCP and have chosen an architecture where each client will have their own GCP project. While this saves us from the headache of dealing with multitenancy in our DBs, storage buckets, etc., it creates the problem of needing to manage and roll out infra to each new client. As our app grows, manually applying infra to each and every client has gotten more time-consuming, error-prone, and downright annoying. Enter Terraform (I think?)

We're approach Terraform usage on an as-needed basis and trying to just add bits and pieces here and there. When I need a new Cloud Storage bucket, for example, I've built the config using Terraform and attempted to deploy it.

We have our main repo of code then connect each client project's Cloud Build to that repo to get the latest changes.

For now, I'm content running Terraform from my local command line even if it means changing the gcloud project manually. 5-10x terraform apply is worlds better than doing the infra manually.

I tried using terraform apply to build a Cloud Storage Bucket in Project A. Upon switching the project to Project B and running terraform apply, the Project A bucket was removed and the Project B bucket was created. I think I understand why Terraform did this but it's certainly not my desired behavior.

I'd like to be able to change the project 10 times and get the same changes applied 10 times without affecting any other of my projects.

What workflow, terminology, process should I be investigating?

I've tried looking at workspaces but it doesn't quite seem like what I need. Any thoughts or suggestions are appreciated!

The starting point of my config is as follows:

``` terraform { required_providers { google = { source = "hashicorp/google" } } }

provider "google" { project = "project-A" }```

submitted by /u/Worldly-Hunter-354
[link] [comments]

Read more here: https://www.reddit.com/r/Terraform/comments/mmbpfv/struggling_to_understand_the_basics_how_to_write/

Content Attribution

This content was originally published by /u/Worldly-Hunter-354 at Terraform, and is syndicated here via their RSS feed. You can read the original post over there.

%d bloggers like this: