diff --git a/google/data_source_google_iam_policy.go b/google/data_source_google_iam_policy.go index 3a8bac5ed1a..a2dd6237ab0 100644 --- a/google/data_source_google_iam_policy.go +++ b/google/data_source_google_iam_policy.go @@ -2,6 +2,7 @@ package google import ( "encoding/json" + "sort" "strconv" "github.com/hashicorp/terraform/helper/hashcode" @@ -97,12 +98,22 @@ func dataSourceGoogleIamPolicyRead(d *schema.ResourceData, meta interface{}) err // Convert each config binding into a cloudresourcemanager.Binding for i, v := range bset.List() { binding := v.(map[string]interface{}) + members := convertStringSet(binding["members"].(*schema.Set)) + + // Sort members to get simpler diffs as it's what the API does + sort.Strings(members) + policy.Bindings[i] = &cloudresourcemanager.Binding{ Role: binding["role"].(string), - Members: convertStringSet(binding["members"].(*schema.Set)), + Members: members, } } + // Sort bindings by their role name to get simpler diffs as it's what the API does + sort.Slice(bindings, func(i, j int) bool { + return bindings[i].Role < bindings[j].Role + }) + // Convert each audit_config into a cloudresourcemanager.AuditConfig policy.AuditConfigs = expandAuditConfig(aset)