-
Notifications
You must be signed in to change notification settings - Fork 50
/
Copy pathretry_policies.go
55 lines (39 loc) · 2 KB
/
retry_policies.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
// Copyright (c) HashiCorp, Inc.
// SPDX-License-Identifier: MPL-2.0
package resourcemanager
import (
"fmt"
"net/http"
"strings"
"github.com/hashicorp/go-azure-sdk/sdk/client"
"github.com/hashicorp/go-azure-sdk/sdk/internal/stringfmt"
"github.com/hashicorp/go-azure-sdk/sdk/odata"
)
// TODO: return a typed error here so that we could potentially change this error/expose this in the Provider
// TODO: the error should return the default error message shown below
var defaultRetryFunctions = []client.RequestRetryFunc{
// NOTE: 429 is handled by the base library
handleResourceProviderNotRegistered,
}
func handleResourceProviderNotRegistered(r *http.Response, o *odata.OData) (bool, error) {
if o != nil && o.Error != nil && o.Error.Code != nil && strings.EqualFold(*o.Error.Code, "MissingSubscriptionRegistration") {
return false, resourceProviderNotRegisteredError(*o.Error.Message)
}
return false, nil
}
func resourceProviderNotRegisteredError(message string) error {
messageSplit := stringfmt.QuoteAndSplitString(">", message, 100)
return fmt.Errorf(`The Resource Provider was not registered
Resource Providers (APIs) in Azure need to be registered before they can be used - however the Resource
Provider was not registered, and calling the API returned the following error:
%[1]s
The Azure Provider by default will automatically register certain Resource Providers at launch-time,
whilst it's possible to opt-out of this (which you may have done)
Please ensure that this Resource Provider is properly registered, you can do this using the Azure CLI
for example to register the Resource Provider "Some.ResourceProvider" is registered run:
> az provider register --namespace "Some.ResourceProvider"
Resource Providers can take a while to register, you can check the status by running:
> az provider show --namespace "Some.ResourceProvider" --query "registrationState"
Once this outputs "Registered" the Resource Provider is available for use and you can re-run Terraform.
`, strings.Join(messageSplit, "\n"))
}