Skip to content

Commit

Permalink
Fix bug: diff being detected for source_repo_repository even when the…
Browse files Browse the repository at this point in the history
…re are no changes (#3786)

This patch fixes a bug in source_repo_repository where a diff was always
being generated for the TypeSet field `pubsub_configs` since its Set
hashing function was not accounting for the fact that
`pubsub_configs[].topic` can contain either a topic's name or relative
path.
  • Loading branch information
jcanseco authored Jul 29, 2020
1 parent cc23ecf commit acb73ca
Show file tree
Hide file tree
Showing 2 changed files with 32 additions and 0 deletions.
2 changes: 2 additions & 0 deletions products/sourcerepo/terraform.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -49,9 +49,11 @@ overrides: !ruby/object:Overrides::ResourceOverrides
A Cloud Pub/Sub topic in this repo's project. Values are of the form
`projects/<project>/topics/<topic>` or `<topic>` (where the topic will
be inferred).
set_hash_func: 'resourceSourceRepoRepositoryPubSubConfigsHash'
pubsubConfigs.serviceAccountEmail: !ruby/object:Overrides::Terraform::PropertyOverride
default_from_api: true
custom_code: !ruby/object:Provider::Terraform::CustomCode
constants: templates/terraform/constants/source_repo_repository.go.erb
update_encoder: templates/terraform/update_encoder/source_repo_repository.erb
post_create: templates/terraform/post_create/source_repo_repository_update.go.erb
# This is for copying files over
Expand Down
30 changes: 30 additions & 0 deletions templates/terraform/constants/source_repo_repository.go.erb
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
<%- # the license inside this block applies to this file
# Copyright 2019 Google Inc.
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
-%>
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())
}

0 comments on commit acb73ca

Please sign in to comment.