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 {