diff --git a/5-appinfra/apps/accounts-contacts/envs/shared/main.tf b/5-appinfra/apps/accounts-contacts/envs/shared/main.tf index ca5b494c8..5c7f07af3 100644 --- a/5-appinfra/apps/accounts-contacts/envs/shared/main.tf +++ b/5-appinfra/apps/accounts-contacts/envs/shared/main.tf @@ -24,11 +24,9 @@ locals { module "app" { source = "../../../../modules/cicd-pipeline" - project_id = var.project_id - region = var.region - cluster_membership_id_dev = var.cluster_membership_id_dev - cluster_membership_ids_nonprod = var.cluster_membership_ids_nonprod - cluster_membership_ids_prod = var.cluster_membership_ids_prod + project_id = var.project_id + region = var.region + env_cluster_membership_ids = var.env_cluster_membership_ids service = local.service_name repo_name = local.repo_name diff --git a/5-appinfra/apps/accounts-contacts/envs/shared/variables.tf b/5-appinfra/apps/accounts-contacts/envs/shared/variables.tf index e2264359a..f07c41ae6 100644 --- a/5-appinfra/apps/accounts-contacts/envs/shared/variables.tf +++ b/5-appinfra/apps/accounts-contacts/envs/shared/variables.tf @@ -24,19 +24,11 @@ variable "region" { type = string } -variable "cluster_membership_id_dev" { - description = "Cluster fleet membership ID in development environment" - type = string -} - -variable "cluster_membership_ids_nonprod" { - description = "Cluster fleet membership IDs in nonprod environment" - type = list(string) -} - -variable "cluster_membership_ids_prod" { - description = "Cluster fleet membership IDs in prod environment" - type = list(string) +variable "env_cluster_membership_ids" { + description = "Cluster Membership IDs" + type = map(object({ + cluster_membership_ids = list(string) + })) } variable "buckets_force_destroy" { diff --git a/5-appinfra/apps/accounts-userservice/envs/shared/main.tf b/5-appinfra/apps/accounts-userservice/envs/shared/main.tf index f6ad79a19..ddbe30dc5 100644 --- a/5-appinfra/apps/accounts-userservice/envs/shared/main.tf +++ b/5-appinfra/apps/accounts-userservice/envs/shared/main.tf @@ -24,11 +24,9 @@ locals { module "app" { source = "../../../../modules/cicd-pipeline" - project_id = var.project_id - region = var.region - cluster_membership_id_dev = var.cluster_membership_id_dev - cluster_membership_ids_nonprod = var.cluster_membership_ids_nonprod - cluster_membership_ids_prod = var.cluster_membership_ids_prod + project_id = var.project_id + region = var.region + env_cluster_membership_ids = var.env_cluster_membership_ids service = local.service_name repo_name = local.repo_name diff --git a/5-appinfra/apps/accounts-userservice/envs/shared/variables.tf b/5-appinfra/apps/accounts-userservice/envs/shared/variables.tf index e2264359a..f07c41ae6 100644 --- a/5-appinfra/apps/accounts-userservice/envs/shared/variables.tf +++ b/5-appinfra/apps/accounts-userservice/envs/shared/variables.tf @@ -24,19 +24,11 @@ variable "region" { type = string } -variable "cluster_membership_id_dev" { - description = "Cluster fleet membership ID in development environment" - type = string -} - -variable "cluster_membership_ids_nonprod" { - description = "Cluster fleet membership IDs in nonprod environment" - type = list(string) -} - -variable "cluster_membership_ids_prod" { - description = "Cluster fleet membership IDs in prod environment" - type = list(string) +variable "env_cluster_membership_ids" { + description = "Cluster Membership IDs" + type = map(object({ + cluster_membership_ids = list(string) + })) } variable "buckets_force_destroy" { diff --git a/5-appinfra/apps/frontend/envs/shared/main.tf b/5-appinfra/apps/frontend/envs/shared/main.tf index b2a1f87a3..e328a888b 100644 --- a/5-appinfra/apps/frontend/envs/shared/main.tf +++ b/5-appinfra/apps/frontend/envs/shared/main.tf @@ -24,11 +24,9 @@ locals { module "app" { source = "../../../../modules/cicd-pipeline" - project_id = var.project_id - region = var.region - cluster_membership_id_dev = var.cluster_membership_id_dev - cluster_membership_ids_nonprod = var.cluster_membership_ids_nonprod - cluster_membership_ids_prod = var.cluster_membership_ids_prod + project_id = var.project_id + region = var.region + env_cluster_membership_ids = var.env_cluster_membership_ids service = local.service_name repo_name = local.repo_name diff --git a/5-appinfra/apps/frontend/envs/shared/variables.tf b/5-appinfra/apps/frontend/envs/shared/variables.tf index e2264359a..f07c41ae6 100644 --- a/5-appinfra/apps/frontend/envs/shared/variables.tf +++ b/5-appinfra/apps/frontend/envs/shared/variables.tf @@ -24,19 +24,11 @@ variable "region" { type = string } -variable "cluster_membership_id_dev" { - description = "Cluster fleet membership ID in development environment" - type = string -} - -variable "cluster_membership_ids_nonprod" { - description = "Cluster fleet membership IDs in nonprod environment" - type = list(string) -} - -variable "cluster_membership_ids_prod" { - description = "Cluster fleet membership IDs in prod environment" - type = list(string) +variable "env_cluster_membership_ids" { + description = "Cluster Membership IDs" + type = map(object({ + cluster_membership_ids = list(string) + })) } variable "buckets_force_destroy" { diff --git a/5-appinfra/apps/ledger-balancereader/envs/shared/main.tf b/5-appinfra/apps/ledger-balancereader/envs/shared/main.tf index 15b3e0143..6b6177cad 100644 --- a/5-appinfra/apps/ledger-balancereader/envs/shared/main.tf +++ b/5-appinfra/apps/ledger-balancereader/envs/shared/main.tf @@ -24,11 +24,9 @@ locals { module "app" { source = "../../../../modules/cicd-pipeline" - project_id = var.project_id - region = var.region - cluster_membership_id_dev = var.cluster_membership_id_dev - cluster_membership_ids_nonprod = var.cluster_membership_ids_nonprod - cluster_membership_ids_prod = var.cluster_membership_ids_prod + project_id = var.project_id + region = var.region + env_cluster_membership_ids = var.env_cluster_membership_ids service = local.service_name repo_name = local.repo_name diff --git a/5-appinfra/apps/ledger-balancereader/envs/shared/variables.tf b/5-appinfra/apps/ledger-balancereader/envs/shared/variables.tf index e2264359a..f07c41ae6 100644 --- a/5-appinfra/apps/ledger-balancereader/envs/shared/variables.tf +++ b/5-appinfra/apps/ledger-balancereader/envs/shared/variables.tf @@ -24,19 +24,11 @@ variable "region" { type = string } -variable "cluster_membership_id_dev" { - description = "Cluster fleet membership ID in development environment" - type = string -} - -variable "cluster_membership_ids_nonprod" { - description = "Cluster fleet membership IDs in nonprod environment" - type = list(string) -} - -variable "cluster_membership_ids_prod" { - description = "Cluster fleet membership IDs in prod environment" - type = list(string) +variable "env_cluster_membership_ids" { + description = "Cluster Membership IDs" + type = map(object({ + cluster_membership_ids = list(string) + })) } variable "buckets_force_destroy" { diff --git a/5-appinfra/apps/ledger-ledgerwriter/envs/shared/main.tf b/5-appinfra/apps/ledger-ledgerwriter/envs/shared/main.tf index 6ce502fbb..a3848deb5 100644 --- a/5-appinfra/apps/ledger-ledgerwriter/envs/shared/main.tf +++ b/5-appinfra/apps/ledger-ledgerwriter/envs/shared/main.tf @@ -24,11 +24,9 @@ locals { module "app" { source = "../../../../modules/cicd-pipeline" - project_id = var.project_id - region = var.region - cluster_membership_id_dev = var.cluster_membership_id_dev - cluster_membership_ids_nonprod = var.cluster_membership_ids_nonprod - cluster_membership_ids_prod = var.cluster_membership_ids_prod + project_id = var.project_id + region = var.region + env_cluster_membership_ids = var.env_cluster_membership_ids service = local.service_name repo_name = local.repo_name diff --git a/5-appinfra/apps/ledger-ledgerwriter/envs/shared/variables.tf b/5-appinfra/apps/ledger-ledgerwriter/envs/shared/variables.tf index e2264359a..f07c41ae6 100644 --- a/5-appinfra/apps/ledger-ledgerwriter/envs/shared/variables.tf +++ b/5-appinfra/apps/ledger-ledgerwriter/envs/shared/variables.tf @@ -24,19 +24,11 @@ variable "region" { type = string } -variable "cluster_membership_id_dev" { - description = "Cluster fleet membership ID in development environment" - type = string -} - -variable "cluster_membership_ids_nonprod" { - description = "Cluster fleet membership IDs in nonprod environment" - type = list(string) -} - -variable "cluster_membership_ids_prod" { - description = "Cluster fleet membership IDs in prod environment" - type = list(string) +variable "env_cluster_membership_ids" { + description = "Cluster Membership IDs" + type = map(object({ + cluster_membership_ids = list(string) + })) } variable "buckets_force_destroy" { diff --git a/5-appinfra/apps/ledger-transactionhistory/envs/shared/main.tf b/5-appinfra/apps/ledger-transactionhistory/envs/shared/main.tf index 34b4813b1..e81e4e219 100644 --- a/5-appinfra/apps/ledger-transactionhistory/envs/shared/main.tf +++ b/5-appinfra/apps/ledger-transactionhistory/envs/shared/main.tf @@ -24,11 +24,9 @@ locals { module "app" { source = "../../../../modules/cicd-pipeline" - project_id = var.project_id - region = var.region - cluster_membership_id_dev = var.cluster_membership_id_dev - cluster_membership_ids_nonprod = var.cluster_membership_ids_nonprod - cluster_membership_ids_prod = var.cluster_membership_ids_prod + project_id = var.project_id + region = var.region + env_cluster_membership_ids = var.env_cluster_membership_ids service = local.service_name repo_name = local.repo_name diff --git a/5-appinfra/apps/ledger-transactionhistory/envs/shared/variables.tf b/5-appinfra/apps/ledger-transactionhistory/envs/shared/variables.tf index e2264359a..f07c41ae6 100644 --- a/5-appinfra/apps/ledger-transactionhistory/envs/shared/variables.tf +++ b/5-appinfra/apps/ledger-transactionhistory/envs/shared/variables.tf @@ -24,19 +24,11 @@ variable "region" { type = string } -variable "cluster_membership_id_dev" { - description = "Cluster fleet membership ID in development environment" - type = string -} - -variable "cluster_membership_ids_nonprod" { - description = "Cluster fleet membership IDs in nonprod environment" - type = list(string) -} - -variable "cluster_membership_ids_prod" { - description = "Cluster fleet membership IDs in prod environment" - type = list(string) +variable "env_cluster_membership_ids" { + description = "Cluster Membership IDs" + type = map(object({ + cluster_membership_ids = list(string) + })) } variable "buckets_force_destroy" { diff --git a/5-appinfra/modules/cicd-pipeline/README.md b/5-appinfra/modules/cicd-pipeline/README.md index 5d56f4150..064a113b1 100644 --- a/5-appinfra/modules/cicd-pipeline/README.md +++ b/5-appinfra/modules/cicd-pipeline/README.md @@ -6,9 +6,7 @@ | Name | Description | Type | Default | Required | |------|-------------|------|---------|:--------:| | buckets\_force\_destroy | When deleting the bucket for storing CICD artifacts, this boolean option will delete all contained objects. If false, Terraform will fail to delete buckets which contain objects. | `bool` | `false` | no | -| cluster\_membership\_id\_dev | Fleet membership ID for the cluster in development environment | `string` | n/a | yes | -| cluster\_membership\_ids\_nonprod | Fleet membership IDs for the cluster in non-production environment | `list(string)` | n/a | yes | -| cluster\_membership\_ids\_prod | Fleet membership IDs for the cluster in production environment | `list(string)` | n/a | yes | +| env\_cluster\_membership\_ids | Env Cluster Membership IDs |
map(object({
cluster_membership_ids = list(string)
}))
| n/a | yes | | project\_id | CI/CD project ID | `string` | n/a | yes | | region | CI/CD Region (e.g. us-central1) | `string` | n/a | yes | | repo\_branch | Branch to sync ACM configs from & trigger CICD if pushed to. | `string` | n/a | yes | diff --git a/5-appinfra/modules/cicd-pipeline/cloud-deploy.tf b/5-appinfra/modules/cicd-pipeline/cloud-deploy.tf index 46a2d177e..dc7491366 100644 --- a/5-appinfra/modules/cicd-pipeline/cloud-deploy.tf +++ b/5-appinfra/modules/cicd-pipeline/cloud-deploy.tf @@ -19,9 +19,9 @@ resource "google_clouddeploy_delivery_pipeline" "delivery-pipeline" { name = local.service_name serial_pipeline { dynamic "stages" { - for_each = { for idx, target in local.targets : idx => target } + for_each = google_clouddeploy_target.clouddeploy_targets content { - # TODO: use "production" profile once it works. + # TODO: use "production" profile once validated. profiles = [stages.value.name == "${local.service_name}-dev" ? "development" : (startswith(stages.value.name, "${local.service_name}-nonprod") ? "staging" : "production")] target_id = stages.value.name } diff --git a/5-appinfra/modules/cicd-pipeline/locals.tf b/5-appinfra/modules/cicd-pipeline/locals.tf index c718f54ff..ca26028e2 100644 --- a/5-appinfra/modules/cicd-pipeline/locals.tf +++ b/5-appinfra/modules/cicd-pipeline/locals.tf @@ -17,6 +17,5 @@ locals { service_name = reverse(split("-", var.service))[0] team_name = split("-", var.service)[0] service_clean = replace(var.service, "/", "-") - targets = [google_clouddeploy_target.development, google_clouddeploy_target.non_prod[0], google_clouddeploy_target.non_prod[1], google_clouddeploy_target.prod[0], google_clouddeploy_target.prod[1]] container_registry = google_artifact_registry_repository.container_registry } diff --git a/5-appinfra/modules/cicd-pipeline/pipelines.tf b/5-appinfra/modules/cicd-pipeline/pipelines.tf index 06d1777f5..d657dc687 100644 --- a/5-appinfra/modules/cicd-pipeline/pipelines.tf +++ b/5-appinfra/modules/cicd-pipeline/pipelines.tf @@ -26,50 +26,16 @@ resource "google_service_account" "cloud_deploy" { create_ignore_already_exists = true } -resource "google_clouddeploy_target" "development" { - # one CloudDeploy target per target defined in vars +resource "google_clouddeploy_target" "clouddeploy_targets" { + # one CloudDeploy target per cluster_membership_id defined in vars + for_each = merge([ + for key, value in var.env_cluster_membership_ids : { + for item in value.cluster_membership_ids : "${key}-${item}" => item + } + ]...) project = var.project_id - name = "${local.service_name}-dev" - location = var.region - - anthos_cluster { - membership = regex(local.fleet_membership_re, var.cluster_membership_id_dev)[0] - } - - execution_configs { - artifact_storage = "gs://${google_storage_bucket.delivery_artifacts_development.name}" - service_account = google_service_account.cloud_deploy.email - usages = [ - "RENDER", - "DEPLOY" - ] - } -} - -# GCS bucket used by Cloud Deploy for delivery artifact storage -resource "google_storage_bucket" "delivery_artifacts_development" { - project = var.project_id - name = "delivery-artifacts-development-${data.google_project.project.number}-${local.service_name}" - uniform_bucket_level_access = true - location = var.region - force_destroy = var.buckets_force_destroy -} - -# give CloudDeploy SA access to administrate to delivery artifact bucket -resource "google_storage_bucket_iam_member" "delivery_artifacts_development" { - bucket = google_storage_bucket.delivery_artifacts_development.name - - member = "serviceAccount:${google_service_account.cloud_deploy.email}" - role = "roles/storage.admin" -} - -resource "google_clouddeploy_target" "non_prod" { - # one CloudDeploy target per target defined in vars - for_each = { for i, v in var.cluster_membership_ids_nonprod : i => v } - - project = var.project_id - name = "${local.service_name}-nonprod-${each.key}" + name = "${local.service_name}-${split("-", each.key)[0]}" location = var.region anthos_cluster { @@ -77,66 +43,33 @@ resource "google_clouddeploy_target" "non_prod" { } execution_configs { - artifact_storage = "gs://${google_storage_bucket.delivery_artifacts_non_prod.name}" + artifact_storage = "gs://${google_storage_bucket.delivery_artifacts[split("-", each.key)[0]].name}" service_account = google_service_account.cloud_deploy.email usages = [ "RENDER", "DEPLOY" ] } -} - -# GCS bucket used by Cloud Deploy for delivery artifact storage -resource "google_storage_bucket" "delivery_artifacts_non_prod" { - project = var.project_id - name = "delivery-artifacts-non-prod-${data.google_project.project.number}-${local.service_name}" - uniform_bucket_level_access = true - location = var.region - force_destroy = var.buckets_force_destroy -} - -# give CloudDeploy SA access to administrate to delivery artifact bucket -resource "google_storage_bucket_iam_member" "delivery_artifacts_non_prod" { - bucket = google_storage_bucket.delivery_artifacts_non_prod.name - - member = "serviceAccount:${google_service_account.cloud_deploy.email}" - role = "roles/storage.admin" -} - -resource "google_clouddeploy_target" "prod" { - # one CloudDeploy target per target defined in vars - for_each = { for i, v in var.cluster_membership_ids_prod : i => v } - - project = var.project_id - name = "${local.service_name}-prod-${each.key}" - location = var.region - - anthos_cluster { - membership = regex(local.fleet_membership_re, each.value)[0] - } - execution_configs { - artifact_storage = "gs://${google_storage_bucket.delivery_artifacts_prod.name}" - service_account = google_service_account.cloud_deploy.email - usages = [ - "RENDER", - "DEPLOY" - ] - } + depends_on = [google_storage_bucket.delivery_artifacts] } # GCS bucket used by Cloud Deploy for delivery artifact storage -resource "google_storage_bucket" "delivery_artifacts_prod" { +resource "google_storage_bucket" "delivery_artifacts" { + for_each = var.env_cluster_membership_ids + project = var.project_id - name = "delivery-artifacts-prod-${data.google_project.project.number}-${local.service_name}" + name = "delivery-artifacts-${each.key}-${data.google_project.project.number}-${local.service_name}" uniform_bucket_level_access = true location = var.region force_destroy = var.buckets_force_destroy } # give CloudDeploy SA access to administrate to delivery artifact bucket -resource "google_storage_bucket_iam_member" "delivery_artifacts_prod" { - bucket = google_storage_bucket.delivery_artifacts_prod.name +resource "google_storage_bucket_iam_member" "delivery_artifacts" { + for_each = var.env_cluster_membership_ids + + bucket = google_storage_bucket.delivery_artifacts[each.key].name member = "serviceAccount:${google_service_account.cloud_deploy.email}" role = "roles/storage.admin" diff --git a/5-appinfra/modules/cicd-pipeline/project-iam-bindings.tf b/5-appinfra/modules/cicd-pipeline/project-iam-bindings.tf index 76892c067..95444856b 100644 --- a/5-appinfra/modules/cicd-pipeline/project-iam-bindings.tf +++ b/5-appinfra/modules/cicd-pipeline/project-iam-bindings.tf @@ -15,14 +15,18 @@ locals { cloud_build_sas = ["serviceAccount:${google_service_account.cloud_build.email}"] # cloud build service accounts used for CI membership_re = "projects/([^/]*)/locations/([^/]*)/memberships/([^/]*)$" - gke_projects = [regex(local.membership_re, var.cluster_membership_id_dev)[0], regex(local.membership_re, var.cluster_membership_ids_nonprod[0])[0], regex(local.membership_re, var.cluster_membership_ids_prod[0])[0]] + gke_projects = distinct(flatten([ + for _, value in var.env_cluster_membership_ids : [ + for item in value.cluster_membership_ids : regex(local.membership_re, item)[0] + ] + ])) } # authoritative project-iam-bindings to increase reproducibility module "project-iam-bindings" { source = "terraform-google-modules/iam/google//modules/projects_iam" version = "~> 7.7" - projects = [var.project_id] + projects = concat([var.project_id], local.gke_projects) mode = "authoritative" bindings = { diff --git a/5-appinfra/modules/cicd-pipeline/variables.tf b/5-appinfra/modules/cicd-pipeline/variables.tf index b9c21b650..4f177c351 100644 --- a/5-appinfra/modules/cicd-pipeline/variables.tf +++ b/5-appinfra/modules/cicd-pipeline/variables.tf @@ -22,19 +22,11 @@ variable "region" { description = "CI/CD Region (e.g. us-central1)" } -variable "cluster_membership_id_dev" { - type = string - description = "Fleet membership ID for the cluster in development environment" -} - -variable "cluster_membership_ids_nonprod" { - type = list(string) - description = "Fleet membership IDs for the cluster in non-production environment" -} - -variable "cluster_membership_ids_prod" { - type = list(string) - description = "Fleet membership IDs for the cluster in production environment" +variable "env_cluster_membership_ids" { + description = "Env Cluster Membership IDs" + type = map(object({ + cluster_membership_ids = list(string) + })) } variable "service" { diff --git a/test/integration/appinfra/accounts_contacts_test.go b/test/integration/appinfra/accounts_contacts_test.go index 91fa3a898..c5614a51c 100644 --- a/test/integration/appinfra/accounts_contacts_test.go +++ b/test/integration/appinfra/accounts_contacts_test.go @@ -15,6 +15,7 @@ package frontend import ( + "fmt" "testing" "time" @@ -24,19 +25,20 @@ import ( ) func TestAppInfraContacts(t *testing.T) { - multitenant := tft.NewTFBlueprintTest(t, tft.WithTFDir("../../../2-multitenant/envs/development")) - multitenant_nonprod := tft.NewTFBlueprintTest(t, tft.WithTFDir("../../../2-multitenant/envs/non-production")) - multitenant_prod := tft.NewTFBlueprintTest(t, tft.WithTFDir("../../../2-multitenant/envs/production")) appFactory := tft.NewTFBlueprintTest(t, tft.WithTFDir("../../../3-appfactory/apps/cymbal-bank")) projectID := appFactory.GetJsonOutput("app-group").Get("contacts.app_admin_project_id").String() + env_cluster_membership_ids := make(map[string]map[string][]string, 0) + for _, envName := range testutils.EnvNames { + env_cluster_membership_ids[envName] = make(map[string][]string, 0) + multitenant := tft.NewTFBlueprintTest(t, tft.WithTFDir(fmt.Sprintf("../../../2-multitenant/envs/%s", envName))) + env_cluster_membership_ids[envName]["cluster_membership_ids"] = testutils.GetBptOutputStrSlice(multitenant, "cluster_membership_ids") + } + vars := map[string]interface{}{ "project_id": projectID, - "region": testutils.GetBptOutputStrSlice(multitenant, "cluster_regions")[0], - // TODO: Convert to a dynamic array - "cluster_membership_id_dev": testutils.GetBptOutputStrSlice(multitenant, "cluster_membership_ids")[0], - "cluster_membership_ids_nonprod": testutils.GetBptOutputStrSlice(multitenant_nonprod, "cluster_membership_ids"), - "cluster_membership_ids_prod": testutils.GetBptOutputStrSlice(multitenant_prod, "cluster_membership_ids"), + "region": "us-central1", // TODO: Move to terraform.tfvars? + "env_cluster_membership_ids": env_cluster_membership_ids, "buckets_force_destroy": "true", } frontend := tft.NewTFBlueprintTest(t, diff --git a/test/integration/appinfra/accounts_userservice_test.go b/test/integration/appinfra/accounts_userservice_test.go index cb073fbb1..0bd9c974f 100644 --- a/test/integration/appinfra/accounts_userservice_test.go +++ b/test/integration/appinfra/accounts_userservice_test.go @@ -15,6 +15,7 @@ package frontend import ( + "fmt" "testing" "time" @@ -24,19 +25,20 @@ import ( ) func TestAppInfraUserservice(t *testing.T) { - multitenant := tft.NewTFBlueprintTest(t, tft.WithTFDir("../../../2-multitenant/envs/development")) - multitenant_nonprod := tft.NewTFBlueprintTest(t, tft.WithTFDir("../../../2-multitenant/envs/non-production")) - multitenant_prod := tft.NewTFBlueprintTest(t, tft.WithTFDir("../../../2-multitenant/envs/production")) appFactory := tft.NewTFBlueprintTest(t, tft.WithTFDir("../../../3-appfactory/apps/cymbal-bank")) projectID := appFactory.GetJsonOutput("app-group").Get("userservice.app_admin_project_id").String() + env_cluster_membership_ids := make(map[string]map[string][]string, 0) + for _, envName := range testutils.EnvNames { + env_cluster_membership_ids[envName] = make(map[string][]string, 0) + multitenant := tft.NewTFBlueprintTest(t, tft.WithTFDir(fmt.Sprintf("../../../2-multitenant/envs/%s", envName))) + env_cluster_membership_ids[envName]["cluster_membership_ids"] = testutils.GetBptOutputStrSlice(multitenant, "cluster_membership_ids") + } + vars := map[string]interface{}{ "project_id": projectID, - "region": testutils.GetBptOutputStrSlice(multitenant, "cluster_regions")[0], - // TODO: Convert to a dynamic array - "cluster_membership_id_dev": testutils.GetBptOutputStrSlice(multitenant, "cluster_membership_ids")[0], - "cluster_membership_ids_nonprod": testutils.GetBptOutputStrSlice(multitenant_nonprod, "cluster_membership_ids"), - "cluster_membership_ids_prod": testutils.GetBptOutputStrSlice(multitenant_prod, "cluster_membership_ids"), + "region": "us-central1", // TODO: Move to terraform.tfvars? + "env_cluster_membership_ids": env_cluster_membership_ids, "buckets_force_destroy": "true", } frontend := tft.NewTFBlueprintTest(t, diff --git a/test/integration/appinfra/frontend_test.go b/test/integration/appinfra/frontend_test.go index 17070c43d..8f41912ef 100644 --- a/test/integration/appinfra/frontend_test.go +++ b/test/integration/appinfra/frontend_test.go @@ -30,19 +30,22 @@ import ( // TOOD: Update to a single parallel TestAppInfra test // https://github.com/GoogleCloudPlatform/terraform-google-enterprise-application/pull/107 func TestAppInfraFrontend(t *testing.T) { - multitenant := tft.NewTFBlueprintTest(t, tft.WithTFDir("../../../2-multitenant/envs/development")) - multitenant_nonprod := tft.NewTFBlueprintTest(t, tft.WithTFDir("../../../2-multitenant/envs/non-production")) - multitenant_prod := tft.NewTFBlueprintTest(t, tft.WithTFDir("../../../2-multitenant/envs/production")) appFactory := tft.NewTFBlueprintTest(t, tft.WithTFDir("../../../3-appfactory/apps/cymbal-bank")) projectID := appFactory.GetJsonOutput("app-group").Get("frontend.app_admin_project_id").String() + env_cluster_membership_ids := make(map[string]map[string][]string, 0) + for _, envName := range testutils.EnvNames { + env_cluster_membership_ids[envName] = make(map[string][]string, 0) + multitenant := tft.NewTFBlueprintTest(t, tft.WithTFDir(fmt.Sprintf("../../../2-multitenant/envs/%s", envName))) + env_cluster_membership_ids[envName]["cluster_membership_ids"] = testutils.GetBptOutputStrSlice(multitenant, "cluster_membership_ids") + } + + region := "us-central1" // TODO: Move to terraform.tfvars? + vars := map[string]interface{}{ "project_id": projectID, - "region": testutils.GetBptOutputStrSlice(multitenant, "cluster_regions")[0], - // TODO: Convert to a dynamic array - "cluster_membership_id_dev": testutils.GetBptOutputStrSlice(multitenant, "cluster_membership_ids")[0], - "cluster_membership_ids_nonprod": testutils.GetBptOutputStrSlice(multitenant_nonprod, "cluster_membership_ids"), - "cluster_membership_ids_prod": testutils.GetBptOutputStrSlice(multitenant_prod, "cluster_membership_ids"), + "region": region, + "env_cluster_membership_ids": env_cluster_membership_ids, "buckets_force_destroy": "true", } frontend := tft.NewTFBlueprintTest(t, @@ -199,12 +202,10 @@ func TestAppInfraFrontend(t *testing.T) { cloudDeployTargets := []string{ fmt.Sprintf("%s-dev", serviceName), } - for i := range testutils.GetBptOutputStrSlice(multitenant_nonprod, "cluster_membership_ids") { - cloudDeployTargets = append(cloudDeployTargets, fmt.Sprintf("%s-nonprod-%d", serviceName, i)) - } - - for i := range testutils.GetBptOutputStrSlice(multitenant_prod, "cluster_membership_ids") { - cloudDeployTargets = append(cloudDeployTargets, fmt.Sprintf("%s-prod-%d", serviceName, i)) + for env, v := range env_cluster_membership_ids { + for i := range v["cluster_membership_ids"] { + cloudDeployTargets = append(cloudDeployTargets, fmt.Sprintf("%s-%s-%d", serviceName, env, i)) + } } for _, targetName := range cloudDeployTargets { diff --git a/test/integration/appinfra/ledger_balancereader_test.go b/test/integration/appinfra/ledger_balancereader_test.go index 3d8dcae8a..014244b01 100644 --- a/test/integration/appinfra/ledger_balancereader_test.go +++ b/test/integration/appinfra/ledger_balancereader_test.go @@ -15,6 +15,7 @@ package frontend import ( + "fmt" "testing" "time" @@ -24,19 +25,20 @@ import ( ) func TestAppInfraBalancereader(t *testing.T) { - multitenant := tft.NewTFBlueprintTest(t, tft.WithTFDir("../../../2-multitenant/envs/development")) - multitenant_nonprod := tft.NewTFBlueprintTest(t, tft.WithTFDir("../../../2-multitenant/envs/non-production")) - multitenant_prod := tft.NewTFBlueprintTest(t, tft.WithTFDir("../../../2-multitenant/envs/production")) appFactory := tft.NewTFBlueprintTest(t, tft.WithTFDir("../../../3-appfactory/apps/cymbal-bank")) projectID := appFactory.GetJsonOutput("app-group").Get("balancereader.app_admin_project_id").String() + env_cluster_membership_ids := make(map[string]map[string][]string, 0) + for _, envName := range testutils.EnvNames { + env_cluster_membership_ids[envName] = make(map[string][]string, 0) + multitenant := tft.NewTFBlueprintTest(t, tft.WithTFDir(fmt.Sprintf("../../../2-multitenant/envs/%s", envName))) + env_cluster_membership_ids[envName]["cluster_membership_ids"] = testutils.GetBptOutputStrSlice(multitenant, "cluster_membership_ids") + } + vars := map[string]interface{}{ "project_id": projectID, - "region": testutils.GetBptOutputStrSlice(multitenant, "cluster_regions")[0], - // TODO: Convert to a dynamic array - "cluster_membership_id_dev": testutils.GetBptOutputStrSlice(multitenant, "cluster_membership_ids")[0], - "cluster_membership_ids_nonprod": testutils.GetBptOutputStrSlice(multitenant_nonprod, "cluster_membership_ids"), - "cluster_membership_ids_prod": testutils.GetBptOutputStrSlice(multitenant_prod, "cluster_membership_ids"), + "region": "us-central1", // TODO: Move to terraform.tfvars? + "env_cluster_membership_ids": env_cluster_membership_ids, "buckets_force_destroy": "true", } frontend := tft.NewTFBlueprintTest(t, diff --git a/test/integration/appinfra/ledger_ledgerwriter_test.go b/test/integration/appinfra/ledger_ledgerwriter_test.go index 57296434c..db7294cb1 100644 --- a/test/integration/appinfra/ledger_ledgerwriter_test.go +++ b/test/integration/appinfra/ledger_ledgerwriter_test.go @@ -15,6 +15,7 @@ package frontend import ( + "fmt" "testing" "time" @@ -24,20 +25,20 @@ import ( ) func TestAppInfraLedgerwriter(t *testing.T) { - multitenant := tft.NewTFBlueprintTest(t, tft.WithTFDir("../../../2-multitenant/envs/development")) - multitenant_nonprod := tft.NewTFBlueprintTest(t, tft.WithTFDir("../../../2-multitenant/envs/non-production")) - multitenant_prod := tft.NewTFBlueprintTest(t, tft.WithTFDir("../../../2-multitenant/envs/production")) appFactory := tft.NewTFBlueprintTest(t, tft.WithTFDir("../../../3-appfactory/apps/cymbal-bank")) projectID := appFactory.GetJsonOutput("app-group").Get("ledgerwriter.app_admin_project_id").String() + env_cluster_membership_ids := make(map[string]map[string][]string, 0) + for _, envName := range testutils.EnvNames { + env_cluster_membership_ids[envName] = make(map[string][]string, 0) + multitenant := tft.NewTFBlueprintTest(t, tft.WithTFDir(fmt.Sprintf("../../../2-multitenant/envs/%s", envName))) + env_cluster_membership_ids[envName]["cluster_membership_ids"] = testutils.GetBptOutputStrSlice(multitenant, "cluster_membership_ids") + } vars := map[string]interface{}{ "project_id": projectID, - "region": testutils.GetBptOutputStrSlice(multitenant, "cluster_regions")[0], - // TODO: Convert to a dynamic array - "cluster_membership_id_dev": testutils.GetBptOutputStrSlice(multitenant, "cluster_membership_ids")[0], - "cluster_membership_ids_nonprod": testutils.GetBptOutputStrSlice(multitenant_nonprod, "cluster_membership_ids"), - "cluster_membership_ids_prod": testutils.GetBptOutputStrSlice(multitenant_prod, "cluster_membership_ids"), + "region": "us-central1", // TODO: Move to terraform.tfvars? + "env_cluster_membership_ids": env_cluster_membership_ids, "buckets_force_destroy": "true", } frontend := tft.NewTFBlueprintTest(t, @@ -47,7 +48,6 @@ func TestAppInfraLedgerwriter(t *testing.T) { ) frontend.DefineVerify(func(assert *assert.Assertions) { frontend.DefaultVerify(assert) - }) frontend.Test() } diff --git a/test/integration/appinfra/ledger_transactionhistory_test.go b/test/integration/appinfra/ledger_transactionhistory_test.go index 30b5c31f7..98c795446 100644 --- a/test/integration/appinfra/ledger_transactionhistory_test.go +++ b/test/integration/appinfra/ledger_transactionhistory_test.go @@ -15,6 +15,7 @@ package frontend import ( + "fmt" "testing" "time" @@ -24,19 +25,20 @@ import ( ) func TestAppInfraTransactionHistory(t *testing.T) { - multitenant := tft.NewTFBlueprintTest(t, tft.WithTFDir("../../../2-multitenant/envs/development")) - multitenant_nonprod := tft.NewTFBlueprintTest(t, tft.WithTFDir("../../../2-multitenant/envs/non-production")) - multitenant_prod := tft.NewTFBlueprintTest(t, tft.WithTFDir("../../../2-multitenant/envs/production")) appFactory := tft.NewTFBlueprintTest(t, tft.WithTFDir("../../../3-appfactory/apps/cymbal-bank")) projectID := appFactory.GetJsonOutput("app-group").Get("transactionhistory.app_admin_project_id").String() + env_cluster_membership_ids := make(map[string]map[string][]string, 0) + for _, envName := range testutils.EnvNames { + env_cluster_membership_ids[envName] = make(map[string][]string, 0) + multitenant := tft.NewTFBlueprintTest(t, tft.WithTFDir(fmt.Sprintf("../../../2-multitenant/envs/%s", envName))) + env_cluster_membership_ids[envName]["cluster_membership_ids"] = testutils.GetBptOutputStrSlice(multitenant, "cluster_membership_ids") + } + vars := map[string]interface{}{ "project_id": projectID, - "region": testutils.GetBptOutputStrSlice(multitenant, "cluster_regions")[0], - // TODO: Convert to a dynamic array - "cluster_membership_id_dev": testutils.GetBptOutputStrSlice(multitenant, "cluster_membership_ids")[0], - "cluster_membership_ids_nonprod": testutils.GetBptOutputStrSlice(multitenant_nonprod, "cluster_membership_ids"), - "cluster_membership_ids_prod": testutils.GetBptOutputStrSlice(multitenant_prod, "cluster_membership_ids"), + "region": "us-central1", // TODO: Move to terraform.tfvars? + "env_cluster_membership_ids": env_cluster_membership_ids, "buckets_force_destroy": "true", } frontend := tft.NewTFBlueprintTest(t, diff --git a/test/integration/appsource/cymbal_bank_test.go b/test/integration/appsource/cymbal_bank_test.go index 33c3f59e7..bfc64d130 100644 --- a/test/integration/appsource/cymbal_bank_test.go +++ b/test/integration/appsource/cymbal_bank_test.go @@ -35,10 +35,12 @@ import ( func TestSourceCymbalBank(t *testing.T) { - // TODO: switch to an array based on ENVs - multitenant := tft.NewTFBlueprintTest(t, tft.WithTFDir("../../../2-multitenant/envs/development")) - multitenant_nonprod := tft.NewTFBlueprintTest(t, tft.WithTFDir("../../../2-multitenant/envs/non-production")) - multitenant_prod := tft.NewTFBlueprintTest(t, tft.WithTFDir("../../../2-multitenant/envs/production")) + env_cluster_membership_ids := make(map[string]map[string][]string, 0) + for _, envName := range testutils.EnvNames { + env_cluster_membership_ids[envName] = make(map[string][]string, 0) + multitenant := tft.NewTFBlueprintTest(t, tft.WithTFDir(fmt.Sprintf("../../../2-multitenant/envs/%s", envName))) + env_cluster_membership_ids[envName]["cluster_membership_ids"] = testutils.GetBptOutputStrSlice(multitenant, "cluster_membership_ids") + } type ServiceInfos struct { ProjectID string @@ -50,7 +52,7 @@ func TestSourceCymbalBank(t *testing.T) { suffixServiceName string splitServiceName []string ) - region := testutils.GetBptOutputStrSlice(multitenant, "cluster_regions")[0] + region := "us-central1" // TODO: Plumb output from appInfra servicesInfoMap := make(map[string]ServiceInfos) for appName, serviceNames := range testutils.ServicesNames { @@ -86,9 +88,7 @@ func TestSourceCymbalBank(t *testing.T) { vars := map[string]interface{}{ "project_id": servicesInfoMap[serviceName].ProjectID, "region": region, - "cluster_membership_id_dev": testutils.GetBptOutputStrSlice(multitenant, "cluster_membership_ids")[0], - "cluster_membership_ids_nonprod": testutils.GetBptOutputStrSlice(multitenant_nonprod, "cluster_membership_ids"), - "cluster_membership_ids_prod": testutils.GetBptOutputStrSlice(multitenant_prod, "cluster_membership_ids"), + "env_cluster_membership_ids": env_cluster_membership_ids, "buckets_force_destroy": "true", }