← Back to list

gcp + terraform: workload folder and project

A simple and effective structure to organise workload in GCP.

John Zen · 2023-11-14 03:21 · 6 claps · 0.8 min read
#gcp #terraform #gcp-project #gcp-folder #workload
Open on Medium ↗
Wiki topics: ☁️ · DevOps & Cloud

gcp + terraform: workload folder and project

A simple and effective structure to organise workload in GCP.

Workloads are top level folders under organisation. Under each folder has a list of projects. i.e. a two level system.

The structure is as follow

locals {
  workloads = {
    # folder for experimental work
    "fldr-playpen" = {
      projects = {
        "prj-a-trial" = {}
        "prj-another" = {}
      }
    }

    # extract-load-transform work
    "fldr-elt" = {
      projects = {
        # for common items such as GCP Artifactory Repository (GAR), Composer and etc  
        "prj-elt-common" = {
          # enable billing
          billing_account = "123456-123456-123456"
        }
        # another project
        "prj-elt-supplychain" = {
          billing_account = "123456-123456-123456"
        }
      }
    }
  }
}

Terraform code to create folders and projects

resource "google_folder" "this" {
  for_each = local.workloads

  display_name = each.key
  parent       = "organizations/123456789012"
}

resource "google_project" "this" {
  for_each = merge(
    [
      for w, v in local.workloads :
      {
        for p, a in v.projects :
        "${w}:${p}" => {
          folder  = w
          project = p
          billing_account = contains(keys(a), "billing_account")? a.billing_account: null
        }
      }
    ]...
  )

  name       = each.value.project
  project_id = each.value.project
  folder_id  = google_folder.this[each.value.folder].id
  billing_account = each.value.billing_account
}

— The end —


메타데이터
post_id
2e232aa425e1
slug
gcp-terraform-workload-folder-and-project-2e232aa425e1
url
https://medium.com/@john.shaw.zen/gcp-terraform-workload-folder-and-project-2e232aa425e1
canonical_url
https://medium.com/@john.shaw.zen/gcp-terraform-workload-folder-and-project-2e232aa425e1
author_url
https://medium.com/@john.shaw.zen
status
ok
fetched_at
2026-06-09 15:37:30