mirror of
https://github.com/letic/terraform-provider-google.git
synced 2024-06-29 06:42:36 +00:00
Add additional fingerprint error to check for when updating metadata (#221)
This commit is contained in:
parent
adaae73e8f
commit
4c8f62edf6
|
@ -3,12 +3,14 @@ package google
|
||||||
import (
|
import (
|
||||||
"fmt"
|
"fmt"
|
||||||
"log"
|
"log"
|
||||||
|
"strings"
|
||||||
|
|
||||||
"google.golang.org/api/compute/v1"
|
"google.golang.org/api/compute/v1"
|
||||||
)
|
)
|
||||||
|
|
||||||
const FINGERPRINT_RETRIES = 10
|
const FINGERPRINT_RETRIES = 10
|
||||||
const FINGERPRINT_FAIL = "Invalid fingerprint."
|
|
||||||
|
var FINGERPRINT_FAIL_ERRORS = []string{"Invalid fingerprint.", "Supplied fingerprint does not match current metadata fingerprint."}
|
||||||
|
|
||||||
// Since the google compute API uses optimistic locking, there is a chance
|
// Since the google compute API uses optimistic locking, there is a chance
|
||||||
// we need to resubmit our updated metadata. To do this, you need to provide
|
// we need to resubmit our updated metadata. To do this, you need to provide
|
||||||
|
@ -17,11 +19,25 @@ func MetadataRetryWrapper(update func() error) error {
|
||||||
attempt := 0
|
attempt := 0
|
||||||
for attempt < FINGERPRINT_RETRIES {
|
for attempt < FINGERPRINT_RETRIES {
|
||||||
err := update()
|
err := update()
|
||||||
if err != nil && err.Error() == FINGERPRINT_FAIL {
|
if err == nil {
|
||||||
attempt++
|
return nil
|
||||||
} else {
|
}
|
||||||
|
|
||||||
|
// Check to see if the error matches any of our fingerprint-related failure messages
|
||||||
|
var fingerprintError bool
|
||||||
|
for _, msg := range FINGERPRINT_FAIL_ERRORS {
|
||||||
|
if strings.Contains(err.Error(), msg) {
|
||||||
|
fingerprintError = true
|
||||||
|
break
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if !fingerprintError {
|
||||||
|
// Something else went wrong, don't retry
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
|
||||||
|
attempt++
|
||||||
}
|
}
|
||||||
|
|
||||||
return fmt.Errorf("Failed to update metadata after %d retries", attempt)
|
return fmt.Errorf("Failed to update metadata after %d retries", attempt)
|
||||||
|
|
Loading…
Reference in New Issue
Block a user