-
Notifications
You must be signed in to change notification settings - Fork 856
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* New Cloud Identity module * Add tests to cloud-identity-group module * Fix boilerplate * Fix outputs * Remove support for creating managers and admins * Update cloud-identity-group README * Small fix to cloud-identity-group README
- Loading branch information
Showing
9 changed files
with
338 additions
and
0 deletions.
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'] |