diff --git a/google/config.go b/google/config.go index ddfdc9f0..2e57c312 100644 --- a/google/config.go +++ b/google/config.go @@ -5,6 +5,7 @@ import ( "fmt" "log" "net/http" + "time" "github.com/hashicorp/terraform/helper/logging" "github.com/hashicorp/terraform/helper/pathorcontents" @@ -114,6 +115,10 @@ func (c *Config) loadAndValidate() error { client := oauth2.NewClient(context.Background(), tokenSource) client.Transport = logging.NewTransport("Google", client.Transport) + // Each individual request should return within 30s - timeouts will be retried. + // This is a timeout for, e.g. a single GET request of an operation - not a + // timeout for the maximum amount of time a logical request can take. + client.Timeout, _ = time.ParseDuration("30s") terraformVersion := httpclient.UserAgentString() providerVersion := fmt.Sprintf("terraform-provider-google/%s", version.ProviderVersion) diff --git a/google/utils.go b/google/utils.go index 67883350..68dfb8ef 100644 --- a/google/utils.go +++ b/google/utils.go @@ -7,6 +7,7 @@ import ( "encoding/hex" "fmt" "log" + "net/url" "strings" "time" @@ -343,6 +344,11 @@ func isRetryableError(err error) bool { if gerr, ok := err.(*googleapi.Error); ok && (gerr.Code == 409 || gerr.Code == 429 || gerr.Code == 500 || gerr.Code == 502 || gerr.Code == 503) { return true } + // These operations are always hitting googleapis.com - they should rarely + // time out, and if they do, that timeout is retryable. + if urlerr, ok := err.(*url.Error); ok && urlerr.Timeout() { + return true + } return false }