diff --git a/.changelog/3786.txt b/.changelog/3786.txt new file mode 100644 index 00000000000..94427bbbacf --- /dev/null +++ b/.changelog/3786.txt @@ -0,0 +1,3 @@ +```release-note:bug +sourcerepo: fixed perma-diff in `google_sourcerepo_repository` +``` diff --git a/google/resource_source_repo_repository.go b/google/resource_source_repo_repository.go index 9f963d36823..721eff7983a 100644 --- a/google/resource_source_repo_repository.go +++ b/google/resource_source_repo_repository.go @@ -15,6 +15,7 @@ package google import ( + "bytes" "fmt" "log" "reflect" @@ -22,10 +23,28 @@ import ( "strings" "time" + "github.com/hashicorp/terraform-plugin-sdk/helper/hashcode" "github.com/hashicorp/terraform-plugin-sdk/helper/schema" "github.com/hashicorp/terraform-plugin-sdk/helper/validation" ) +func resourceSourceRepoRepositoryPubSubConfigsHash(v interface{}) int { + if v == nil { + return 0 + } + + var buf bytes.Buffer + m := v.(map[string]interface{}) + + buf.WriteString(fmt.Sprintf("%s-", GetResourceNameFromSelfLink(m["topic"].(string)))) + buf.WriteString(fmt.Sprintf("%s-", m["message_format"].(string))) + if v, ok := m["service_account_email"]; ok { + buf.WriteString(fmt.Sprintf("%s-", v.(string))) + } + + return hashcode.String(buf.String()) +} + func resourceSourceRepoRepository() *schema.Resource { return &schema.Resource{ Create: resourceSourceRepoRepositoryCreate, @@ -81,6 +100,7 @@ If unspecified, it defaults to the compute engine default service account.`, }, }, }, + Set: resourceSourceRepoRepositoryPubSubConfigsHash, }, "size": { Type: schema.TypeInt,