Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Feat: Multiple registry projects #815

Merged
merged 9 commits into from
Feb 16, 2021
Merged
Show file tree
Hide file tree
Changes from 3 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -176,7 +176,7 @@ Then perform the following commands on the root folder:
| project\_id | The project ID to host the cluster in (required) | `string` | n/a | yes |
| region | The region to host the cluster in (optional if zonal cluster / required if regional) | `string` | `null` | no |
| regional | Whether is a regional cluster (zonal cluster if set false. WARNING: changing this after cluster creation is destructive!) | `bool` | `true` | no |
| registry\_project\_id | Project holding the Google Container Registry. If empty, we use the cluster project. If grant\_registry\_access is true, storage.objectViewer role is assigned on this project. | `string` | `""` | no |
| registry\_project\_ids | Projects holding Google Container Registries. If empty, we use the cluster project. If a service account is created and the `grant_registry_access` variable is set to `true`, the `storage.objectViewer` role is assigned on these projects. | `list(string)` | `[]` | no |
| release\_channel | The release channel of this cluster. Accepted values are `UNSPECIFIED`, `RAPID`, `REGULAR` and `STABLE`. Defaults to `UNSPECIFIED`. | `string` | `null` | no |
| remove\_default\_node\_pool | Remove default node pool while setting up the cluster | `bool` | `false` | no |
| resource\_usage\_export\_dataset\_id | The ID of a BigQuery Dataset for using BigQuery as the destination of resource usage export. | `string` | `""` | no |
Expand Down Expand Up @@ -280,7 +280,7 @@ following project roles:
- roles/iam.serviceAccountUser
- roles/resourcemanager.projectIamAdmin (only required if `service_account` is set to `create`)

Additionally, if `service_account` is set to `create` and `grant_registry_access` is requested, the service account requires the following role on the `registry_project_id` project:
Additionally, if `service_account` is set to `create` and `grant_registry_access` is requested, the service account requires the following role on the `registry_project_ids` projects:
- roles/resourcemanager.projectIamAdmin

### Enable APIs
Expand Down
2 changes: 1 addition & 1 deletion autogen/main/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -241,7 +241,7 @@ following project roles:
- roles/iam.serviceAccountUser
- roles/resourcemanager.projectIamAdmin (only required if `service_account` is set to `create`)

Additionally, if `service_account` is set to `create` and `grant_registry_access` is requested, the service account requires the following role on the `registry_project_id` project:
Additionally, if `service_account` is set to `create` and `grant_registry_access` is requested, the service account requires the following role on the `registry_project_ids` projects:
- roles/resourcemanager.projectIamAdmin

### Enable APIs
Expand Down
18 changes: 10 additions & 8 deletions autogen/main/sa.tf.tmpl
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,8 @@ locals {
)
// if user set var.service_account it will be used even if var.create_service_account==true, so service account will be created but not used
service_account = (var.service_account == "" || var.service_account == "create") && var.create_service_account ? local.service_account_list[0] : var.service_account

registry_projects_list = length(var.registry_project_ids) == 0 ? [var.project_id] : var.registry_project_ids
}

resource "random_string" "cluster_service_account_suffix" {
Expand Down Expand Up @@ -70,15 +72,15 @@ resource "google_project_iam_member" "cluster_service_account-resourceMetadata-w
}

resource "google_project_iam_member" "cluster_service_account-gcr" {
count = var.create_service_account && var.grant_registry_access ? 1 : 0
project = var.registry_project_id == "" ? var.project_id : var.registry_project_id
role = "roles/storage.objectViewer"
member = "serviceAccount:${google_service_account.cluster_service_account[0].email}"
for_each = var.create_service_account && var.grant_registry_access ? toset(local.registry_projects_list) : []
project = each.key
role = "roles/storage.objectViewer"
member = "serviceAccount:${google_service_account.cluster_service_account[0].email}"
}

resource "google_project_iam_member" "cluster_service_account-artifact-registry" {
count = var.create_service_account && var.grant_registry_access ? 1 : 0
project = var.registry_project_id == "" ? var.project_id : var.registry_project_id
role = "roles/artifactregistry.reader"
member = "serviceAccount:${google_service_account.cluster_service_account[0].email}"
for_each = var.create_service_account && var.grant_registry_access ? toset(local.registry_projects_list) : []
project = each.key
role = "roles/artifactregistry.reader"
member = "serviceAccount:${google_service_account.cluster_service_account[0].email}"
}
8 changes: 4 additions & 4 deletions autogen/main/variables.tf.tmpl
Original file line number Diff line number Diff line change
Expand Up @@ -358,10 +358,10 @@ variable "grant_registry_access" {
default = false
}

variable "registry_project_id" {
type = string
description = "Project holding the Google Container Registry. If empty, we use the cluster project. If grant_registry_access is true, storage.objectViewer role is assigned on this project."
default = ""
variable "registry_project_ids" {
type = list(string)
description = "Projects holding Google Container Registries. If empty, we use the cluster project. If a service account is created and the `grant_registry_access` variable is set to `true`, the `storage.objectViewer` role is assigned on these projects."
default = []
}

variable "service_account" {
Expand Down
4 changes: 2 additions & 2 deletions autogen/safer-cluster/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ developers, which mostly just want to deploy and debug applications.
own projects, so that they can be administered independently (e.g., dev cluster;
production clusters; staging clusters should go in different projects.)

- *A shared GCR project (`registry_project_id`):* all clusters can share the same GCR project.
- *A shared GCR project (`registry_project_ids`):* all clusters can share the same GCR project.

- Easier to share images between environments. The same image could be
progressively rolled-out in dev, staging, and then production.
Expand Down Expand Up @@ -93,7 +93,7 @@ The Safer Cluster setup relies on several service accounts:

```
create_service_account = true
registry_project_id = <the project id for your GCR project>
registry_project_ids = [<the project id for your GCR project>]
grant_registry_access = true
```

Expand Down
2 changes: 1 addition & 1 deletion autogen/safer-cluster/main.tf.tmpl
Original file line number Diff line number Diff line change
Expand Up @@ -100,7 +100,7 @@ module "gke" {
// wants to maintain control of their service accounts.
create_service_account = var.compute_engine_service_account == "" ? true : false
service_account = var.compute_engine_service_account
registry_project_id = var.registry_project_id
registry_project_ids = var.registry_project_ids
grant_registry_access = var.grant_registry_access

// Basic Auth disabled
Expand Down
8 changes: 4 additions & 4 deletions autogen/safer-cluster/variables.tf.tmpl
Original file line number Diff line number Diff line change
Expand Up @@ -208,10 +208,10 @@ variable "grant_registry_access" {
default = true
}

variable "registry_project_id" {
type = string
description = "Project holding the Google Container Registry. If empty, we use the cluster project. If grant_registry_access is true, storage.objectViewer role is assigned on this project."
default = ""
variable "registry_project_ids" {
type = list(string)
description = "Projects holding Google Container Registries. If empty, we use the cluster project. If a service account is created and the `grant_registry_access` variable is set to `true`, the `storage.objectViewer` role is assigned on these projects."
default = []
}

variable "cluster_resource_labels" {
Expand Down
2 changes: 1 addition & 1 deletion examples/workload_metadata_config/main.tf
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ module "gke" {
ip_range_services = var.ip_range_services
create_service_account = true
grant_registry_access = true
registry_project_id = var.registry_project_id
registry_project_ids = var.registry_project_ids
enable_private_endpoint = true
enable_private_nodes = true
master_ipv4_cidr_block = "172.16.0.0/28"
Expand Down
5 changes: 3 additions & 2 deletions examples/workload_metadata_config/variables.tf
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,7 @@ variable "ip_range_services" {
description = "The secondary ip range to use for services"
}

variable "registry_project_id" {
description = "Project name for the GCR registry"
variable "registry_project_ids" {
description = "Project names for GCR registries"
type = list(string)
}
4 changes: 2 additions & 2 deletions modules/beta-private-cluster-update-variant/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -231,7 +231,7 @@ Then perform the following commands on the root folder:
| project\_id | The project ID to host the cluster in (required) | `string` | n/a | yes |
| region | The region to host the cluster in (optional if zonal cluster / required if regional) | `string` | `null` | no |
| regional | Whether is a regional cluster (zonal cluster if set false. WARNING: changing this after cluster creation is destructive!) | `bool` | `true` | no |
| registry\_project\_id | Project holding the Google Container Registry. If empty, we use the cluster project. If grant\_registry\_access is true, storage.objectViewer role is assigned on this project. | `string` | `""` | no |
| registry\_project\_ids | Projects holding Google Container Registries. If empty, we use the cluster project. If a service account is created and the `grant_registry_access` variable is set to `true`, the `storage.objectViewer` role is assigned on these projects. | `list(string)` | `[]` | no |
| release\_channel | The release channel of this cluster. Accepted values are `UNSPECIFIED`, `RAPID`, `REGULAR` and `STABLE`. Defaults to `UNSPECIFIED`. | `string` | `null` | no |
| remove\_default\_node\_pool | Remove default node pool while setting up the cluster | `bool` | `false` | no |
| resource\_usage\_export\_dataset\_id | The ID of a BigQuery Dataset for using BigQuery as the destination of resource usage export. | `string` | `""` | no |
Expand Down Expand Up @@ -350,7 +350,7 @@ following project roles:
- roles/iam.serviceAccountUser
- roles/resourcemanager.projectIamAdmin (only required if `service_account` is set to `create`)

Additionally, if `service_account` is set to `create` and `grant_registry_access` is requested, the service account requires the following role on the `registry_project_id` project:
Additionally, if `service_account` is set to `create` and `grant_registry_access` is requested, the service account requires the following role on the `registry_project_ids` projects:
- roles/resourcemanager.projectIamAdmin

### Enable APIs
Expand Down
18 changes: 10 additions & 8 deletions modules/beta-private-cluster-update-variant/sa.tf
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,8 @@ locals {
)
// if user set var.service_account it will be used even if var.create_service_account==true, so service account will be created but not used
service_account = (var.service_account == "" || var.service_account == "create") && var.create_service_account ? local.service_account_list[0] : var.service_account

registry_projects_list = length(var.registry_project_ids) == 0 ? [var.project_id] : var.registry_project_ids
}

resource "random_string" "cluster_service_account_suffix" {
Expand Down Expand Up @@ -70,15 +72,15 @@ resource "google_project_iam_member" "cluster_service_account-resourceMetadata-w
}

resource "google_project_iam_member" "cluster_service_account-gcr" {
count = var.create_service_account && var.grant_registry_access ? 1 : 0
project = var.registry_project_id == "" ? var.project_id : var.registry_project_id
role = "roles/storage.objectViewer"
member = "serviceAccount:${google_service_account.cluster_service_account[0].email}"
for_each = var.create_service_account && var.grant_registry_access ? toset(local.registry_projects_list) : []
project = each.key
role = "roles/storage.objectViewer"
member = "serviceAccount:${google_service_account.cluster_service_account[0].email}"
}

resource "google_project_iam_member" "cluster_service_account-artifact-registry" {
count = var.create_service_account && var.grant_registry_access ? 1 : 0
project = var.registry_project_id == "" ? var.project_id : var.registry_project_id
role = "roles/artifactregistry.reader"
member = "serviceAccount:${google_service_account.cluster_service_account[0].email}"
for_each = var.create_service_account && var.grant_registry_access ? toset(local.registry_projects_list) : []
project = each.key
role = "roles/artifactregistry.reader"
member = "serviceAccount:${google_service_account.cluster_service_account[0].email}"
}
8 changes: 4 additions & 4 deletions modules/beta-private-cluster-update-variant/variables.tf
Original file line number Diff line number Diff line change
Expand Up @@ -346,10 +346,10 @@ variable "grant_registry_access" {
default = false
}

variable "registry_project_id" {
type = string
description = "Project holding the Google Container Registry. If empty, we use the cluster project. If grant_registry_access is true, storage.objectViewer role is assigned on this project."
default = ""
variable "registry_project_ids" {
type = list(string)
description = "Projects holding Google Container Registries. If empty, we use the cluster project. If a service account is created and the `grant_registry_access` variable is set to `true`, the `storage.objectViewer` role is assigned on these projects."
default = []
}

variable "service_account" {
Expand Down
4 changes: 2 additions & 2 deletions modules/beta-private-cluster/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -209,7 +209,7 @@ Then perform the following commands on the root folder:
| project\_id | The project ID to host the cluster in (required) | `string` | n/a | yes |
| region | The region to host the cluster in (optional if zonal cluster / required if regional) | `string` | `null` | no |
| regional | Whether is a regional cluster (zonal cluster if set false. WARNING: changing this after cluster creation is destructive!) | `bool` | `true` | no |
| registry\_project\_id | Project holding the Google Container Registry. If empty, we use the cluster project. If grant\_registry\_access is true, storage.objectViewer role is assigned on this project. | `string` | `""` | no |
| registry\_project\_ids | Projects holding Google Container Registries. If empty, we use the cluster project. If a service account is created and the `grant_registry_access` variable is set to `true`, the `storage.objectViewer` role is assigned on these projects. | `list(string)` | `[]` | no |
| release\_channel | The release channel of this cluster. Accepted values are `UNSPECIFIED`, `RAPID`, `REGULAR` and `STABLE`. Defaults to `UNSPECIFIED`. | `string` | `null` | no |
| remove\_default\_node\_pool | Remove default node pool while setting up the cluster | `bool` | `false` | no |
| resource\_usage\_export\_dataset\_id | The ID of a BigQuery Dataset for using BigQuery as the destination of resource usage export. | `string` | `""` | no |
Expand Down Expand Up @@ -328,7 +328,7 @@ following project roles:
- roles/iam.serviceAccountUser
- roles/resourcemanager.projectIamAdmin (only required if `service_account` is set to `create`)

Additionally, if `service_account` is set to `create` and `grant_registry_access` is requested, the service account requires the following role on the `registry_project_id` project:
Additionally, if `service_account` is set to `create` and `grant_registry_access` is requested, the service account requires the following role on the `registry_project_ids` projects:
- roles/resourcemanager.projectIamAdmin

### Enable APIs
Expand Down
18 changes: 10 additions & 8 deletions modules/beta-private-cluster/sa.tf
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,8 @@ locals {
)
// if user set var.service_account it will be used even if var.create_service_account==true, so service account will be created but not used
service_account = (var.service_account == "" || var.service_account == "create") && var.create_service_account ? local.service_account_list[0] : var.service_account

registry_projects_list = length(var.registry_project_ids) == 0 ? [var.project_id] : var.registry_project_ids
}

resource "random_string" "cluster_service_account_suffix" {
Expand Down Expand Up @@ -70,15 +72,15 @@ resource "google_project_iam_member" "cluster_service_account-resourceMetadata-w
}

resource "google_project_iam_member" "cluster_service_account-gcr" {
count = var.create_service_account && var.grant_registry_access ? 1 : 0
project = var.registry_project_id == "" ? var.project_id : var.registry_project_id
role = "roles/storage.objectViewer"
member = "serviceAccount:${google_service_account.cluster_service_account[0].email}"
for_each = var.create_service_account && var.grant_registry_access ? toset(local.registry_projects_list) : []
project = each.key
role = "roles/storage.objectViewer"
member = "serviceAccount:${google_service_account.cluster_service_account[0].email}"
}

resource "google_project_iam_member" "cluster_service_account-artifact-registry" {
count = var.create_service_account && var.grant_registry_access ? 1 : 0
project = var.registry_project_id == "" ? var.project_id : var.registry_project_id
role = "roles/artifactregistry.reader"
member = "serviceAccount:${google_service_account.cluster_service_account[0].email}"
for_each = var.create_service_account && var.grant_registry_access ? toset(local.registry_projects_list) : []
project = each.key
role = "roles/artifactregistry.reader"
member = "serviceAccount:${google_service_account.cluster_service_account[0].email}"
}
8 changes: 4 additions & 4 deletions modules/beta-private-cluster/variables.tf
Original file line number Diff line number Diff line change
Expand Up @@ -346,10 +346,10 @@ variable "grant_registry_access" {
default = false
}

variable "registry_project_id" {
type = string
description = "Project holding the Google Container Registry. If empty, we use the cluster project. If grant_registry_access is true, storage.objectViewer role is assigned on this project."
default = ""
variable "registry_project_ids" {
type = list(string)
description = "Projects holding Google Container Registries. If empty, we use the cluster project. If a service account is created and the `grant_registry_access` variable is set to `true`, the `storage.objectViewer` role is assigned on these projects."
default = []
}

variable "service_account" {
Expand Down
4 changes: 2 additions & 2 deletions modules/beta-public-cluster-update-variant/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -220,7 +220,7 @@ Then perform the following commands on the root folder:
| project\_id | The project ID to host the cluster in (required) | `string` | n/a | yes |
| region | The region to host the cluster in (optional if zonal cluster / required if regional) | `string` | `null` | no |
| regional | Whether is a regional cluster (zonal cluster if set false. WARNING: changing this after cluster creation is destructive!) | `bool` | `true` | no |
| registry\_project\_id | Project holding the Google Container Registry. If empty, we use the cluster project. If grant\_registry\_access is true, storage.objectViewer role is assigned on this project. | `string` | `""` | no |
| registry\_project\_ids | Projects holding Google Container Registries. If empty, we use the cluster project. If a service account is created and the `grant_registry_access` variable is set to `true`, the `storage.objectViewer` role is assigned on these projects. | `list(string)` | `[]` | no |
| release\_channel | The release channel of this cluster. Accepted values are `UNSPECIFIED`, `RAPID`, `REGULAR` and `STABLE`. Defaults to `UNSPECIFIED`. | `string` | `null` | no |
| remove\_default\_node\_pool | Remove default node pool while setting up the cluster | `bool` | `false` | no |
| resource\_usage\_export\_dataset\_id | The ID of a BigQuery Dataset for using BigQuery as the destination of resource usage export. | `string` | `""` | no |
Expand Down Expand Up @@ -337,7 +337,7 @@ following project roles:
- roles/iam.serviceAccountUser
- roles/resourcemanager.projectIamAdmin (only required if `service_account` is set to `create`)

Additionally, if `service_account` is set to `create` and `grant_registry_access` is requested, the service account requires the following role on the `registry_project_id` project:
Additionally, if `service_account` is set to `create` and `grant_registry_access` is requested, the service account requires the following role on the `registry_project_ids` projects:
- roles/resourcemanager.projectIamAdmin

### Enable APIs
Expand Down
Loading