-
Notifications
You must be signed in to change notification settings - Fork 545
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix: Fix regression in shared VPC service account submodule (#438)
- Loading branch information
1 parent
9eb64e2
commit dd2dd99
Showing
9 changed files
with
93 additions
and
51 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -19,40 +19,48 @@ data "google_project" "service_project" { | |
} | ||
|
||
locals { | ||
apis = { | ||
"container.googleapis.com" : format("service-%[email protected]", data.google_project.service_project.number), | ||
"dataproc.googleapis.com" : format("service-%[email protected]", data.google_project.service_project.number), | ||
} | ||
gke_shared_vpc_enabled = contains(var.active_apis, "container.googleapis.com") | ||
gke_s_account = local.gke_shared_vpc_enabled ? format( | ||
"service-%[email protected]", | ||
data.google_project.service_project.number, | ||
) : "" | ||
dataproc_shared_vpc_enabled = contains(var.active_apis, "dataproc.googleapis.com") | ||
dataproc_s_account = local.dataproc_shared_vpc_enabled ? format( | ||
"service-%[email protected]", | ||
data.google_project.service_project.number | ||
) : "" | ||
active_api_s_accounts = compact([local.gke_s_account, local.dataproc_s_account]) | ||
active_apis = setintersection(keys(local.apis), var.active_apis) | ||
subnetwork_api = length(var.shared_vpc_subnets) != 0 ? tolist(setproduct(local.active_apis, var.shared_vpc_subnets)) : [] | ||
} | ||
|
||
/****************************************** | ||
compute.networkUser role granted to GKE service account for GKE on shared VPC subnets | ||
if "container.googleapis.com" compute.networkUser role granted to GKE service account for GKE on shared VPC subnets | ||
if "dataproc.googleapis.com" compute.networkUser role granted to dataproc service account for dataproc on shared VPC subnets | ||
See: https://cloud.google.com/kubernetes-engine/docs/how-to/cluster-shared-vpc | ||
*****************************************/ | ||
resource "google_compute_subnetwork_iam_member" "gke_shared_vpc_subnets" { | ||
resource "google_compute_subnetwork_iam_member" "service_shared_vpc_subnet_users" { | ||
provider = google-beta | ||
count = local.gke_shared_vpc_enabled && length(var.shared_vpc_subnets) != 0 ? length(var.shared_vpc_subnets) : 0 | ||
count = length(local.subnetwork_api) | ||
subnetwork = element( | ||
split("/", var.shared_vpc_subnets[count.index]), | ||
split("/", local.subnetwork_api[count.index][1]), | ||
index( | ||
split("/", var.shared_vpc_subnets[count.index]), | ||
split("/", local.subnetwork_api[count.index][1]), | ||
"subnetworks", | ||
) + 1, | ||
) | ||
role = "roles/compute.networkUser" | ||
region = element( | ||
split("/", var.shared_vpc_subnets[count.index]), | ||
index(split("/", var.shared_vpc_subnets[count.index]), "regions") + 1, | ||
split("/", local.subnetwork_api[count.index][1]), | ||
index(split("/", local.subnetwork_api[count.index][1]), "regions") + 1, | ||
) | ||
project = var.host_project_id | ||
member = format("serviceAccount:%s", local.gke_s_account) | ||
member = format("serviceAccount:%s", local.apis[local.subnetwork_api[count.index][0]]) | ||
} | ||
|
||
/****************************************** | ||
if "container.googleapis.com" compute.networkUser role granted to GKE service account for GKE on shared VPC Project if no subnets defined | ||
if "dataproc.googleapis.com" compute.networkUser role granted to dataproc service account for dataproc on shared VPC Project if no subnets defined | ||
*****************************************/ | ||
resource "google_project_iam_member" "service_shared_vpc_user" { | ||
for_each = length(var.shared_vpc_subnets) == 0 ? local.active_apis : [] | ||
project = var.host_project_id | ||
role = "roles/compute.networkUser" | ||
member = format("serviceAccount:%s", local.apis[each.value]) | ||
} | ||
|
||
/****************************************** | ||
|
@@ -63,16 +71,5 @@ resource "google_project_iam_member" "gke_host_agent" { | |
count = local.gke_shared_vpc_enabled ? 1 : 0 | ||
project = var.host_project_id | ||
role = "roles/container.hostServiceAgentUser" | ||
member = format("serviceAccount:%s", local.gke_s_account) | ||
} | ||
|
||
/****************************************** | ||
compute.networkUser role granted to dataproc service account for dataproc on shared VPC subnets | ||
See: https://cloud.google.com/dataproc/docs/concepts/configuring-clusters/network#creating_a_cluster_that_uses_a_vpc_network_in_another_project | ||
*****************************************/ | ||
resource "google_project_iam_member" "dataproc_shared_vpc_network_user" { | ||
count = local.dataproc_shared_vpc_enabled ? 1 : 0 | ||
project = var.host_project_id | ||
role = "roles/compute.networkUser" | ||
member = format("serviceAccount:%s", local.dataproc_s_account) | ||
member = format("serviceAccount:%s", local.apis["container.googleapis.com"]) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters