Skip to content

Commit

Permalink
fix: terraform-google-modules#362 allow users to supply dynamically g…
Browse files Browse the repository at this point in the history
…enerated list of subnets
  • Loading branch information
rjerrems committed Jan 30, 2020
1 parent 9e4b202 commit f068bd2
Showing 1 changed file with 5 additions and 32 deletions.
37 changes: 5 additions & 32 deletions modules/core_project_factory/main.tf
Original file line number Diff line number Diff line change
Expand Up @@ -90,33 +90,6 @@ resource "null_resource" "preconditions" {
}
}

/*******************************************
Shared VPC Subnets names validation
*******************************************/

resource "null_resource" "shared_vpc_subnet_invalid_name" {
count = length(var.shared_vpc_subnets)

triggers = {
name = replace(
var.shared_vpc_subnets[count.index],
"/(https://www.googleapis.com/compute/v1/)?projects/[a-z0-9-]+/regions/[a-z0-9-]+/subnetworks/[a-z0-9-]+/",
"",
)
}
}

resource "null_resource" "check_if_shared_vpc_subnets_contains_items_with_invalid_name" {
count = length(
compact(null_resource.shared_vpc_subnet_invalid_name.*.triggers.name),
) == 0 ? 0 : 1

provisioner "local-exec" {
command = "false"
interpreter = ["bash", "-c"]
}
}

/*******************************************
Project creation
*******************************************/
Expand Down Expand Up @@ -304,7 +277,7 @@ resource "google_service_account_iam_member" "service_account_grant_to_group" {
Account on shared VPC
*****************************************************************************************************************/
resource "google_project_iam_member" "controlling_group_vpc_membership" {
count = var.shared_vpc_enabled && length(compact(var.shared_vpc_subnets)) == 0 ? local.shared_vpc_users_length : 0
count = var.shared_vpc_enabled && length(var.shared_vpc_subnets) == 0 ? local.shared_vpc_users_length : 0

project = var.shared_vpc
role = "roles/compute.networkUser"
Expand All @@ -320,7 +293,7 @@ resource "google_project_iam_member" "controlling_group_vpc_membership" {
*************************************************************************************/
resource "google_compute_subnetwork_iam_member" "service_account_role_to_vpc_subnets" {
provider = google-beta
count = var.shared_vpc_enabled && length(compact(var.shared_vpc_subnets)) > 0 ? length(var.shared_vpc_subnets) : 0
count = var.shared_vpc_enabled && length(var.shared_vpc_subnets) > 0 ? length(var.shared_vpc_subnets) : 0

subnetwork = element(
split("/", var.shared_vpc_subnets[count.index]),
Expand All @@ -344,7 +317,7 @@ resource "google_compute_subnetwork_iam_member" "service_account_role_to_vpc_sub
resource "google_compute_subnetwork_iam_member" "group_role_to_vpc_subnets" {
provider = google-beta

count = var.shared_vpc_enabled && length(compact(var.shared_vpc_subnets)) > 0 && var.manage_group ? length(var.shared_vpc_subnets) : 0
count = var.shared_vpc_enabled && length(var.shared_vpc_subnets) > 0 && var.manage_group ? length(var.shared_vpc_subnets) : 0
subnetwork = element(
split("/", var.shared_vpc_subnets[count.index]),
index(
Expand All @@ -367,7 +340,7 @@ resource "google_compute_subnetwork_iam_member" "group_role_to_vpc_subnets" {
resource "google_compute_subnetwork_iam_member" "apis_service_account_role_to_vpc_subnets" {
provider = google-beta

count = var.shared_vpc_enabled && length(compact(var.shared_vpc_subnets)) > 0 ? length(var.shared_vpc_subnets) : 0
count = var.shared_vpc_enabled && length(var.shared_vpc_subnets) > 0 ? length(var.shared_vpc_subnets) : 0
subnetwork = element(
split("/", var.shared_vpc_subnets[count.index]),
index(
Expand Down Expand Up @@ -456,7 +429,7 @@ resource "google_storage_bucket_iam_member" "api_s_account_storage_admin_on_proj
*****************************************/
resource "google_compute_subnetwork_iam_member" "gke_shared_vpc_subnets" {
provider = google-beta
count = local.gke_shared_vpc_enabled && length(compact(var.shared_vpc_subnets)) != 0 ? length(var.shared_vpc_subnets) : 0
count = local.gke_shared_vpc_enabled && length(var.shared_vpc_subnets) != 0 ? length(var.shared_vpc_subnets) : 0
subnetwork = element(
split("/", var.shared_vpc_subnets[count.index]),
index(
Expand Down

0 comments on commit f068bd2

Please sign in to comment.