Skip to content

Commit

Permalink
feat: allow Cloud Source Repos to be optional (#68)
Browse files Browse the repository at this point in the history
  • Loading branch information
realtimetodie authored Oct 26, 2020
1 parent af34b11 commit 6df33bc
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 5 deletions.
3 changes: 2 additions & 1 deletion modules/cloudbuild/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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)` | <pre>[<br> "serviceusage.googleapis.com",<br> "servicenetworking.googleapis.com",<br> "compute.googleapis.com",<br> "logging.googleapis.com",<br> "bigquery.googleapis.com",<br> "cloudresourcemanager.googleapis.com",<br> "cloudbilling.googleapis.com",<br> "iam.googleapis.com",<br> "admin.googleapis.com",<br> "appengine.googleapis.com",<br> "storage-api.googleapis.com"<br>]</pre> | 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)` | <pre>[<br> "gcp-org",<br> "gcp-networks",<br> "gcp-projects"<br>]</pre> | no |
| cloud\_source\_repos | List of Cloud Source Repos to create with CloudBuild triggers. | `list(string)` | <pre>[<br> "gcp-org",<br> "gcp-networks",<br> "gcp-projects"<br>]</pre> | 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 |
Expand Down
7 changes: 4 additions & 3 deletions modules/cloudbuild/main.tf
Original file line number Diff line number Diff line change
Expand Up @@ -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 = [
Expand All @@ -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}"
Expand All @@ -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."

Expand Down Expand Up @@ -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."

Expand Down
8 changes: 7 additions & 1 deletion modules/cloudbuild/variables.tf
Original file line number Diff line number Diff line change
Expand Up @@ -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 = [
Expand Down

0 comments on commit 6df33bc

Please sign in to comment.