Skip to content
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

make iam members case insensitive #3900

Merged
merged 1 commit into from
Jun 24, 2019
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
make iam members case insensitive
Signed-off-by: Modular Magician <magic-modules@google.com>
danawillow authored and modular-magician committed Jun 21, 2019
commit 7cf07647fffb5667b9da860ca0806a76f87648bb
8 changes: 4 additions & 4 deletions google/resource_compute_instance_iam_test.go
Original file line number Diff line number Diff line change
@@ -130,7 +130,7 @@ func testAccComputeInstanceIamMember_basic(zone, instanceName, roleId string) st
zone = "${google_compute_instance.test_vm.zone}"
instance_name = "${google_compute_instance.test_vm.name}"
role = "%s"
member = "user:admin@hashicorptest.com"
member = "user:Admin@hashicorptest.com"
}

`, zone, instanceName, roleId)
@@ -157,7 +157,7 @@ func testAccComputeInstanceIamPolicy_basic(zone, instanceName, roleId string) st
data "google_iam_policy" "foo" {
binding {
role = "%s"
members = ["user:admin@hashicorptest.com"]
members = ["user:Admin@hashicorptest.com"]
}
}

@@ -194,7 +194,7 @@ func testAccComputeInstanceIamBinding_basic(zone, instanceName, roleId string) s
zone = "${google_compute_instance.test_vm.zone}"
instance_name = "${google_compute_instance.test_vm.name}"
role = "%s"
members = ["user:admin@hashicorptest.com"]
members = ["user:Admin@hashicorptest.com"]
}

`, zone, instanceName, roleId)
@@ -223,7 +223,7 @@ func testAccComputeInstanceIamBinding_update(zone, instanceName, roleId string)
zone = "${google_compute_instance.test_vm.zone}"
instance_name = "${google_compute_instance.test_vm.name}"
role = "%s"
members = ["user:admin@hashicorptest.com", "user:paddy@hashicorp.com"]
members = ["user:Admin@hashicorptest.com", "user:paddy@hashicorp.com"]
}

`, zone, instanceName, roleId)
4 changes: 4 additions & 0 deletions google/resource_google_project_iam_policy.go
Original file line number Diff line number Diff line change
@@ -6,6 +6,7 @@ import (
"log"
"reflect"
"sort"
"strings"

"github.com/hashicorp/errwrap"
"github.com/hashicorp/terraform/helper/schema"
@@ -217,6 +218,9 @@ func derefBindings(b []*cloudresourcemanager.Binding) []cloudresourcemanager.Bin

for i, v := range b {
db[i] = *v
for j, m := range db[i].Members {
db[i].Members[j] = strings.ToLower(m)
}
sort.Strings(db[i].Members)
}
return db
6 changes: 5 additions & 1 deletion google/resource_iam_binding.go
Original file line number Diff line number Diff line change
@@ -20,7 +20,11 @@ var iamBindingSchema = map[string]*schema.Schema{
Type: schema.TypeSet,
Required: true,
Elem: &schema.Schema{
Type: schema.TypeString,
Type: schema.TypeString,
DiffSuppressFunc: caseDiffSuppress,
},
Set: func(v interface{}) int {
return schema.HashString(strings.ToLower(v.(string)))
},
},
"etag": {
13 changes: 7 additions & 6 deletions google/resource_iam_member.go
Original file line number Diff line number Diff line change
@@ -17,9 +17,10 @@ var IamMemberBaseSchema = map[string]*schema.Schema{
ForceNew: true,
},
"member": {
Type: schema.TypeString,
Required: true,
ForceNew: true,
Type: schema.TypeString,
Required: true,
ForceNew: true,
DiffSuppressFunc: caseDiffSuppress,
},
"etag": {
Type: schema.TypeString,
@@ -98,7 +99,7 @@ func resourceIamMemberCreate(newUpdaterFunc newResourceIamUpdaterFunc) schema.Cr
if err != nil {
return err
}
d.SetId(updater.GetResourceId() + "/" + p.Role + "/" + p.Members[0])
d.SetId(updater.GetResourceId() + "/" + p.Role + "/" + strings.ToLower(p.Members[0]))
return resourceIamMemberRead(newUpdaterFunc)(d, meta)
}
}
@@ -138,7 +139,7 @@ func resourceIamMemberRead(newUpdaterFunc newResourceIamUpdaterFunc) schema.Read
}
var member string
for _, m := range binding.Members {
if m == eMember.Members[0] {
if strings.ToLower(m) == strings.ToLower(eMember.Members[0]) {
member = m
}
}
@@ -179,7 +180,7 @@ func resourceIamMemberDelete(newUpdaterFunc newResourceIamUpdaterFunc) schema.De
binding := p.Bindings[bindingToRemove]
memberToRemove := -1
for pos, m := range binding.Members {
if m != member.Members[0] {
if strings.ToLower(m) != strings.ToLower(member.Members[0]) {
continue
}
memberToRemove = pos