-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #11 from mineiros-io/waxb/update-module
feat: add support for computed members and condition
- Loading branch information
Showing
6 changed files
with
199 additions
and
17 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 |
---|---|---|
@@ -1,29 +1,47 @@ | ||
locals { | ||
iam_map = { for iam in var.iam : iam.role => iam } | ||
# filter all objects that define a single role | ||
iam_role = [for iam in var.iam : iam if can(iam.role)] | ||
|
||
# filter all objects that define multiple roles and expand them to single roles | ||
iam_roles = flatten([for iam in var.iam : | ||
[for role in iam.roles : merge(iam, { role = role })] if can(iam.roles) | ||
]) | ||
|
||
iam = concat(local.iam_role, local.iam_roles) | ||
|
||
iam_map = { for idx, iam in local.iam : | ||
try(iam._key, "${iam.role}/${iam.condition._key}", "${iam.role}/${md5(jsonencode(iam.condition))}", iam.role) => idx | ||
} | ||
} | ||
|
||
module "iam" { | ||
source = "github.com/mineiros-io/terraform-google-subnetwork-iam.git?ref=v0.0.1" | ||
source = "github.com/mineiros-io/terraform-google-subnetwork-iam.git?ref=v0.1.0" | ||
|
||
for_each = var.policy_bindings == null ? local.iam_map : {} | ||
|
||
module_enabled = var.module_enabled | ||
module_depends_on = var.module_depends_on | ||
|
||
subnetwork = try(google_compute_subnetwork.subnetwork[0].name, null) | ||
role = each.value.role | ||
members = each.value.members | ||
authoritative = try(each.value.authoritative, true) | ||
subnetwork = try(google_compute_subnetwork.subnetwork[0].name, null) | ||
|
||
role = local.iam[each.value].role | ||
|
||
members = try(local.iam[each.value].members, []) | ||
computed_members_map = var.computed_members_map | ||
|
||
condition = try(local.iam[each.value].condition, null) | ||
authoritative = try(local.iam[each.value].authoritative, true) | ||
} | ||
|
||
module "policy_bindings" { | ||
source = "github.com/mineiros-io/terraform-google-subnetwork-iam.git?ref=v0.0.1" | ||
source = "github.com/mineiros-io/terraform-google-subnetwork-iam.git?ref=v0.1.0" | ||
|
||
count = var.policy_bindings != null ? 1 : 0 | ||
|
||
module_enabled = var.module_enabled | ||
module_depends_on = var.module_depends_on | ||
|
||
subnetwork = try(google_compute_subnetwork.subnetwork[0].name, null) | ||
policy_bindings = var.policy_bindings | ||
subnetwork = try(google_compute_subnetwork.subnetwork[0].name, null) | ||
policy_bindings = var.policy_bindings | ||
computed_members_map = var.computed_members_map | ||
} |
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 |
---|---|---|
@@ -1,11 +1,84 @@ | ||
module "test-sa" { | ||
source = "github.com/mineiros-io/terraform-google-service-account?ref=v0.0.12" | ||
|
||
account_id = "service-account-id-${local.random_suffix}" | ||
} | ||
|
||
module "test" { | ||
source = "../.." | ||
|
||
module_enabled = true | ||
project = local.project_id | ||
|
||
# add all required arguments | ||
network = "projects/test-project/global/networks/test-network" | ||
name = "test-subnetwork" | ||
description = "unit-complete" | ||
ip_cidr_range = "10.2.0.0/16" | ||
region = "us-central1" | ||
secondary_ip_ranges = [ | ||
{ | ||
range_name = "kubernetes-pods" | ||
ip_cidr_range = "10.10.0.0/20" | ||
} | ||
] | ||
|
||
private_ip_google_access = false | ||
|
||
# add all optional arguments that create additional resources | ||
|
||
# add most/all other optional arguments | ||
|
||
# module_tags = { | ||
# Environment = "unknown" | ||
# } | ||
|
||
log_config = { | ||
aggregation_interval = "INTERVAL_10_MIN" | ||
flow_sampling = 0.5 | ||
metadata = "CUSTOM_METADATA" | ||
metadata_fields = ["field0"] | ||
filter_expr = true | ||
} | ||
|
||
iam = [ | ||
{ | ||
role = "roles/browser" | ||
members = ["domain:example-domain"] | ||
condition = { | ||
title = "expires_after_2021_12_31" | ||
description = "Expiring at midnight of 2021-12-31" | ||
expression = "request.time < timestamp(\"2022-01-01T00:00:00Z\")" | ||
} | ||
}, | ||
{ | ||
role = "roles/viewer" | ||
members = ["domain:example-domain"] | ||
authoritative = false | ||
}, | ||
{ | ||
roles = ["roles/editor", "roles/browser"] | ||
members = ["computed:computed_sa"] | ||
} | ||
] | ||
|
||
computed_members_map = { | ||
myserviceaccount = "serviceAccount:${module.test-sa.service_account.email}" | ||
} | ||
|
||
module_depends_on = ["nothing"] | ||
} | ||
|
||
module "test2" { | ||
source = "../.." | ||
|
||
module_enabled = true | ||
project = local.project_id | ||
|
||
# add all required arguments | ||
network = "projects/test-project/global/networks/test-network" | ||
name = "test-subnetwork" | ||
description = "unit-complete" | ||
ip_cidr_range = "10.2.0.0/16" | ||
region = "us-central1" | ||
secondary_ip_ranges = [ | ||
|
@@ -15,6 +88,8 @@ module "test" { | |
} | ||
] | ||
|
||
private_ip_google_access = false | ||
|
||
# add all optional arguments that create additional resources | ||
|
||
# add most/all other optional arguments | ||
|
@@ -23,5 +98,26 @@ module "test" { | |
# Environment = "unknown" | ||
# } | ||
|
||
log_config = { | ||
aggregation_interval = "INTERVAL_10_MIN" | ||
flow_sampling = 0.5 | ||
metadata = "INCLUDE_ALL_METADATA" | ||
filter_expr = true | ||
} | ||
|
||
policy_bindings = [{ | ||
role = "roles/storage.admin" | ||
members = ["user:[email protected]"] | ||
condition = { | ||
title = "expires_after_2021_12_31" | ||
description = "Expiring at midnight of 2021-12-31" | ||
expression = "request.time < timestamp(\"2022-01-01T00:00:00Z\")" | ||
} | ||
}] | ||
|
||
computed_members_map = { | ||
myserviceaccount = "serviceAccount:${module.test-sa.service_account.email}" | ||
} | ||
|
||
module_depends_on = ["nothing"] | ||
} |
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