-
Notifications
You must be signed in to change notification settings - Fork 1.8k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Change IAM binding to be authoritative (#2764)
<!-- This change is generated by MagicModules. --> /cc @chrisst
- Loading branch information
1 parent
505cb42
commit 43d40f4
Showing
13 changed files
with
172 additions
and
121 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
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 |
---|---|---|
|
@@ -169,6 +169,62 @@ func testAccCheckGoogleProjectIamPolicyExists(projectRes, policyRes, pid string) | |
} | ||
} | ||
|
||
func TestIamOverwriteBinding(t *testing.T) { | ||
table := []struct { | ||
input []*cloudresourcemanager.Binding | ||
override cloudresourcemanager.Binding | ||
expect []cloudresourcemanager.Binding | ||
}{ | ||
{ | ||
input: []*cloudresourcemanager.Binding{ | ||
{ | ||
Role: "role-1", | ||
Members: []string{"member-1", "member-2"}, | ||
}, | ||
}, | ||
override: cloudresourcemanager.Binding{ | ||
Role: "role-1", | ||
Members: []string{"new-member"}, | ||
}, | ||
expect: []cloudresourcemanager.Binding{ | ||
{ | ||
Role: "role-1", | ||
Members: []string{"new-member"}, | ||
}, | ||
}, | ||
}, | ||
{ | ||
input: []*cloudresourcemanager.Binding{ | ||
{ | ||
Role: "role-1", | ||
Members: []string{"member-1", "member-2"}, | ||
}, | ||
}, | ||
override: cloudresourcemanager.Binding{ | ||
Role: "role-2", | ||
Members: []string{"member-3"}, | ||
}, | ||
expect: []cloudresourcemanager.Binding{ | ||
{ | ||
Role: "role-1", | ||
Members: []string{"member-1", "member-2"}, | ||
}, | ||
{ | ||
Role: "role-2", | ||
Members: []string{"member-3"}, | ||
}, | ||
}, | ||
}, | ||
} | ||
|
||
for _, test := range table { | ||
got := overwriteBinding(test.input, &test.override) | ||
if !reflect.DeepEqual(derefBindings(got), test.expect) { | ||
t.Errorf("OverwriteIamBinding failed.\nGot %+v\nWant %+v", derefBindings(got), test.expect) | ||
} | ||
} | ||
} | ||
|
||
func TestIamMergeBindings(t *testing.T) { | ||
table := []struct { | ||
input []*cloudresourcemanager.Binding | ||
|
@@ -177,95 +233,61 @@ func TestIamMergeBindings(t *testing.T) { | |
{ | ||
input: []*cloudresourcemanager.Binding{ | ||
{ | ||
Role: "role-1", | ||
Members: []string{ | ||
"member-1", | ||
"member-2", | ||
}, | ||
Role: "role-1", | ||
Members: []string{"member-1", "member-2"}, | ||
}, | ||
{ | ||
Role: "role-1", | ||
Members: []string{ | ||
"member-3", | ||
}, | ||
Role: "role-1", | ||
Members: []string{"member-3"}, | ||
}, | ||
}, | ||
expect: []cloudresourcemanager.Binding{ | ||
{ | ||
Role: "role-1", | ||
Members: []string{ | ||
"member-1", | ||
"member-2", | ||
"member-3", | ||
}, | ||
Role: "role-1", | ||
Members: []string{"member-1", "member-2", "member-3"}, | ||
}, | ||
}, | ||
}, | ||
{ | ||
input: []*cloudresourcemanager.Binding{ | ||
{ | ||
Role: "role-1", | ||
Members: []string{ | ||
"member-3", | ||
"member-4", | ||
}, | ||
Role: "role-1", | ||
Members: []string{"member-3", "member-4"}, | ||
}, | ||
{ | ||
Role: "role-1", | ||
Members: []string{ | ||
"member-2", | ||
"member-1", | ||
}, | ||
Role: "role-1", | ||
Members: []string{"member-2", "member-1"}, | ||
}, | ||
{ | ||
Role: "role-2", | ||
Members: []string{ | ||
"member-1", | ||
}, | ||
Role: "role-2", | ||
Members: []string{"member-1"}, | ||
}, | ||
{ | ||
Role: "role-1", | ||
Members: []string{ | ||
"member-5", | ||
}, | ||
Role: "role-1", | ||
Members: []string{"member-5"}, | ||
}, | ||
{ | ||
Role: "role-3", | ||
Members: []string{ | ||
"member-1", | ||
}, | ||
Role: "role-3", | ||
Members: []string{"member-1"}, | ||
}, | ||
{ | ||
Role: "role-2", | ||
Members: []string{ | ||
"member-2", | ||
}, | ||
Role: "role-2", | ||
Members: []string{"member-2"}, | ||
}, | ||
{Role: "empty-role", Members: []string{}}, | ||
}, | ||
expect: []cloudresourcemanager.Binding{ | ||
{ | ||
Role: "role-1", | ||
Members: []string{ | ||
"member-1", | ||
"member-2", | ||
"member-3", | ||
"member-4", | ||
"member-5", | ||
}, | ||
Role: "role-1", | ||
Members: []string{"member-1", "member-2", "member-3", "member-4", "member-5"}, | ||
}, | ||
{ | ||
Role: "role-2", | ||
Members: []string{ | ||
"member-1", | ||
"member-2", | ||
}, | ||
Role: "role-2", | ||
Members: []string{"member-1", "member-2"}, | ||
}, | ||
{ | ||
Role: "role-3", | ||
Members: []string{ | ||
"member-1", | ||
}, | ||
Role: "role-3", | ||
Members: []string{"member-1"}, | ||
}, | ||
}, | ||
}, | ||
|
@@ -416,7 +438,7 @@ data "google_iam_policy" "expanded" { | |
"user:[email protected]", | ||
] | ||
} | ||
binding { | ||
role = "roles/viewer" | ||
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
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 |
---|---|---|
|
@@ -26,10 +26,10 @@ data "google_iam_policy" "admin" { | |
role = "roles/storage.objectViewer" | ||
members = [ | ||
"user:jane@example.com", | ||
"user:alice@gmail.com", | ||
] | ||
} | ||
audit_config { | ||
service = "cloudkms.googleapis.com" | ||
audit_log_configs = [ | ||
|
@@ -73,11 +73,11 @@ each accept the following arguments: | |
See the [IAM Roles](https://cloud.google.com/compute/docs/access/iam) documentation for a complete list of roles. | ||
Note that custom roles must be of the format `[projects|organizations]/{parent-name}/roles/{role-name}`. | ||
|
||
* `members` (Required) - An array of identites that will be granted the privilege in the `role`. | ||
* `members` (Required) - An array of identites that will be granted the privilege in the `role`. For more details on format and restrictions see https://cloud.google.com/billing/reference/rest/v1/Policy#Binding | ||
Each entry can have one of the following values: | ||
* **allUsers**: A special identifier that represents anyone who is on the internet; with or without a Google account. It **can't** be used with the `google_project` resource. | ||
* **allAuthenticatedUsers**: A special identifier that represents anyone who is authenticated with a Google account or a service account. It **can't** be used with the `google_project` resource. | ||
* **user:{emailid}**: An email address that represents a specific Google account. For example, [email protected] or [email protected]. | ||
* **user:{emailid}**: An email address that represents a specific Google account. For example, [email protected]. | ||
* **serviceAccount:{emailid}**: An email address that represents a service account. For example, [email protected]. | ||
* **group:{emailid}**: An email address that represents a Google group. For example, [email protected]. | ||
* **domain:{domain}**: A G Suite domain (primary, instead of alias) name that represents all the users of that domain. For example, google.com or example.com. | ||
|
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
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
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 |
---|---|---|
|
@@ -15,6 +15,10 @@ an existing Google Cloud Platform folder. | |
`google_folder_iam_policy` or they will fight over what your policy | ||
should be. | ||
|
||
~> **Note:** On create, this resource will overwrite members of any existing roles. | ||
Use `terraform import` and inspect the `terraform plan` output to ensure | ||
your existing members are preserved. | ||
|
||
## Example Usage | ||
|
||
```hcl | ||
|
@@ -28,7 +32,7 @@ resource "google_folder_iam_binding" "admin" { | |
role = "roles/editor" | ||
members = [ | ||
"user:jane@example.com", | ||
"user:alice@gmail.com", | ||
] | ||
} | ||
``` | ||
|
@@ -41,10 +45,11 @@ The following arguments are supported: | |
|
||
* `members` (Required) - An array of identites that will be granted the privilege in the `role`. | ||
Each entry can have one of the following values: | ||
* **user:{emailid}**: An email address that represents a specific Google account. For example, alice@gmail.com or joe@example.com. | ||
* **user:{emailid}**: An email address that is associated with a specific Google account. For example, [email protected]. | ||
* **serviceAccount:{emailid}**: An email address that represents a service account. For example, [email protected]. | ||
* **group:{emailid}**: An email address that represents a Google group. For example, [email protected]. | ||
* **domain:{domain}**: A G Suite domain (primary, instead of alias) name that represents all the users of that domain. For example, google.com or example.com. | ||
* For more details on format and restrictions see https://cloud.google.com/billing/reference/rest/v1/Policy#Binding | ||
|
||
* `role` - (Required) The role that should be applied. Only one | ||
`google_folder_iam_binding` can be used per role. Note that custom roles must be of the format | ||
|
Oops, something went wrong.