mirror of
https://github.com/letic/terraform-provider-google.git
synced 2024-10-06 18:51:13 +00:00
Merge pull request #1524 from terraform-providers/paddy_eventual_services
Guard against eventually consistent services
This commit is contained in:
commit
23acaf2dd3
@ -6,6 +6,7 @@ import (
|
|||||||
"strings"
|
"strings"
|
||||||
|
|
||||||
"github.com/hashicorp/terraform/helper/schema"
|
"github.com/hashicorp/terraform/helper/schema"
|
||||||
|
"google.golang.org/api/googleapi"
|
||||||
"google.golang.org/api/serviceusage/v1beta1"
|
"google.golang.org/api/serviceusage/v1beta1"
|
||||||
)
|
)
|
||||||
|
|
||||||
@ -227,6 +228,30 @@ func enableServices(s []string, pid string, config *Config) error {
|
|||||||
if waitErr != nil {
|
if waitErr != nil {
|
||||||
return waitErr
|
return waitErr
|
||||||
}
|
}
|
||||||
|
services, err := getApiServices(pid, config, map[string]struct{}{})
|
||||||
|
if err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
var missing []string
|
||||||
|
for _, toEnable := range s {
|
||||||
|
var found bool
|
||||||
|
for _, service := range services {
|
||||||
|
if service == toEnable {
|
||||||
|
found = true
|
||||||
|
break
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if !found {
|
||||||
|
missing = append(missing, toEnable)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if len(missing) > 0 {
|
||||||
|
// spoof a googleapi Error so retryTime will try again
|
||||||
|
return &googleapi.Error{
|
||||||
|
Code: 503, // haha, get it, service unavailable
|
||||||
|
Message: fmt.Sprintf("The services %s are still being enabled for project %q. This isn't a real API error, this is just eventual consistency.", strings.Join(missing, ", "), pid),
|
||||||
|
}
|
||||||
|
}
|
||||||
return nil
|
return nil
|
||||||
}, 10)
|
}, 10)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
|
Loading…
Reference in New Issue
Block a user