Skip to content

Commit

Permalink
Add filestore index mutex (#4886) (#9396)
Browse files Browse the repository at this point in the history
Signed-off-by: Modular Magician <[email protected]>
  • Loading branch information
modular-magician authored Jun 18, 2021
1 parent 0e19c11 commit d2e0482
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 0 deletions.
3 changes: 3 additions & 0 deletions .changelog/4886.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
```release-note:bug
filestore: fixed an issue in `google_filestore_instance` where creating two instances simultaneously resulted in an error.
```
21 changes: 21 additions & 0 deletions google/resource_filestore_instance.go
Original file line number Diff line number Diff line change
Expand Up @@ -202,6 +202,13 @@ func resourceFilestoreInstanceCreate(d *schema.ResourceData, meta interface{}) e
obj["networks"] = networksProp
}

lockName, err := replaceVars(d, config, "filestore/{{project}}")
if err != nil {
return err
}
mutexKV.Lock(lockName)
defer mutexKV.Unlock(lockName)

url, err := replaceVars(d, config, "{{FilestoreBasePath}}projects/{{project}}/locations/{{zone}}/instances?instanceId={{name}}")
if err != nil {
return err
Expand Down Expand Up @@ -351,6 +358,13 @@ func resourceFilestoreInstanceUpdate(d *schema.ResourceData, meta interface{}) e
obj["fileShares"] = fileSharesProp
}

lockName, err := replaceVars(d, config, "filestore/{{project}}")
if err != nil {
return err
}
mutexKV.Lock(lockName)
defer mutexKV.Unlock(lockName)

url, err := replaceVars(d, config, "{{FilestoreBasePath}}projects/{{project}}/locations/{{zone}}/instances/{{name}}")
if err != nil {
return err
Expand Down Expand Up @@ -416,6 +430,13 @@ func resourceFilestoreInstanceDelete(d *schema.ResourceData, meta interface{}) e
}
billingProject = project

lockName, err := replaceVars(d, config, "filestore/{{project}}")
if err != nil {
return err
}
mutexKV.Lock(lockName)
defer mutexKV.Unlock(lockName)

url, err := replaceVars(d, config, "{{FilestoreBasePath}}projects/{{project}}/locations/{{zone}}/instances/{{name}}")
if err != nil {
return err
Expand Down

0 comments on commit d2e0482

Please sign in to comment.