diff --git a/modules/cloudbuild/README.md b/modules/cloudbuild/README.md index 3622c28e..434cefbc 100644 --- a/modules/cloudbuild/README.md +++ b/modules/cloudbuild/README.md @@ -53,9 +53,10 @@ Functional examples and sample Cloud Build definitions are included in the [exam |------|-------------|------|---------|:--------:| | activate\_apis | List of APIs to enable in the Cloudbuild project. | `list(string)` |
[
"serviceusage.googleapis.com",
"servicenetworking.googleapis.com",
"compute.googleapis.com",
"logging.googleapis.com",
"bigquery.googleapis.com",
"cloudresourcemanager.googleapis.com",
"cloudbilling.googleapis.com",
"iam.googleapis.com",
"admin.googleapis.com",
"appengine.googleapis.com",
"storage-api.googleapis.com"
]
| no | | billing\_account | The ID of the billing account to associate projects with. | `string` | n/a | yes | -| cloud\_source\_repos | List of Cloud Source Repo's to create with CloudBuild triggers. | `list(string)` |
[
"gcp-org",
"gcp-networks",
"gcp-projects"
]
| no | +| cloud\_source\_repos | List of Cloud Source Repos to create with CloudBuild triggers. | `list(string)` |
[
"gcp-org",
"gcp-networks",
"gcp-projects"
]
| no | | cloudbuild\_apply\_filename | Path and name of Cloud Build YAML definition used for terraform apply. | `string` | `"cloudbuild-tf-apply.yaml"` | no | | cloudbuild\_plan\_filename | Path and name of Cloud Build YAML definition used for terraform plan. | `string` | `"cloudbuild-tf-plan.yaml"` | no | +| create\_cloud\_source\_repos | If shared Cloud Source Repos should be created. | `bool` | `true` | no | | default\_region | Default region to create resources where applicable. | `string` | `"us-central1"` | no | | folder\_id | The ID of a folder to host this project | `string` | `""` | no | | group\_org\_admins | Google Group for GCP Organization Administrators | `string` | n/a | yes | diff --git a/modules/cloudbuild/main.tf b/modules/cloudbuild/main.tf index fb9ec08e..7ee28fa1 100644 --- a/modules/cloudbuild/main.tf +++ b/modules/cloudbuild/main.tf @@ -144,7 +144,7 @@ resource "google_kms_crypto_key_iam_binding" "cloud_build_crypto_key_encrypter" *******************************************/ resource "google_sourcerepo_repository" "gcp_repo" { - for_each = toset(var.cloud_source_repos) + for_each = var.create_cloud_source_repos ? toset(var.cloud_source_repos) : [] project = module.cloudbuild_project.project_id name = each.value depends_on = [ @@ -157,6 +157,7 @@ resource "google_sourcerepo_repository" "gcp_repo" { *******************************************/ resource "google_project_iam_member" "org_admins_source_repo_admin" { + count = var.create_cloud_source_repos ? 1 : 0 project = module.cloudbuild_project.project_id role = "roles/source.admin" member = "group:${var.group_org_admins}" @@ -167,7 +168,7 @@ resource "google_project_iam_member" "org_admins_source_repo_admin" { ***********************************************/ resource "google_cloudbuild_trigger" "master_trigger" { - for_each = toset(var.cloud_source_repos) + for_each = var.create_cloud_source_repos ? toset(var.cloud_source_repos) : [] project = module.cloudbuild_project.project_id description = "${each.value} - terraform apply." @@ -198,7 +199,7 @@ resource "google_cloudbuild_trigger" "master_trigger" { ***********************************************/ resource "google_cloudbuild_trigger" "non_master_trigger" { - for_each = toset(var.cloud_source_repos) + for_each = var.create_cloud_source_repos ? toset(var.cloud_source_repos) : [] project = module.cloudbuild_project.project_id description = "${each.value} - terraform plan." diff --git a/modules/cloudbuild/variables.tf b/modules/cloudbuild/variables.tf index c119ba44..278040fd 100644 --- a/modules/cloudbuild/variables.tf +++ b/modules/cloudbuild/variables.tf @@ -102,8 +102,14 @@ variable "storage_bucket_labels" { default = {} } +variable "create_cloud_source_repos" { + description = "If shared Cloud Source Repos should be created." + type = bool + default = true +} + variable "cloud_source_repos" { - description = "List of Cloud Source Repo's to create with CloudBuild triggers." + description = "List of Cloud Source Repos to create with CloudBuild triggers." type = list(string) default = [