-
Notifications
You must be signed in to change notification settings - Fork 856
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Cloud Identity Group module #182
Merged
Changes from all commits
Commits
Show all changes
7 commits
Select commit
Hold shift + click to select a range
8f8a7e1
New Cloud Identity module
juliocc 71dab68
Add tests to cloud-identity-group module
juliocc 0a119eb
Fix boilerplate
juliocc 072c7e2
Fix outputs
juliocc e1095eb
Remove support for creating managers and admins
juliocc 53c9844
Update cloud-identity-group README
juliocc e8fe6c7
Small fix to cloud-identity-group README
juliocc File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,52 @@ | ||
# Cloud Identity Group Module | ||
|
||
This module allows creating a Cloud Identity group and assigning members. | ||
|
||
## Usage | ||
To use this module you must either run terraform as a user that has the Groups Admin role in Cloud Identity or [enable domain-wide delegation](https://developers.google.com/admin-sdk/directory/v1/guides/delegation) to the service account used by terraform. If you use a service account, you must also grant that service account the Groups Admin role in Cloud Identity. | ||
|
||
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: | ||
- 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. | ||
|
||
## Examples | ||
|
||
### Simple Group | ||
```hcl | ||
module "group" { | ||
source = "./modules/cloud-identity-group" | ||
customer_id = "customers/C01234567" | ||
name = "[email protected]" | ||
display_name = "My group name" | ||
description = "My group Description" | ||
members = [ | ||
"[email protected]", | ||
"[email protected]", | ||
"[email protected]" | ||
] | ||
} | ||
# tftest:modules=1:resources=4 | ||
``` | ||
|
||
<!-- BEGIN TFDOC --> | ||
## Variables | ||
|
||
| name | description | type | required | default | | ||
|---|---|:---: |:---:|:---:| | ||
| customer_id | Directory customer ID in the form customers/C0xxxxxxx. | <code title="string validation { condition = can(regex("^customers/C0[a-z0-9]{7}$", var.customer_id)) error_message = "Customer ID must be in the form customers/C0xxxxxxx." }">string</code> | ✓ | | | ||
| display_name | Group display name. | <code title="">string</code> | ✓ | | | ||
| name | Group ID (usually an email). | <code title="">string</code> | ✓ | | | ||
| *description* | Group description | <code title="">string</code> | | <code title="">null</code> | | ||
| *members* | List of group members. | <code title="list(string)">list(string)</code> | | <code title="">[]</code> | | ||
|
||
## Outputs | ||
|
||
| name | description | sensitive | | ||
|---|---|:---:| | ||
| id | Group ID. | | | ||
| name | Group name. | | | ||
<!-- END TFDOC --> |
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 |
---|---|---|
@@ -0,0 +1,52 @@ | ||
/** | ||
* Copyright 2020 Google LLC | ||
* | ||
* Licensed under the Apache License, Version 2.0 (the "License"); | ||
* you may not use this file except in compliance with the License. | ||
* You may obtain a copy of the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, software | ||
* distributed under the License is distributed on an "AS IS" BASIS, | ||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
* See the License for the specific language governing permissions and | ||
* limitations under the License. | ||
*/ | ||
|
||
resource "google_cloud_identity_group" "group" { | ||
display_name = var.display_name | ||
parent = var.customer_id | ||
|
||
group_key { | ||
id = var.name | ||
} | ||
|
||
labels = { | ||
"cloudidentity.googleapis.com/groups.discussion_forum" = "" | ||
} | ||
} | ||
|
||
# resource "google_cloud_identity_group_membership" "owners" { | ||
# group = google_cloud_identity_group.group.id | ||
# for_each = toset(var.owners) | ||
# preferred_member_key { id = each.key } | ||
# roles { name = "OWNER" } | ||
# 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" } | ||
} |
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 |
---|---|---|
@@ -0,0 +1,28 @@ | ||
/** | ||
* Copyright 2020 Google LLC | ||
* | ||
* Licensed under the Apache License, Version 2.0 (the "License"); | ||
* you may not use this file except in compliance with the License. | ||
* You may obtain a copy of the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, software | ||
* distributed under the License is distributed on an "AS IS" BASIS, | ||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
* See the License for the specific language governing permissions and | ||
* limitations under the License. | ||
*/ | ||
|
||
output "id" { | ||
description = "Group ID." | ||
value = google_cloud_identity_group.group.id | ||
} | ||
|
||
output "name" { | ||
description = "Group name." | ||
value = var.name | ||
depends_on = [ | ||
google_cloud_identity_group.group | ||
] | ||
} |
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 |
---|---|---|
@@ -0,0 +1,58 @@ | ||
/** | ||
* Copyright 2020 Google LLC | ||
* | ||
* Licensed under the Apache License, Version 2.0 (the "License"); | ||
* you may not use this file except in compliance with the License. | ||
* You may obtain a copy of the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, software | ||
* distributed under the License is distributed on an "AS IS" BASIS, | ||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
* See the License for the specific language governing permissions and | ||
* limitations under the License. | ||
*/ | ||
|
||
variable "display_name" { | ||
description = "Group display name." | ||
type = string | ||
} | ||
|
||
variable "name" { | ||
description = "Group ID (usually an email)." | ||
type = string | ||
} | ||
|
||
variable "description" { | ||
description = "Group description" | ||
type = string | ||
default = null | ||
} | ||
|
||
variable "customer_id" { | ||
description = "Directory customer ID in the form customers/C0xxxxxxx." | ||
type = string | ||
validation { | ||
condition = can(regex("^customers/C0[a-z0-9]{7}$", var.customer_id)) | ||
error_message = "Customer ID must be in the form customers/C0xxxxxxx." | ||
} | ||
} | ||
|
||
# variable "owners" { | ||
# description = "List of group owners." | ||
# type = list(string) | ||
# default = [] | ||
# } | ||
|
||
# variable "managers" { | ||
# description = "List of group managers." | ||
# type = list(string) | ||
# default = [] | ||
# } | ||
|
||
variable "members" { | ||
description = "List of group members." | ||
type = list(string) | ||
default = [] | ||
} |
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 |
---|---|---|
@@ -0,0 +1,22 @@ | ||
/** | ||
* Copyright 2020 Google LLC | ||
* | ||
* Licensed under the Apache License, Version 2.0 (the "License"); | ||
* you may not use this file except in compliance with the License. | ||
* You may obtain a copy of the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, software | ||
* distributed under the License is distributed on an "AS IS" BASIS, | ||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
* See the License for the specific language governing permissions and | ||
* limitations under the License. | ||
*/ | ||
|
||
terraform { | ||
required_version = ">= 0.13.0" | ||
required_providers { | ||
google = "~> 3.49" | ||
} | ||
} |
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 |
---|---|---|
@@ -0,0 +1,13 @@ | ||
# Copyright 2020 Google LLC | ||
# | ||
# Licensed under the Apache License, Version 2.0 (the "License"); | ||
# you may not use this file except in compliance with the License. | ||
# You may obtain a copy of the License at | ||
# | ||
# http://www.apache.org/licenses/LICENSE-2.0 | ||
# | ||
# Unless required by applicable law or agreed to in writing, software | ||
# distributed under the License is distributed on an "AS IS" BASIS, | ||
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
# See the License for the specific language governing permissions and | ||
# limitations under the License. |
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 |
---|---|---|
@@ -0,0 +1,24 @@ | ||
/** | ||
* Copyright 2020 Google LLC | ||
* | ||
* Licensed under the Apache License, Version 2.0 (the "License"); | ||
* you may not use this file except in compliance with the License. | ||
* You may obtain a copy of the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, software | ||
* distributed under the License is distributed on an "AS IS" BASIS, | ||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
* See the License for the specific language governing permissions and | ||
* limitations under the License. | ||
*/ | ||
|
||
module "test" { | ||
source = "../../../../modules/cloud-identity-group" | ||
name = var.name | ||
display_name = var.display_name | ||
description = var.description | ||
customer_id = var.customer_id | ||
members = var.members | ||
} |
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 |
---|---|---|
@@ -0,0 +1,40 @@ | ||
/** | ||
* Copyright 2020 Google LLC | ||
* | ||
* Licensed under the Apache License, Version 2.0 (the "License"); | ||
* you may not use this file except in compliance with the License. | ||
* You may obtain a copy of the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, software | ||
* distributed under the License is distributed on an "AS IS" BASIS, | ||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
* See the License for the specific language governing permissions and | ||
* limitations under the License. | ||
*/ | ||
|
||
variable "display_name" { | ||
type = string | ||
default = "display name" | ||
} | ||
|
||
variable "name" { | ||
type = string | ||
default = "[email protected]" | ||
} | ||
|
||
variable "description" { | ||
type = string | ||
default = null | ||
} | ||
|
||
variable "customer_id" { | ||
type = string | ||
default = "customers/C01234567" | ||
} | ||
|
||
variable "members" { | ||
type = list(string) | ||
default = [] | ||
} |
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 |
---|---|---|
@@ -0,0 +1,49 @@ | ||
# Copyright 2020 Google LLC | ||
# | ||
# Licensed under the Apache License, Version 2.0 (the "License"); | ||
# you may not use this file except in compliance with the License. | ||
# You may obtain a copy of the License at | ||
# | ||
# http://www.apache.org/licenses/LICENSE-2.0 | ||
# | ||
# Unless required by applicable law or agreed to in writing, software | ||
# distributed under the License is distributed on an "AS IS" BASIS, | ||
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
# See the License for the specific language governing permissions and | ||
# limitations under the License. | ||
|
||
|
||
import os | ||
import pytest | ||
|
||
from collections import Counter | ||
|
||
|
||
FIXTURES_DIR = os.path.join(os.path.dirname(__file__), 'fixture') | ||
|
||
|
||
def test_group(plan_runner): | ||
"Test group." | ||
_, resources = plan_runner(FIXTURES_DIR) | ||
assert len(resources) == 1 | ||
r = resources[0] | ||
assert r['type'] == 'google_cloud_identity_group' | ||
assert r['values']['display_name'] == 'display name' | ||
assert r['values']['group_key'][0]['id'] == '[email protected]' | ||
assert r['values']['parent'] == 'customers/C01234567' | ||
|
||
|
||
def test_members(plan_runner): | ||
"Test group members." | ||
members = '["[email protected]"]' | ||
_, resources = plan_runner(FIXTURES_DIR, members=members) | ||
|
||
resource_types = Counter([r['type'] for r in resources]) | ||
assert resource_types == { | ||
'google_cloud_identity_group': 1, | ||
'google_cloud_identity_group_membership': 1, | ||
} | ||
|
||
values = next(r['values'] for r in resources if r['name'] == 'members') | ||
assert values['preferred_member_key'][0]['id'] == '[email protected]' | ||
assert [role['name'] for role in values['roles']] == ['MEMBER'] |
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Nit: potentially external members can be allowed after setting allowExternalMembers - this can't be easily automated with TF yet as the provisioner doesn't support the admin-sdk.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think the terraform resource uses the Directory API, which doesn't support the allowExternalMembers option.