Skip to content

Commit

Permalink
Merge pull request #31 from getindata/feature/groups-users_additional…
Browse files Browse the repository at this point in the history
…_output

feat: Add additional output for groups-users submodule
  • Loading branch information
dgniewek authored Jan 18, 2024
2 parents 2de8e4d + 452b3d5 commit 62d8e4e
Show file tree
Hide file tree
Showing 13 changed files with 77 additions and 8 deletions.
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -87,7 +87,7 @@ Apache 2 Licensed. See [LICENSE](LICENSE) for full details.
## AUTHORS

<!--- Replace repository name -->
<a href="https://github.com/getindata/REPO_NAME/graphs/contributors">
<a href="https://github.com/getindata/terraform-google-group-users-data-source/graphs/contributors">
<img src="https://contrib.rocks/image?repo=getindata/terraform-module-template" />
</a>

Expand Down
Empty file added examples/groups-users/.env.dist
Empty file.
2 changes: 2 additions & 0 deletions examples/groups-users/.envrc
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
#Override defaults
command -v dotenv && test -f .env && dotenv
11 changes: 11 additions & 0 deletions examples/groups-users/Makefile
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
init:
terraform init

plan:
terraform plan -out tfplan

apply:
terraform apply tfplan

destroy:
terraform destroy
19 changes: 19 additions & 0 deletions examples/groups-users/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
# Groups-Users submodule Example

```terraform
module "terraform_google_group_users_data_source" {
source = "../../modules/groups-users"
group_emails = [
"[email protected]",
"[email protected]",
]
}
```

## Usage

```shell
terraform init
terraform plan -out tfplan
terraform apply tfplan
```
7 changes: 7 additions & 0 deletions examples/groups-users/main.tf
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
module "terraform_google_group_users_data_source" {
source = "../../modules/groups-users"
group_emails = [
"[email protected]",
"[email protected]",
]
}
4 changes: 4 additions & 0 deletions examples/groups-users/outputs.tf
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
output "example_output" {
description = "Example output of the module"
value = module.terraform_google_group_users_data_source
}
2 changes: 2 additions & 0 deletions examples/groups-users/providers.tf
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
provider "google" {
}
12 changes: 12 additions & 0 deletions examples/groups-users/versions.tf
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
# Example configuration of terraform providers

terraform {
required_version = ">= 1.3.0"

required_providers {
google = {
source = "hashicorp/google"
version = "~> 5.4"
}
}
}
7 changes: 3 additions & 4 deletions examples/simple/README.md
Original file line number Diff line number Diff line change
@@ -1,10 +1,9 @@
# Simple Example

```terraform
module "terraform_module_template" {
source = "../../"
example_var = "This is a example value."
module "terraform_google_group_users_data_source" {
source = "../../"
group_email = "[email protected]"
}
```

Expand Down
1 change: 1 addition & 0 deletions modules/groups-users/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@ module "groups_users" {
|------|-------------|
| <a name="output_group_members"></a> [group\_members](#output\_group\_members) | Map of google group details and its members |
| <a name="output_users"></a> [users](#output\_users) | Deduplicated map of google group members (users) in format { email => username } |
| <a name="output_users_groups"></a> [users\_groups](#output\_users\_groups) | Deduplicated map of google group members (users) in format { email => {user\_name = username, groups = list(groups)}} |

## Providers

Expand Down
13 changes: 10 additions & 3 deletions modules/groups-users/locals.tf
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,17 @@ locals {
# Create map of group names without domain
groups = { for group in var.group_emails : split("@", group)[0] => group }

# Deduplicated user list
users_list = distinct(flatten([for group in module.google_group_members : group.users]))
# Create a map of users with groups assigned to them
users_groups = transpose({ for group, details in module.google_group_members : group => details.users })

# Create a map of users from deduplicated user list to avoid broadcasting of
# fake changes due to changes in list ordering
users_map = { for user in local.users_list : user => split("@", user)[0] }
users_map = { for user_email, groups in local.users_groups : user_email => split("@", user_email)[0] }

# Create a map of user emails, groups and user names assigned to them
users_groups_map = { for user_email, groups in local.users_groups : user_email => {
user_name = split("@", user_email)[0]
groups = groups
}
}
}
5 changes: 5 additions & 0 deletions modules/groups-users/outputs.tf
Original file line number Diff line number Diff line change
Expand Up @@ -7,3 +7,8 @@ output "users" {
value = local.users_map
description = "Deduplicated map of google group members (users) in format { email => username }"
}

output "users_groups" {
value = local.users_groups_map
description = "Deduplicated map of google group members (users) in format { email => {user_name = username, groups = list(groups)}}"
}

0 comments on commit 62d8e4e

Please sign in to comment.