Skip to content

Commit

Permalink
Add mutex to compute_project_metadata_item (#4778) (#3262)
Browse files Browse the repository at this point in the history
Co-authored-by: Chris Tomlinson <chris.tomlinson@dunnhumby.com>
Signed-off-by: Modular Magician <magic-modules@google.com>

Co-authored-by: Chris Tomlinson <chris.tomlinson@dunnhumby.com>
  • Loading branch information
modular-magician and Chris Tomlinson authored May 17, 2021
1 parent 1cd7edf commit 328faec
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 0 deletions.
3 changes: 3 additions & 0 deletions .changelog/4778.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
```release-note:bug
compute: added mutex in `google_compute_metadata_item` to reduce retries + quota errors
```
4 changes: 4 additions & 0 deletions google-beta/resource_compute_project_metadata_item.go
Original file line number Diff line number Diff line change
Expand Up @@ -170,6 +170,10 @@ func resourceComputeProjectMetadataItemDelete(d *schema.ResourceData, meta inter

func updateComputeCommonInstanceMetadata(config *Config, projectID, key, userAgent string, afterVal *string, timeout time.Duration, failIfPresent metadataPresentBehavior) error {
updateMD := func() error {
lockName := fmt.Sprintf("projects/%s/commoninstancemetadata", projectID)
mutexKV.Lock(lockName)
defer mutexKV.Unlock(lockName)

log.Printf("[DEBUG] Loading project metadata: %s", projectID)
project, err := config.NewComputeClient(userAgent).Projects.Get(projectID).Do()
if err != nil {
Expand Down

0 comments on commit 328faec

Please sign in to comment.