Skip to content

Commit

Permalink
make iam members case insensitive (#3900)
Browse files Browse the repository at this point in the history
Signed-off-by: Modular Magician <magic-modules@google.com>
  • Loading branch information
modular-magician authored and danawillow committed Jun 24, 2019
1 parent 1da7310 commit 51a5322
Show file tree
Hide file tree
Showing 4 changed files with 20 additions and 11 deletions.
8 changes: 4 additions & 4 deletions google/resource_compute_instance_iam_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand All @@ -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"]
}
}
Expand Down Expand Up @@ -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)
Expand Down Expand Up @@ -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)
Expand Down
4 changes: 4 additions & 0 deletions google/resource_google_project_iam_policy.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import (
"log"
"reflect"
"sort"
"strings"

"github.com/hashicorp/errwrap"
"github.com/hashicorp/terraform/helper/schema"
Expand Down Expand Up @@ -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
Expand Down
6 changes: 5 additions & 1 deletion google/resource_iam_binding.go
Original file line number Diff line number Diff line change
Expand Up @@ -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": {
Expand Down
13 changes: 7 additions & 6 deletions google/resource_iam_member.go
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down Expand Up @@ -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)
}
}
Expand Down Expand Up @@ -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
}
}
Expand Down Expand Up @@ -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
Expand Down

0 comments on commit 51a5322

Please sign in to comment.