From a2534464060cdf58d1cad765ea29d66053832b9c Mon Sep 17 00:00:00 2001 From: lcaggio Date: Wed, 31 Aug 2022 11:14:18 +0200 Subject: [PATCH] First commit --- modules/cloud-identity-group/README.md | 30 +++++++++++++++---- modules/cloud-identity-group/main.tf | 15 +++++----- modules/cloud-identity-group/variables.tf | 12 ++++---- .../cloud_identity_group/fixture/main.tf | 1 + .../cloud_identity_group/fixture/variables.tf | 5 ++++ 5 files changed, 45 insertions(+), 18 deletions(-) diff --git a/modules/cloud-identity-group/README.md b/modules/cloud-identity-group/README.md index 01c1289d..03c05407 100644 --- a/modules/cloud-identity-group/README.md +++ b/modules/cloud-identity-group/README.md @@ -7,11 +7,10 @@ To use this module you must either run terraform as a user that has the Groups A Please note that the underlying terraform resources only allow the creation of groups with members that are part of the organization. If you want to create memberships for identities outside your own organization, you have to manually allow members outside your organization in the Cloud Identity admin console. -As of version 3.50 of the GCP Terraform provider two operations are not working: +As of version 4.34 of the GCP Terraform provider one operation is not working: - removing a group that has at least one OWNER managed by terraform ([bug](https://github.com/hashicorp/terraform-provider-google/issues/7617)) -- removing a role from an existing membership ([bug](https://github.com/hashicorp/terraform-provider-google/issues/7616)) -Until those two bugs are fixed, this module will only support the creation of MEMBER memberships. +Until that bug is fixed, this module will only support the creation of MEMBER and MANAGER memberships. ## Examples @@ -31,6 +30,26 @@ module "group" { } # tftest modules=1 resources=4 ``` + +### Group with managers +```hcl +module "group" { + source = "./modules/cloud-identity-group" + customer_id = "customers/C01234567" + name = "mygroup2@example.com" + display_name = "My group name 2" + description = "My group 2 Description" + members = [ + "user1@example.com", + "user2@example.com", + "service-account@my-gcp-project.iam.gserviceaccount.com" + ] + managers = [ + "user3@example.com" + ] +} +# tftest modules=1 resources=5 +``` ## Variables @@ -39,9 +58,10 @@ module "group" { |---|---|:---:|:---:|:---:| | [customer_id](variables.tf#L17) | Directory customer ID in the form customers/C0xxxxxxx. | string | ✓ | | | [display_name](variables.tf#L32) | Group display name. | string | ✓ | | -| [name](variables.tf#L43) | Group ID (usually an email). | string | ✓ | | +| [name](variables.tf#L49) | Group ID (usually an email). | string | ✓ | | | [description](variables.tf#L26) | Group description. | string | | null | -| [members](variables.tf#L37) | List of group members. | list(string) | | [] | +| [managers](variables.tf#L37) | List of group managers. | list(string) | | [] | +| [members](variables.tf#L43) | List of group members. | list(string) | | [] | ## Outputs diff --git a/modules/cloud-identity-group/main.tf b/modules/cloud-identity-group/main.tf index 2bed4435..b71be55f 100644 --- a/modules/cloud-identity-group/main.tf +++ b/modules/cloud-identity-group/main.tf @@ -36,17 +36,18 @@ resource "google_cloud_identity_group" "group" { # roles { name = "MANAGER" } # } -# resource "google_cloud_identity_group_membership" "managers" { -# group = google_cloud_identity_group.group.id -# for_each = toset(var.managers) -# preferred_member_key { id = each.key } -# roles { name = "MEMBER" } -# roles { name = "MANAGER" } -# } +resource "google_cloud_identity_group_membership" "managers" { + group = google_cloud_identity_group.group.id + for_each = toset(var.managers) + preferred_member_key { id = each.key } + roles { name = "MEMBER" } + roles { name = "MANAGER" } +} resource "google_cloud_identity_group_membership" "members" { group = google_cloud_identity_group.group.id for_each = toset(var.members) preferred_member_key { id = each.key } roles { name = "MEMBER" } + depends_on = [google_cloud_identity_group_membership.managers] } diff --git a/modules/cloud-identity-group/variables.tf b/modules/cloud-identity-group/variables.tf index b9590537..221bcb84 100644 --- a/modules/cloud-identity-group/variables.tf +++ b/modules/cloud-identity-group/variables.tf @@ -34,6 +34,12 @@ variable "display_name" { type = string } +variable "managers" { + description = "List of group managers." + type = list(string) + default = [] +} + variable "members" { description = "List of group members." type = list(string) @@ -50,9 +56,3 @@ variable "name" { # type = list(string) # default = [] # } - -# variable "managers" { -# description = "List of group managers." -# type = list(string) -# default = [] -# } diff --git a/tests/modules/cloud_identity_group/fixture/main.tf b/tests/modules/cloud_identity_group/fixture/main.tf index a4058573..98a2a747 100644 --- a/tests/modules/cloud_identity_group/fixture/main.tf +++ b/tests/modules/cloud_identity_group/fixture/main.tf @@ -20,5 +20,6 @@ module "test" { display_name = var.display_name description = var.description customer_id = var.customer_id + managers = var.managers members = var.members } diff --git a/tests/modules/cloud_identity_group/fixture/variables.tf b/tests/modules/cloud_identity_group/fixture/variables.tf index 936282d8..c18b2497 100644 --- a/tests/modules/cloud_identity_group/fixture/variables.tf +++ b/tests/modules/cloud_identity_group/fixture/variables.tf @@ -34,6 +34,11 @@ variable "customer_id" { default = "customers/C01234567" } +variable "managers" { + type = list(string) + default = [] +} + variable "members" { type = list(string) default = []