Skip to content

Commit ff80ced

Browse files
feat: copy over code from old mp module (#1)
## what - Copy over changes from poorly named MP repo - https://github.com/masterpointio/terraform-users-groups-automation-googleworkspace - Copy over doc changes from [a PR](masterpointio/terraform-users-groups-automation-googleworkspace#3) on that repo ## references - [MP automate google setup](https://www.notion.so/masterpoint/Managing-GSuite-Users-via-IaC-1d0859758a568029b956f2ab8c9a2651) <!-- This is an auto-generated comment: release notes by coderabbit.ai --> ## Summary by CodeRabbit - **New Features** - Introduced comprehensive support for managing Google Workspace users, groups, group settings, and group memberships via Terraform. - Added detailed input variables for users and groups, including advanced validation and configuration options. - Provided extensive usage examples and sample configurations for both new and existing organizations. - **Documentation** - Rewrote and expanded the README with module-specific usage instructions, authentication guidance, and input schemas. - Updated all documentation links and badges to reflect the new module repository. - **Bug Fixes** - Improved input validation for user and group attributes, including email formats and password requirements. - **Tests** - Added tests to validate user and group input variables, including email, password, group membership, and settings. - **Chores** - Updated provider requirements to use the googleworkspace provider (version >= 0.7.0). - Removed outdated outputs and example resources related to previous random resource usage. <!-- end of auto-generated comment: release notes by coderabbit.ai -->
1 parent 06933d4 commit ff80ced

17 files changed

+1028
-97
lines changed

CHANGELOG.md

Lines changed: 0 additions & 61 deletions
Original file line numberDiff line numberDiff line change
@@ -1,64 +1,3 @@
11
# Changelog
22

3-
## [0.7.0](https://github.com/masterpointio/terraform-module-template/compare/v0.6.0...v0.7.0) (2025-05-07)
43

5-
6-
### Features
7-
8-
* GHA, trunk and renovate updates ([#34](https://github.com/masterpointio/terraform-module-template/issues/34)) ([b16fa86](https://github.com/masterpointio/terraform-module-template/commit/b16fa86ea444eb1464c443324908b284a7842861))
9-
10-
## [0.6.0](https://github.com/masterpointio/terraform-module-template/compare/v0.5.1...v0.6.0) (2025-04-30)
11-
12-
13-
### Features
14-
15-
* **gha:** oidc aws credentials if AWS provider is used ([#29](https://github.com/masterpointio/terraform-module-template/issues/29)) ([4f8f1ad](https://github.com/masterpointio/terraform-module-template/commit/4f8f1adec3274960a11ee7277296e88d662c8036))
16-
17-
## [0.5.1](https://github.com/masterpointio/terraform-module-template/compare/v0.5.0...v0.5.1) (2025-04-30)
18-
19-
20-
### Bug Fixes
21-
22-
* **renovate:** valid regex ([#30](https://github.com/masterpointio/terraform-module-template/issues/30)) ([224acea](https://github.com/masterpointio/terraform-module-template/commit/224aceac5b841ab78c22ba42b7c3d74edae90b26))
23-
24-
## [0.5.0](https://github.com/masterpointio/terraform-module-template/compare/v0.4.0...v0.5.0) (2025-04-24)
25-
26-
27-
### Features
28-
29-
* upgrade terraform docs ([#23](https://github.com/masterpointio/terraform-module-template/issues/23)) ([475707f](https://github.com/masterpointio/terraform-module-template/commit/475707f7d6eef8bde27bca632cba25a535010fdc))
30-
31-
## [0.4.0](https://github.com/masterpointio/terraform-module-template/compare/v0.3.0...v0.4.0) (2025-04-16)
32-
33-
34-
### Features
35-
36-
* setup connection to notion db ([#21](https://github.com/masterpointio/terraform-module-template/issues/21)) ([857df50](https://github.com/masterpointio/terraform-module-template/commit/857df5042fbde3d3e9ffbfc964eae9f7a7927cb0))
37-
38-
## [0.3.0](https://github.com/masterpointio/terraform-module-template/compare/v0.2.0...v0.3.0) (2025-04-10)
39-
40-
41-
### Features
42-
43-
* actualize README template ([#15](https://github.com/masterpointio/terraform-module-template/issues/15)) ([5d8de5f](https://github.com/masterpointio/terraform-module-template/commit/5d8de5fcf98b255ed65201b1ab2036ebf92ca138))
44-
* **renovate:** enables renovate terraform manager ([#18](https://github.com/masterpointio/terraform-module-template/issues/18)) ([e45f5ac](https://github.com/masterpointio/terraform-module-template/commit/e45f5acf08195f45ac9d4fe23447c600230ba4b4))
45-
46-
47-
### Bug Fixes
48-
49-
* **renovate:** schedule update ([#20](https://github.com/masterpointio/terraform-module-template/issues/20)) ([62d7e24](https://github.com/masterpointio/terraform-module-template/commit/62d7e24aa39312565c894525ef5c0ebb1053eb74))
50-
51-
## [0.2.0](https://github.com/masterpointio/terraform-module-template/compare/v0.1.1...v0.2.0) (2024-11-14)
52-
53-
54-
### Features
55-
56-
* adds GH + CRabbit configs ([d86d463](https://github.com/masterpointio/terraform-module-template/commit/d86d463385d501db5465b02de13d60c925b5815d))
57-
58-
## [0.1.1](https://github.com/masterpointio/terraform-module-template/compare/0.1.0...v0.1.1) (2024-08-15)
59-
60-
61-
### Bug Fixes
62-
63-
* remove markdown trailing whitespace ([d609646](https://github.com/masterpointio/terraform-module-template/commit/d6096463b916eb536603d4ca3b2f3315e3fec9f2))
64-
* removes redundant editorconfig settings ([bbe0050](https://github.com/masterpointio/terraform-module-template/commit/bbe0050450cece8074f3d9ff5c3bd72ff01d8a1b))

README.md

Lines changed: 80 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -1,24 +1,83 @@
11
[![Banner][banner-image]](https://masterpoint.io/)
22

3-
# terraform-module-template
3+
# terraform-googleworkspace-users-groups-automation
44

55
[![Release][release-badge]][latest-release]
66

77
💡 Learn more about Masterpoint [below](#who-we-are-𐦂𖨆𐀪𖠋).
88

99
## Purpose and Functionality
1010

11-
This repository serves as a template for creating Terraform modules, providing a standardized structure and essential files for efficient module development. It's designed to ensure consistency and our best practices across Terraform projects.
11+
Use this [child module](https://opentofu.org/docs/language/modules/#child-modules) to manage Google Workspace users, groups, and roles.
1212

13-
## Usage
14-
15-
### Prerequisites (optional)
13+
If you want to use this module with an existing Google Workspace, see the [import-existing-org](examples/import-existing-org) example, which demonstrates how to import your existing Google users and groups.
1614

17-
TODO
15+
## Usage
1816

1917
### Step-by-Step Instructions
2018

21-
TODO
19+
There are two provider authentication methods available:
20+
21+
1. Authenticate using a Google Cloud service account key file.
22+
2. Authenticate using a Google Cloud service account key file and impersonate a real user with Super Admin privileges.
23+
24+
We recommend method (2), impersonating a Super Admin, as this allows you to grant Admin privileges to users (service accounts cannot do this). To set this up, follow the [Domain-Wide Delegation authentication instructions](https://github.com/hashicorp/terraform-provider-googleworkspace/blob/main/docs/index.md#using-domain-wide-delegation).
25+
26+
Follow the provider [authentication setup instructions](https://github.com/hashicorp/terraform-provider-googleworkspace/blob/main/docs/index.md#google-workspace-provider).
27+
28+
Once you've completed the setup process, your provider block should look like this:
29+
30+
```hcl
31+
provider "googleworkspace" {
32+
# Use 'my_customer' as an alias for your account's customerId to ensure compatibility with Google's API
33+
# For example, custom schemas on the user object will fail if the customer_id is set to your actual customer_id
34+
# For more details: https://developers.google.com/workspace/admin/directory/reference/rest/v1/schemas/get
35+
customer_id = "my_customer"
36+
37+
credentials = "/path/to/credentials/my-google-project-credentials-1234567890.json"
38+
impersonated_user_email = "my_impersonated_user_email@my_domain.com"
39+
40+
oauth_scopes = [
41+
"https://www.googleapis.com/auth/admin.directory.group",
42+
"https://www.googleapis.com/auth/admin.directory.user",
43+
"https://www.googleapis.com/auth/admin.directory.userschema",
44+
"https://www.googleapis.com/auth/apps.groups.settings",
45+
"https://www.googleapis.com/auth/iam",
46+
]
47+
}
48+
```
49+
50+
## Example
51+
52+
```hcl
53+
module "googleworkspace_users_groups" {
54+
source = "git::https://github.com/masterpointio/terraform-googleworkspace-users-groups-automation.git"
55+
56+
users = {
57+
"first.last@example.com" = {
58+
primary_email = "first.last@example.com"
59+
family_name = "Last"
60+
given_name = "First"
61+
password = "example-password"
62+
groups = {
63+
"platform" = {
64+
role = "member"
65+
}
66+
}
67+
}
68+
}
69+
70+
groups = {
71+
"platform" = {
72+
name = "Platform"
73+
email = "platform@example.com"
74+
settings = {
75+
who_can_join = "ALL_IN_DOMAIN_CAN_JOIN"
76+
}
77+
}
78+
}
79+
}
80+
```
2281

2382
<!-- prettier-ignore-start -->
2483
<!-- markdownlint-disable MD013 -->
@@ -28,13 +87,13 @@ TODO
2887
| Name | Version |
2988
|------|---------|
3089
| <a name="requirement_terraform"></a> [terraform](#requirement\_terraform) | >= 1.0 |
31-
| <a name="requirement_random"></a> [random](#requirement\_random) | >= 3.0 |
90+
| <a name="requirement_googleworkspace"></a> [googleworkspace](#requirement\_googleworkspace) | >= 0.7.0 |
3291

3392
## Providers
3493

3594
| Name | Version |
3695
|------|---------|
37-
| <a name="provider_random"></a> [random](#provider\_random) | >= 3.0 |
96+
| <a name="provider_googleworkspace"></a> [googleworkspace](#provider\_googleworkspace) | >= 0.7.0 |
3897

3998
## Modules
4099

@@ -46,7 +105,10 @@ TODO
46105

47106
| Name | Type |
48107
|------|------|
49-
| [random_pet.template](https://registry.terraform.io/providers/hashicorp/random/latest/docs/resources/pet) | resource |
108+
| [googleworkspace_group.defaults](https://registry.terraform.io/providers/hashicorp/googleworkspace/latest/docs/resources/group) | resource |
109+
| [googleworkspace_group_member.user_to_groups](https://registry.terraform.io/providers/hashicorp/googleworkspace/latest/docs/resources/group_member) | resource |
110+
| [googleworkspace_group_settings.defaults](https://registry.terraform.io/providers/hashicorp/googleworkspace/latest/docs/resources/group_settings) | resource |
111+
| [googleworkspace_user.defaults](https://registry.terraform.io/providers/hashicorp/googleworkspace/latest/docs/resources/user) | resource |
50112

51113
## Inputs
52114

@@ -59,24 +121,23 @@ TODO
59121
| <a name="input_descriptor_formats"></a> [descriptor\_formats](#input\_descriptor\_formats) | Describe additional descriptors to be output in the `descriptors` output map.<br/>Map of maps. Keys are names of descriptors. Values are maps of the form<br/>`{<br/> format = string<br/> labels = list(string)<br/>}`<br/>(Type is `any` so the map values can later be enhanced to provide additional options.)<br/>`format` is a Terraform format string to be passed to the `format()` function.<br/>`labels` is a list of labels, in order, to pass to `format()` function.<br/>Label values will be normalized before being passed to `format()` so they will be<br/>identical to how they appear in `id`.<br/>Default is `{}` (`descriptors` output will be empty). | `any` | `{}` | no |
60122
| <a name="input_enabled"></a> [enabled](#input\_enabled) | Set to false to prevent the module from creating any resources | `bool` | `null` | no |
61123
| <a name="input_environment"></a> [environment](#input\_environment) | ID element. Usually used for region e.g. 'uw2', 'us-west-2', OR role 'prod', 'staging', 'dev', 'UAT' | `string` | `null` | no |
124+
| <a name="input_groups"></a> [groups](#input\_groups) | List of groups | <pre>map(object({<br/> name : string,<br/> description : optional(string),<br/> email : string,<br/> timeouts : optional(object({<br/> create : optional(string),<br/> update : optional(string),<br/> }), {<br/> create = null<br/> update = null<br/> }),<br/> # https://registry.terraform.io/providers/hashicorp/googleworkspace/latest/docs/resources/group_settings<br/> settings : optional(object({<br/> allow_external_members : optional(bool),<br/> allow_web_posting : optional(bool),<br/> archive_only : optional(bool),<br/> custom_footer_text : optional(string),<br/> custom_reply_to : optional(string),<br/> default_message_deny_notification_text : optional(string),<br/> enable_collaborative_inbox : optional(bool),<br/> include_custom_footer : optional(bool),<br/> include_in_global_address_list : optional(bool),<br/> is_archived : optional(bool),<br/> members_can_post_as_the_group : optional(bool),<br/> message_moderation_level : optional(string),<br/> primary_language : optional(string),<br/> reply_to : optional(string),<br/> send_message_deny_notification : optional(bool),<br/> spam_moderation_level : optional(string),<br/> who_can_assist_content : optional(string),<br/> who_can_contact_owner : optional(string),<br/> who_can_discover_group : optional(string),<br/> who_can_join : optional(string),<br/> who_can_leave_group : optional(string),<br/> who_can_moderate_content : optional(string),<br/> who_can_moderate_members : optional(string),<br/> who_can_post_message : optional(string),<br/> who_can_view_group : optional(string),<br/> who_can_view_membership : optional(string),<br/> }), {}),<br/> }))</pre> | `{}` | no |
62125
| <a name="input_id_length_limit"></a> [id\_length\_limit](#input\_id\_length\_limit) | Limit `id` to this many characters (minimum 6).<br/>Set to `0` for unlimited length.<br/>Set to `null` for keep the existing setting, which defaults to `0`.<br/>Does not affect `id_full`. | `number` | `null` | no |
63126
| <a name="input_label_key_case"></a> [label\_key\_case](#input\_label\_key\_case) | Controls the letter case of the `tags` keys (label names) for tags generated by this module.<br/>Does not affect keys of tags passed in via the `tags` input.<br/>Possible values: `lower`, `title`, `upper`.<br/>Default value: `title`. | `string` | `null` | no |
64127
| <a name="input_label_order"></a> [label\_order](#input\_label\_order) | The order in which the labels (ID elements) appear in the `id`.<br/>Defaults to ["namespace", "environment", "stage", "name", "attributes"].<br/>You can omit any of the 6 labels ("tenant" is the 6th), but at least one must be present. | `list(string)` | `null` | no |
65128
| <a name="input_label_value_case"></a> [label\_value\_case](#input\_label\_value\_case) | Controls the letter case of ID elements (labels) as included in `id`,<br/>set as tag values, and output by this module individually.<br/>Does not affect values of tags passed in via the `tags` input.<br/>Possible values: `lower`, `title`, `upper` and `none` (no transformation).<br/>Set this to `title` and set `delimiter` to `""` to yield Pascal Case IDs.<br/>Default value: `lower`. | `string` | `null` | no |
66129
| <a name="input_labels_as_tags"></a> [labels\_as\_tags](#input\_labels\_as\_tags) | Set of labels (ID elements) to include as tags in the `tags` output.<br/>Default is to include all labels.<br/>Tags with empty values will not be included in the `tags` output.<br/>Set to `[]` to suppress all generated tags.<br/>**Notes:**<br/> The value of the `name` tag, if included, will be the `id`, not the `name`.<br/> Unlike other `null-label` inputs, the initial setting of `labels_as_tags` cannot be<br/> changed in later chained modules. Attempts to change it will be silently ignored. | `set(string)` | <pre>[<br/> "default"<br/>]</pre> | no |
67-
| <a name="input_length"></a> [length](#input\_length) | The length of the random name | `number` | `2` | no |
68130
| <a name="input_name"></a> [name](#input\_name) | ID element. Usually the component or solution name, e.g. 'app' or 'jenkins'.<br/>This is the only ID element not also included as a `tag`.<br/>The "name" tag is set to the full `id` string. There is no tag with the value of the `name` input. | `string` | `null` | no |
69131
| <a name="input_namespace"></a> [namespace](#input\_namespace) | ID element. Usually an abbreviation of your organization name, e.g. 'eg' or 'cp', to help ensure generated IDs are globally unique | `string` | `null` | no |
70132
| <a name="input_regex_replace_chars"></a> [regex\_replace\_chars](#input\_regex\_replace\_chars) | Terraform regular expression (regex) string.<br/>Characters matching the regex will be removed from the ID elements.<br/>If not set, `"/[^a-zA-Z0-9-]/"` is used to remove all characters other than hyphens, letters and digits. | `string` | `null` | no |
71133
| <a name="input_stage"></a> [stage](#input\_stage) | ID element. Usually used to indicate role, e.g. 'prod', 'staging', 'source', 'build', 'test', 'deploy', 'release' | `string` | `null` | no |
72134
| <a name="input_tags"></a> [tags](#input\_tags) | Additional tags (e.g. `{'BusinessUnit': 'XYZ'}`).<br/>Neither the tag keys nor the tag values will be modified by this module. | `map(string)` | `{}` | no |
73135
| <a name="input_tenant"></a> [tenant](#input\_tenant) | ID element \_(Rarely used, not included by default)\_. A customer identifier, indicating who this instance of a resource is for | `string` | `null` | no |
136+
| <a name="input_users"></a> [users](#input\_users) | List of users | <pre>map(object({<br/> # addresses<br/> aliases : optional(list(string), []),<br/> archived : optional(bool, false),<br/> change_password_at_next_login : optional(bool),<br/> # custom_schemas<br/> # emails<br/> # external_ids<br/> family_name : string,<br/> given_name : string,<br/> groups : optional(map(object({<br/> role : optional(string, "MEMBER"),<br/> delivery_settings : optional(string, "ALL_MAIL"),<br/> type : optional(string, "USER"),<br/> })), {}),<br/> # ims<br/> include_in_global_address_list : optional(bool),<br/> ip_allowlist : optional(bool),<br/> is_admin : optional(bool),<br/> # keywords<br/> # languages<br/> # locations<br/> org_unit_path : optional(string),<br/> # organizations<br/> # phones<br/> # posix_accounts<br/> primary_email : string,<br/> recovery_email : optional(string),<br/> recovery_phone : optional(string),<br/> # relations<br/> # ssh_public_keys<br/> suspended : optional(bool),<br/> # timeouts<br/> # websites<br/><br/> # User attributes with unique constraints<br/><br/> # password and hash_function<br/> # If a hashFunction is specified, the password must be a valid hash key.<br/> # If it's not specified, the password should be in clear text and between<br/> # 8–100 ASCII characters.<br/> # https://developers.google.com/workspace/admin/directory/v1/guides/manage-users<br/> hash_function : optional(string),<br/> password : optional(string),<br/> }))</pre> | `{}` | no |
74137

75138
## Outputs
76139

77-
| Name | Description |
78-
|------|-------------|
79-
| <a name="output_random_pet_name"></a> [random\_pet\_name](#output\_random\_pet\_name) | The generated random pet name |
140+
No outputs.
80141
<!-- END OF PRE-COMMIT-TERRAFORM DOCS HOOK -->
81142
<!-- markdownlint-enable MD013 -->
82143
<!-- prettier-ignore-end -->
@@ -138,11 +199,8 @@ Copyright © 2016-2025 [Masterpoint Consulting LLC](https://masterpoint.io/)
138199
[newsletter-url]: https://newsletter.masterpoint.io/
139200
[youtube-badge]: https://img.shields.io/badge/YouTube-Subscribe-D191BF?style=for-the-badge&logo=youtube&logoColor=white
140201
[youtube-url]: https://www.youtube.com/channel/UCeeDaO2NREVlPy9Plqx-9JQ
141-
142-
<!-- TODO: Replace `terraform-module-template` with your actual repository name. -->
143-
144-
[release-badge]: https://img.shields.io/github/v/release/masterpointio/terraform-module-template?color=0E383A&label=Release&style=for-the-badge&logo=github&logoColor=white
145-
[latest-release]: https://github.com/masterpointio/terraform-module-template/releases/latest
146-
[contributors-image]: https://contrib.rocks/image?repo=masterpointio/terraform-module-template
147-
[contributors-url]: https://github.com/masterpointio/terraform-module-template/graphs/contributors
148-
[issues-url]: https://github.com/masterpointio/terraform-module-template/issues
202+
[release-badge]: https://img.shields.io/github/v/release/masterpointio/terraform-googleworkspace-users-groups-automation?color=0E383A&label=Release&style=for-the-badge&logo=github&logoColor=white
203+
[latest-release]: https://github.com/masterpointio/terraform-googleworkspace-users-groups-automation/releases/latest
204+
[contributors-image]: https://contrib.rocks/image?repo=masterpointio/terraform-googleworkspace-users-groups-automation
205+
[contributors-url]: https://github.com/masterpointio/terraform-googleworkspace-users-groups-automation/graphs/contributors
206+
[issues-url]: https://github.com/masterpointio/terraform-googleworkspace-users-groups-automation/issues

0 commit comments

Comments
 (0)