Skip to content

Commit

Permalink
make iam members case insensitive (#1957)
Browse files Browse the repository at this point in the history
Merged PR #1957.
  • Loading branch information
danawillow authored and modular-magician committed Jun 24, 2019
1 parent a9aa31d commit e9348b5
Show file tree
Hide file tree
Showing 6 changed files with 22 additions and 13 deletions.
2 changes: 1 addition & 1 deletion build/terraform
2 changes: 1 addition & 1 deletion build/terraform-beta
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:[email protected]"]
members = ["user:Admin@hashicorptest.com", "user:[email protected]"]
}
`, zone, instanceName, roleId)
Expand Down
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 third_party/terraform/resources/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 third_party/terraform/resources/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 e9348b5

Please sign in to comment.