From 328faec6de0e1f1fbc7b4616083c251317648d00 Mon Sep 17 00:00:00 2001 From: The Magician Date: Mon, 17 May 2021 15:33:35 -0700 Subject: [PATCH] Add mutex to compute_project_metadata_item (#4778) (#3262) Co-authored-by: Chris Tomlinson Signed-off-by: Modular Magician Co-authored-by: Chris Tomlinson --- .changelog/4778.txt | 3 +++ google-beta/resource_compute_project_metadata_item.go | 4 ++++ 2 files changed, 7 insertions(+) create mode 100644 .changelog/4778.txt diff --git a/.changelog/4778.txt b/.changelog/4778.txt new file mode 100644 index 0000000000..0b12793a4f --- /dev/null +++ b/.changelog/4778.txt @@ -0,0 +1,3 @@ +```release-note:bug +compute: added mutex in `google_compute_metadata_item` to reduce retries + quota errors +``` diff --git a/google-beta/resource_compute_project_metadata_item.go b/google-beta/resource_compute_project_metadata_item.go index 0e4572342b..48bc92e01a 100644 --- a/google-beta/resource_compute_project_metadata_item.go +++ b/google-beta/resource_compute_project_metadata_item.go @@ -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 {