provider/azurerm: Register needed Azure providers
This commit is contained in:
parent
5c6304ed57
commit
a48e713fe0
|
@ -36,6 +36,7 @@ type ArmClient struct {
|
||||||
vnetGatewayClient network.VirtualNetworkGatewaysClient
|
vnetGatewayClient network.VirtualNetworkGatewaysClient
|
||||||
vnetClient network.VirtualNetworksClient
|
vnetClient network.VirtualNetworksClient
|
||||||
|
|
||||||
|
providers resources.ProvidersClient
|
||||||
resourceGroupClient resources.GroupsClient
|
resourceGroupClient resources.GroupsClient
|
||||||
tagsClient resources.TagsClient
|
tagsClient resources.TagsClient
|
||||||
|
|
||||||
|
@ -160,6 +161,11 @@ func (c *Config) getArmClient() (*ArmClient, error) {
|
||||||
rgc.Sender = autorest.CreateSender(withRequestLogging())
|
rgc.Sender = autorest.CreateSender(withRequestLogging())
|
||||||
client.resourceGroupClient = rgc
|
client.resourceGroupClient = rgc
|
||||||
|
|
||||||
|
pc := resources.NewProvidersClient(c.SubscriptionID)
|
||||||
|
pc.Authorizer = spt
|
||||||
|
pc.Sender = autorest.CreateSender(withRequestLogging())
|
||||||
|
client.providers = pc
|
||||||
|
|
||||||
tc := resources.NewTagsClient(c.SubscriptionID)
|
tc := resources.NewTagsClient(c.SubscriptionID)
|
||||||
tc.Authorizer = spt
|
tc.Authorizer = spt
|
||||||
tc.Sender = autorest.CreateSender(withRequestLogging())
|
tc.Sender = autorest.CreateSender(withRequestLogging())
|
||||||
|
|
|
@ -1,6 +1,8 @@
|
||||||
package azurerm
|
package azurerm
|
||||||
|
|
||||||
import (
|
import (
|
||||||
|
"fmt"
|
||||||
|
"net/http"
|
||||||
"strings"
|
"strings"
|
||||||
|
|
||||||
"github.com/hashicorp/terraform/helper/schema"
|
"github.com/hashicorp/terraform/helper/schema"
|
||||||
|
@ -70,9 +72,37 @@ func providerConfigure(d *schema.ResourceData) (interface{}, error) {
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
|
|
||||||
|
err = registerAzureResourceProvidersWithSubscription(&config, client)
|
||||||
|
if err != nil {
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
|
|
||||||
return client, nil
|
return client, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// registerAzureResourceProvidersWithSubscription uses the providers client to register
|
||||||
|
// all Azure resource providers which the Terraform provider may require (regardless of
|
||||||
|
// whether they are actually used by the configuration or not). It was confirmed by Microsoft
|
||||||
|
// that this is the approach their own internal tools also take.
|
||||||
|
func registerAzureResourceProvidersWithSubscription(config *Config, client *ArmClient) error {
|
||||||
|
providerClient := client.providers
|
||||||
|
|
||||||
|
providers := []string{"Microsoft.Network"}
|
||||||
|
|
||||||
|
for _, v := range providers {
|
||||||
|
res, err := providerClient.Register(v)
|
||||||
|
if err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
|
||||||
|
if res.StatusCode != http.StatusOK {
|
||||||
|
return fmt.Errorf("Error registering provider %q with subscription %q", v, config.SubscriptionID)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
|
||||||
func azureRMNormalizeLocation(location interface{}) string {
|
func azureRMNormalizeLocation(location interface{}) string {
|
||||||
input := location.(string)
|
input := location.(string)
|
||||||
return strings.Replace(strings.ToLower(input), " ", "", -1)
|
return strings.Replace(strings.ToLower(input), " ", "", -1)
|
||||||
|
|
Loading…
Reference in New Issue