diff --git a/README.md b/README.md index 6425a06..71af479 100644 --- a/README.md +++ b/README.md @@ -56,6 +56,18 @@ role: name: 'Example Role' ``` +##### Groups in Group example structure +Group member have to be defined within the group definition. +```yaml +role: + email: 'role@example.io' + name: 'Example Role' + groups: + - alt_role +``` +In this example the group 'alt_role' will be a member of the group 'role'. + + #### **Users example structure** ```yaml jane: diff --git a/groups_in_group/groups_in_group.tf b/groups_in_group/groups_in_group.tf new file mode 100644 index 0000000..2250e0f --- /dev/null +++ b/groups_in_group/groups_in_group.tf @@ -0,0 +1,28 @@ +terraform { + required_providers { + gsuite = { + source = "DeviaVir/gsuite" + version = "0.1.58" + } + } +} + +variable "groups" { + type = map(any) + description = "contains objects representing all defined Google Groups" +} + +variable "group" { + type = any + description = "contains an object representing a Google Group" +} + +/** + * Ressource documentation: https://registry.terraform.io/providers/DeviaVir/gsuite/latest/docs/resources/group + */ + +resource "gsuite_group_member" "member" { + for_each = toset(var.group.groups) + group = var.group.email + email = var.groups[each.value].email +} \ No newline at end of file diff --git a/main.tf b/main.tf index a1754c6..d464596 100644 --- a/main.tf +++ b/main.tf @@ -25,6 +25,17 @@ module "groups" { group = each.value } +module "groups_in_group" { + for_each = var.groups + depends_on = [module.groups] + source = "./groups_in_group" + providers = { + gsuite = gsuite + } + groups = var.groups + group = each.value +} + module "users" { for_each = var.users depends_on = [module.groups]