2015-12-08 23:30:12 +01:00
|
|
|
package azurerm
|
|
|
|
|
|
|
|
import (
|
2016-10-25 20:29:24 +02:00
|
|
|
"context"
|
2016-01-06 23:07:15 +01:00
|
|
|
"fmt"
|
2015-12-09 02:25:05 +01:00
|
|
|
"log"
|
|
|
|
"net/http"
|
2016-07-20 21:02:40 +02:00
|
|
|
"net/http/httputil"
|
2015-12-08 23:30:12 +01:00
|
|
|
|
2016-01-19 11:11:37 +01:00
|
|
|
"github.com/Azure/azure-sdk-for-go/arm/cdn"
|
2017-03-02 02:10:27 +01:00
|
|
|
"github.com/Azure/azure-sdk-for-go/arm/compute"
|
2017-01-02 15:37:45 +01:00
|
|
|
"github.com/Azure/azure-sdk-for-go/arm/containerregistry"
|
2017-02-13 17:33:50 +01:00
|
|
|
"github.com/Azure/azure-sdk-for-go/arm/containerservice"
|
2017-03-03 23:31:40 +01:00
|
|
|
"github.com/Azure/azure-sdk-for-go/arm/disk"
|
2016-10-25 16:50:07 +02:00
|
|
|
"github.com/Azure/azure-sdk-for-go/arm/eventhub"
|
2016-10-20 12:30:30 +02:00
|
|
|
"github.com/Azure/azure-sdk-for-go/arm/keyvault"
|
2015-12-08 23:30:12 +01:00
|
|
|
"github.com/Azure/azure-sdk-for-go/arm/network"
|
2016-12-18 15:23:29 +01:00
|
|
|
"github.com/Azure/azure-sdk-for-go/arm/redis"
|
2016-01-08 21:06:09 +01:00
|
|
|
"github.com/Azure/azure-sdk-for-go/arm/resources/resources"
|
2015-12-08 23:30:12 +01:00
|
|
|
"github.com/Azure/azure-sdk-for-go/arm/scheduler"
|
2016-08-15 19:00:00 +02:00
|
|
|
"github.com/Azure/azure-sdk-for-go/arm/servicebus"
|
2015-12-08 23:30:12 +01:00
|
|
|
"github.com/Azure/azure-sdk-for-go/arm/storage"
|
2016-08-01 00:46:15 +02:00
|
|
|
"github.com/Azure/azure-sdk-for-go/arm/trafficmanager"
|
2016-01-26 21:45:18 +01:00
|
|
|
mainStorage "github.com/Azure/azure-sdk-for-go/storage"
|
2016-06-01 22:17:21 +02:00
|
|
|
"github.com/Azure/go-autorest/autorest"
|
|
|
|
"github.com/Azure/go-autorest/autorest/azure"
|
2016-01-06 23:07:15 +01:00
|
|
|
"github.com/hashicorp/terraform/terraform"
|
2016-02-03 01:48:09 +01:00
|
|
|
riviera "github.com/jen20/riviera/azure"
|
2015-12-08 23:30:12 +01:00
|
|
|
)
|
|
|
|
|
|
|
|
// ArmClient contains the handles to all the specific Azure Resource Manager
|
|
|
|
// resource classes' respective clients.
|
|
|
|
type ArmClient struct {
|
2016-10-20 12:29:26 +02:00
|
|
|
clientId string
|
|
|
|
tenantId string
|
|
|
|
subscriptionId string
|
2017-01-17 17:28:24 +01:00
|
|
|
environment azure.Environment
|
2016-10-20 12:29:26 +02:00
|
|
|
|
2016-10-25 20:29:24 +02:00
|
|
|
StopContext context.Context
|
2016-10-24 03:26:06 +02:00
|
|
|
|
2016-02-03 01:48:09 +01:00
|
|
|
rivieraClient *riviera.Client
|
|
|
|
|
2015-12-08 23:30:12 +01:00
|
|
|
availSetClient compute.AvailabilitySetsClient
|
2017-02-23 17:14:55 +01:00
|
|
|
usageOpsClient compute.UsageClient
|
2015-12-08 23:30:12 +01:00
|
|
|
vmExtensionImageClient compute.VirtualMachineExtensionImagesClient
|
|
|
|
vmExtensionClient compute.VirtualMachineExtensionsClient
|
2016-06-11 00:37:14 +02:00
|
|
|
vmScaleSetClient compute.VirtualMachineScaleSetsClient
|
2015-12-08 23:30:12 +01:00
|
|
|
vmImageClient compute.VirtualMachineImagesClient
|
|
|
|
vmClient compute.VirtualMachinesClient
|
|
|
|
|
2017-03-03 21:12:00 +01:00
|
|
|
diskClient disk.DisksClient
|
|
|
|
|
2015-12-08 23:30:12 +01:00
|
|
|
appGatewayClient network.ApplicationGatewaysClient
|
|
|
|
ifaceClient network.InterfacesClient
|
|
|
|
loadBalancerClient network.LoadBalancersClient
|
|
|
|
localNetConnClient network.LocalNetworkGatewaysClient
|
|
|
|
publicIPClient network.PublicIPAddressesClient
|
|
|
|
secGroupClient network.SecurityGroupsClient
|
|
|
|
secRuleClient network.SecurityRulesClient
|
|
|
|
subnetClient network.SubnetsClient
|
|
|
|
netUsageClient network.UsagesClient
|
|
|
|
vnetGatewayConnectionsClient network.VirtualNetworkGatewayConnectionsClient
|
|
|
|
vnetGatewayClient network.VirtualNetworkGatewaysClient
|
|
|
|
vnetClient network.VirtualNetworksClient
|
2016-08-13 20:37:46 +02:00
|
|
|
vnetPeeringsClient network.VirtualNetworkPeeringsClient
|
2016-01-10 02:35:58 +01:00
|
|
|
routeTablesClient network.RouteTablesClient
|
2016-01-10 16:02:48 +01:00
|
|
|
routesClient network.RoutesClient
|
2015-12-08 23:30:12 +01:00
|
|
|
|
2016-01-19 19:08:56 +01:00
|
|
|
cdnProfilesClient cdn.ProfilesClient
|
|
|
|
cdnEndpointsClient cdn.EndpointsClient
|
2016-01-19 11:11:37 +01:00
|
|
|
|
2017-01-02 15:37:45 +01:00
|
|
|
containerRegistryClient containerregistry.RegistriesClient
|
2017-02-13 17:33:50 +01:00
|
|
|
containerServicesClient containerservice.ContainerServicesClient
|
2017-01-02 15:37:45 +01:00
|
|
|
|
2016-12-29 00:12:47 +01:00
|
|
|
eventHubClient eventhub.EventHubsClient
|
|
|
|
eventHubConsumerGroupClient eventhub.ConsumerGroupsClient
|
|
|
|
eventHubNamespacesClient eventhub.NamespacesClient
|
2016-10-25 16:50:07 +02:00
|
|
|
|
2016-01-05 22:43:52 +01:00
|
|
|
providers resources.ProvidersClient
|
2015-12-08 23:30:12 +01:00
|
|
|
resourceGroupClient resources.GroupsClient
|
|
|
|
tagsClient resources.TagsClient
|
2017-02-23 17:14:55 +01:00
|
|
|
resourceFindClient resources.GroupClient
|
2015-12-08 23:30:12 +01:00
|
|
|
|
|
|
|
jobsClient scheduler.JobsClient
|
|
|
|
jobsCollectionsClient scheduler.JobCollectionsClient
|
|
|
|
|
|
|
|
storageServiceClient storage.AccountsClient
|
|
|
|
storageUsageClient storage.UsageOperationsClient
|
2016-03-21 16:49:48 +01:00
|
|
|
|
|
|
|
deploymentsClient resources.DeploymentsClient
|
2016-08-01 00:46:15 +02:00
|
|
|
|
2017-02-23 17:14:55 +01:00
|
|
|
redisClient redis.GroupClient
|
2016-12-18 15:23:29 +01:00
|
|
|
|
2016-08-01 00:46:15 +02:00
|
|
|
trafficManagerProfilesClient trafficmanager.ProfilesClient
|
|
|
|
trafficManagerEndpointsClient trafficmanager.EndpointsClient
|
2016-08-15 19:00:00 +02:00
|
|
|
|
2016-10-03 12:22:18 +02:00
|
|
|
serviceBusNamespacesClient servicebus.NamespacesClient
|
|
|
|
serviceBusTopicsClient servicebus.TopicsClient
|
|
|
|
serviceBusSubscriptionsClient servicebus.SubscriptionsClient
|
2016-10-20 12:30:30 +02:00
|
|
|
|
|
|
|
keyVaultClient keyvault.VaultsClient
|
2015-12-08 23:30:12 +01:00
|
|
|
}
|
|
|
|
|
2015-12-09 02:25:05 +01:00
|
|
|
func withRequestLogging() autorest.SendDecorator {
|
|
|
|
return func(s autorest.Sender) autorest.Sender {
|
|
|
|
return autorest.SenderFunc(func(r *http.Request) (*http.Response, error) {
|
2016-07-20 21:02:40 +02:00
|
|
|
// dump request to wire format
|
|
|
|
if dump, err := httputil.DumpRequestOut(r, true); err == nil {
|
|
|
|
log.Printf("[DEBUG] AzureRM Request: \n%s\n", dump)
|
|
|
|
} else {
|
|
|
|
// fallback to basic message
|
|
|
|
log.Printf("[DEBUG] AzureRM Request: %s to %s\n", r.Method, r.URL)
|
|
|
|
}
|
|
|
|
|
2015-12-09 02:25:05 +01:00
|
|
|
resp, err := s.Do(r)
|
2016-01-18 17:32:39 +01:00
|
|
|
if resp != nil {
|
2016-07-20 21:02:40 +02:00
|
|
|
// dump response to wire format
|
|
|
|
if dump, err := httputil.DumpResponse(resp, true); err == nil {
|
|
|
|
log.Printf("[DEBUG] AzureRM Response for %s: \n%s\n", r.URL, dump)
|
|
|
|
} else {
|
|
|
|
// fallback to basic message
|
|
|
|
log.Printf("[DEBUG] AzureRM Response: %s for %s\n", resp.Status, r.URL)
|
|
|
|
}
|
2016-01-18 17:32:39 +01:00
|
|
|
} else {
|
|
|
|
log.Printf("[DEBUG] Request to %s completed with no response", r.URL)
|
|
|
|
}
|
2015-12-09 02:25:05 +01:00
|
|
|
return resp, err
|
|
|
|
})
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2016-01-06 23:07:15 +01:00
|
|
|
func setUserAgent(client *autorest.Client) {
|
2016-07-21 20:07:16 +02:00
|
|
|
version := terraform.VersionString()
|
2016-01-06 23:07:15 +01:00
|
|
|
client.UserAgent = fmt.Sprintf("HashiCorp-Terraform-v%s", version)
|
|
|
|
}
|
|
|
|
|
2015-12-08 23:30:12 +01:00
|
|
|
// getArmClient is a helper method which returns a fully instantiated
|
|
|
|
// *ArmClient based on the Config's current settings.
|
|
|
|
func (c *Config) getArmClient() (*ArmClient, error) {
|
2017-01-04 13:00:14 +01:00
|
|
|
// detect cloud from environment
|
|
|
|
env, envErr := azure.EnvironmentFromName(c.Environment)
|
|
|
|
if envErr != nil {
|
|
|
|
// try again with wrapped value to support readable values like german instead of AZUREGERMANCLOUD
|
|
|
|
wrapped := fmt.Sprintf("AZURE%sCLOUD", c.Environment)
|
|
|
|
var innerErr error
|
|
|
|
if env, innerErr = azure.EnvironmentFromName(wrapped); innerErr != nil {
|
|
|
|
return nil, envErr
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2017-01-17 17:28:24 +01:00
|
|
|
// client declarations:
|
|
|
|
client := ArmClient{
|
|
|
|
clientId: c.ClientID,
|
|
|
|
tenantId: c.TenantID,
|
|
|
|
subscriptionId: c.SubscriptionID,
|
|
|
|
environment: env,
|
|
|
|
}
|
|
|
|
|
2016-02-03 01:48:09 +01:00
|
|
|
rivieraClient, err := riviera.NewClient(&riviera.AzureResourceManagerCredentials{
|
2017-01-04 13:00:14 +01:00
|
|
|
ClientID: c.ClientID,
|
|
|
|
ClientSecret: c.ClientSecret,
|
|
|
|
TenantID: c.TenantID,
|
|
|
|
SubscriptionID: c.SubscriptionID,
|
|
|
|
ResourceManagerEndpoint: env.ResourceManagerEndpoint,
|
|
|
|
ActiveDirectoryEndpoint: env.ActiveDirectoryEndpoint,
|
2016-02-03 01:48:09 +01:00
|
|
|
})
|
|
|
|
if err != nil {
|
|
|
|
return nil, fmt.Errorf("Error creating Riviera client: %s", err)
|
|
|
|
}
|
|
|
|
client.rivieraClient = rivieraClient
|
|
|
|
|
2017-01-04 13:00:14 +01:00
|
|
|
oauthConfig, err := env.OAuthConfigForTenant(c.TenantID)
|
2016-06-01 22:17:21 +02:00
|
|
|
if err != nil {
|
|
|
|
return nil, err
|
|
|
|
}
|
|
|
|
|
2016-09-05 22:02:27 +02:00
|
|
|
// OAuthConfigForTenant returns a pointer, which can be nil.
|
2016-06-01 22:17:21 +02:00
|
|
|
if oauthConfig == nil {
|
|
|
|
return nil, fmt.Errorf("Unable to configure OAuthConfig for tenant %s", c.TenantID)
|
|
|
|
}
|
|
|
|
|
2017-01-04 13:00:14 +01:00
|
|
|
spt, err := azure.NewServicePrincipalToken(*oauthConfig, c.ClientID, c.ClientSecret, env.ResourceManagerEndpoint)
|
2016-04-22 01:50:47 +02:00
|
|
|
if err != nil {
|
|
|
|
return nil, err
|
|
|
|
}
|
|
|
|
|
2017-01-04 13:00:14 +01:00
|
|
|
endpoint := env.ResourceManagerEndpoint
|
|
|
|
|
2015-12-08 23:30:12 +01:00
|
|
|
// NOTE: these declarations should be left separate for clarity should the
|
|
|
|
// clients be wished to be configured with custom Responders/PollingModess etc...
|
2017-01-04 13:00:14 +01:00
|
|
|
asc := compute.NewAvailabilitySetsClientWithBaseURI(endpoint, c.SubscriptionID)
|
2016-01-06 23:07:15 +01:00
|
|
|
setUserAgent(&asc.Client)
|
2015-12-08 23:30:12 +01:00
|
|
|
asc.Authorizer = spt
|
2015-12-09 02:25:05 +01:00
|
|
|
asc.Sender = autorest.CreateSender(withRequestLogging())
|
2015-12-08 23:30:12 +01:00
|
|
|
client.availSetClient = asc
|
|
|
|
|
2017-02-23 17:14:55 +01:00
|
|
|
uoc := compute.NewUsageClientWithBaseURI(endpoint, c.SubscriptionID)
|
2016-01-06 23:07:15 +01:00
|
|
|
setUserAgent(&uoc.Client)
|
2015-12-08 23:30:12 +01:00
|
|
|
uoc.Authorizer = spt
|
2015-12-09 02:25:05 +01:00
|
|
|
uoc.Sender = autorest.CreateSender(withRequestLogging())
|
2015-12-08 23:30:12 +01:00
|
|
|
client.usageOpsClient = uoc
|
|
|
|
|
2017-01-04 13:00:14 +01:00
|
|
|
vmeic := compute.NewVirtualMachineExtensionImagesClientWithBaseURI(endpoint, c.SubscriptionID)
|
2016-01-06 23:07:15 +01:00
|
|
|
setUserAgent(&vmeic.Client)
|
2015-12-08 23:30:12 +01:00
|
|
|
vmeic.Authorizer = spt
|
2015-12-09 02:25:05 +01:00
|
|
|
vmeic.Sender = autorest.CreateSender(withRequestLogging())
|
2015-12-08 23:30:12 +01:00
|
|
|
client.vmExtensionImageClient = vmeic
|
|
|
|
|
2017-01-04 13:00:14 +01:00
|
|
|
vmec := compute.NewVirtualMachineExtensionsClientWithBaseURI(endpoint, c.SubscriptionID)
|
2016-01-06 23:07:15 +01:00
|
|
|
setUserAgent(&vmec.Client)
|
2015-12-08 23:30:12 +01:00
|
|
|
vmec.Authorizer = spt
|
2015-12-09 02:25:05 +01:00
|
|
|
vmec.Sender = autorest.CreateSender(withRequestLogging())
|
2015-12-08 23:30:12 +01:00
|
|
|
client.vmExtensionClient = vmec
|
|
|
|
|
2017-01-04 13:00:14 +01:00
|
|
|
vmic := compute.NewVirtualMachineImagesClientWithBaseURI(endpoint, c.SubscriptionID)
|
2016-01-06 23:07:15 +01:00
|
|
|
setUserAgent(&vmic.Client)
|
2015-12-08 23:30:12 +01:00
|
|
|
vmic.Authorizer = spt
|
2015-12-09 02:25:05 +01:00
|
|
|
vmic.Sender = autorest.CreateSender(withRequestLogging())
|
2015-12-08 23:30:12 +01:00
|
|
|
client.vmImageClient = vmic
|
|
|
|
|
2017-01-04 13:00:14 +01:00
|
|
|
vmssc := compute.NewVirtualMachineScaleSetsClientWithBaseURI(endpoint, c.SubscriptionID)
|
2016-06-11 00:37:14 +02:00
|
|
|
setUserAgent(&vmssc.Client)
|
|
|
|
vmssc.Authorizer = spt
|
|
|
|
vmssc.Sender = autorest.CreateSender(withRequestLogging())
|
|
|
|
client.vmScaleSetClient = vmssc
|
|
|
|
|
2017-01-04 13:00:14 +01:00
|
|
|
vmc := compute.NewVirtualMachinesClientWithBaseURI(endpoint, c.SubscriptionID)
|
2016-01-06 23:07:15 +01:00
|
|
|
setUserAgent(&vmc.Client)
|
2015-12-08 23:30:12 +01:00
|
|
|
vmc.Authorizer = spt
|
2015-12-09 02:25:05 +01:00
|
|
|
vmc.Sender = autorest.CreateSender(withRequestLogging())
|
2015-12-08 23:30:12 +01:00
|
|
|
client.vmClient = vmc
|
|
|
|
|
2017-01-04 13:00:14 +01:00
|
|
|
agc := network.NewApplicationGatewaysClientWithBaseURI(endpoint, c.SubscriptionID)
|
2016-01-06 23:07:15 +01:00
|
|
|
setUserAgent(&agc.Client)
|
2015-12-08 23:30:12 +01:00
|
|
|
agc.Authorizer = spt
|
2015-12-09 02:25:05 +01:00
|
|
|
agc.Sender = autorest.CreateSender(withRequestLogging())
|
2015-12-08 23:30:12 +01:00
|
|
|
client.appGatewayClient = agc
|
|
|
|
|
2017-01-04 13:00:14 +01:00
|
|
|
crc := containerregistry.NewRegistriesClientWithBaseURI(endpoint, c.SubscriptionID)
|
2017-01-02 15:37:45 +01:00
|
|
|
setUserAgent(&crc.Client)
|
|
|
|
crc.Authorizer = spt
|
|
|
|
crc.Sender = autorest.CreateSender(withRequestLogging())
|
|
|
|
client.containerRegistryClient = crc
|
|
|
|
|
2017-02-13 17:33:50 +01:00
|
|
|
csc := containerservice.NewContainerServicesClientWithBaseURI(endpoint, c.SubscriptionID)
|
|
|
|
setUserAgent(&csc.Client)
|
|
|
|
csc.Authorizer = spt
|
|
|
|
csc.Sender = autorest.CreateSender(withRequestLogging())
|
|
|
|
client.containerServicesClient = csc
|
|
|
|
|
2017-03-03 23:31:40 +01:00
|
|
|
dkc := disk.NewDisksClientWithBaseURI(endpoint, c.SubscriptionID)
|
|
|
|
setUserAgent(&dkc.Client)
|
|
|
|
dkc.Authorizer = spt
|
|
|
|
dkc.Sender = autorest.CreateSender(withRequestLogging())
|
|
|
|
client.diskClient = dkc
|
|
|
|
|
2017-01-04 13:00:14 +01:00
|
|
|
ehc := eventhub.NewEventHubsClientWithBaseURI(endpoint, c.SubscriptionID)
|
2016-11-07 11:19:59 +01:00
|
|
|
setUserAgent(&ehc.Client)
|
|
|
|
ehc.Authorizer = spt
|
|
|
|
ehc.Sender = autorest.CreateSender(withRequestLogging())
|
|
|
|
client.eventHubClient = ehc
|
|
|
|
|
2017-01-04 13:00:14 +01:00
|
|
|
chcgc := eventhub.NewConsumerGroupsClientWithBaseURI(endpoint, c.SubscriptionID)
|
2016-12-29 00:12:47 +01:00
|
|
|
setUserAgent(&chcgc.Client)
|
|
|
|
chcgc.Authorizer = spt
|
|
|
|
chcgc.Sender = autorest.CreateSender(withRequestLogging())
|
|
|
|
client.eventHubConsumerGroupClient = chcgc
|
|
|
|
|
2017-01-04 13:00:14 +01:00
|
|
|
ehnc := eventhub.NewNamespacesClientWithBaseURI(endpoint, c.SubscriptionID)
|
2016-10-25 16:50:07 +02:00
|
|
|
setUserAgent(&ehnc.Client)
|
|
|
|
ehnc.Authorizer = spt
|
|
|
|
ehnc.Sender = autorest.CreateSender(withRequestLogging())
|
|
|
|
client.eventHubNamespacesClient = ehnc
|
|
|
|
|
2017-01-04 13:00:14 +01:00
|
|
|
ifc := network.NewInterfacesClientWithBaseURI(endpoint, c.SubscriptionID)
|
2016-01-06 23:07:15 +01:00
|
|
|
setUserAgent(&ifc.Client)
|
2015-12-08 23:30:12 +01:00
|
|
|
ifc.Authorizer = spt
|
2015-12-09 02:25:05 +01:00
|
|
|
ifc.Sender = autorest.CreateSender(withRequestLogging())
|
2015-12-08 23:30:12 +01:00
|
|
|
client.ifaceClient = ifc
|
|
|
|
|
2017-01-04 13:00:14 +01:00
|
|
|
lbc := network.NewLoadBalancersClientWithBaseURI(endpoint, c.SubscriptionID)
|
2016-01-06 23:07:15 +01:00
|
|
|
setUserAgent(&lbc.Client)
|
2015-12-08 23:30:12 +01:00
|
|
|
lbc.Authorizer = spt
|
2015-12-09 02:25:05 +01:00
|
|
|
lbc.Sender = autorest.CreateSender(withRequestLogging())
|
2015-12-08 23:30:12 +01:00
|
|
|
client.loadBalancerClient = lbc
|
|
|
|
|
2017-01-04 13:00:14 +01:00
|
|
|
lgc := network.NewLocalNetworkGatewaysClientWithBaseURI(endpoint, c.SubscriptionID)
|
2016-01-06 23:07:15 +01:00
|
|
|
setUserAgent(&lgc.Client)
|
2015-12-08 23:30:12 +01:00
|
|
|
lgc.Authorizer = spt
|
2015-12-09 02:25:05 +01:00
|
|
|
lgc.Sender = autorest.CreateSender(withRequestLogging())
|
2015-12-08 23:30:12 +01:00
|
|
|
client.localNetConnClient = lgc
|
|
|
|
|
2017-01-04 13:00:14 +01:00
|
|
|
pipc := network.NewPublicIPAddressesClientWithBaseURI(endpoint, c.SubscriptionID)
|
2016-01-06 23:07:15 +01:00
|
|
|
setUserAgent(&pipc.Client)
|
2015-12-08 23:30:12 +01:00
|
|
|
pipc.Authorizer = spt
|
2015-12-09 02:25:05 +01:00
|
|
|
pipc.Sender = autorest.CreateSender(withRequestLogging())
|
2015-12-08 23:30:12 +01:00
|
|
|
client.publicIPClient = pipc
|
|
|
|
|
2017-01-04 13:00:14 +01:00
|
|
|
sgc := network.NewSecurityGroupsClientWithBaseURI(endpoint, c.SubscriptionID)
|
2016-01-06 23:07:15 +01:00
|
|
|
setUserAgent(&sgc.Client)
|
2015-12-08 23:30:12 +01:00
|
|
|
sgc.Authorizer = spt
|
2015-12-09 02:25:05 +01:00
|
|
|
sgc.Sender = autorest.CreateSender(withRequestLogging())
|
2015-12-08 23:30:12 +01:00
|
|
|
client.secGroupClient = sgc
|
|
|
|
|
2017-01-04 13:00:14 +01:00
|
|
|
src := network.NewSecurityRulesClientWithBaseURI(endpoint, c.SubscriptionID)
|
2016-01-06 23:07:15 +01:00
|
|
|
setUserAgent(&src.Client)
|
2015-12-08 23:30:12 +01:00
|
|
|
src.Authorizer = spt
|
2015-12-09 02:25:05 +01:00
|
|
|
src.Sender = autorest.CreateSender(withRequestLogging())
|
2015-12-08 23:30:12 +01:00
|
|
|
client.secRuleClient = src
|
|
|
|
|
2017-01-04 13:00:14 +01:00
|
|
|
snc := network.NewSubnetsClientWithBaseURI(endpoint, c.SubscriptionID)
|
2016-01-06 23:07:15 +01:00
|
|
|
setUserAgent(&snc.Client)
|
2015-12-08 23:30:12 +01:00
|
|
|
snc.Authorizer = spt
|
2015-12-09 02:25:05 +01:00
|
|
|
snc.Sender = autorest.CreateSender(withRequestLogging())
|
2015-12-08 23:30:12 +01:00
|
|
|
client.subnetClient = snc
|
|
|
|
|
2017-01-04 13:00:14 +01:00
|
|
|
vgcc := network.NewVirtualNetworkGatewayConnectionsClientWithBaseURI(endpoint, c.SubscriptionID)
|
2016-01-06 23:07:15 +01:00
|
|
|
setUserAgent(&vgcc.Client)
|
2015-12-08 23:30:12 +01:00
|
|
|
vgcc.Authorizer = spt
|
2015-12-09 02:25:05 +01:00
|
|
|
vgcc.Sender = autorest.CreateSender(withRequestLogging())
|
2015-12-08 23:30:12 +01:00
|
|
|
client.vnetGatewayConnectionsClient = vgcc
|
|
|
|
|
2017-01-04 13:00:14 +01:00
|
|
|
vgc := network.NewVirtualNetworkGatewaysClientWithBaseURI(endpoint, c.SubscriptionID)
|
2016-01-06 23:07:15 +01:00
|
|
|
setUserAgent(&vgc.Client)
|
2015-12-08 23:30:12 +01:00
|
|
|
vgc.Authorizer = spt
|
2015-12-09 02:25:05 +01:00
|
|
|
vgc.Sender = autorest.CreateSender(withRequestLogging())
|
2015-12-08 23:30:12 +01:00
|
|
|
client.vnetGatewayClient = vgc
|
|
|
|
|
2017-01-04 13:00:14 +01:00
|
|
|
vnc := network.NewVirtualNetworksClientWithBaseURI(endpoint, c.SubscriptionID)
|
2016-01-06 23:07:15 +01:00
|
|
|
setUserAgent(&vnc.Client)
|
2015-12-08 23:30:12 +01:00
|
|
|
vnc.Authorizer = spt
|
2015-12-09 02:25:05 +01:00
|
|
|
vnc.Sender = autorest.CreateSender(withRequestLogging())
|
2015-12-08 23:30:12 +01:00
|
|
|
client.vnetClient = vnc
|
|
|
|
|
2017-01-04 13:00:14 +01:00
|
|
|
vnpc := network.NewVirtualNetworkPeeringsClientWithBaseURI(endpoint, c.SubscriptionID)
|
2016-08-13 20:37:46 +02:00
|
|
|
setUserAgent(&vnpc.Client)
|
|
|
|
vnpc.Authorizer = spt
|
|
|
|
vnpc.Sender = autorest.CreateSender(withRequestLogging())
|
|
|
|
client.vnetPeeringsClient = vnpc
|
|
|
|
|
2017-01-04 13:00:14 +01:00
|
|
|
rtc := network.NewRouteTablesClientWithBaseURI(endpoint, c.SubscriptionID)
|
2016-01-10 02:35:58 +01:00
|
|
|
setUserAgent(&rtc.Client)
|
|
|
|
rtc.Authorizer = spt
|
|
|
|
rtc.Sender = autorest.CreateSender(withRequestLogging())
|
|
|
|
client.routeTablesClient = rtc
|
|
|
|
|
2017-01-04 13:00:14 +01:00
|
|
|
rc := network.NewRoutesClientWithBaseURI(endpoint, c.SubscriptionID)
|
2016-01-10 16:02:48 +01:00
|
|
|
setUserAgent(&rc.Client)
|
|
|
|
rc.Authorizer = spt
|
|
|
|
rc.Sender = autorest.CreateSender(withRequestLogging())
|
|
|
|
client.routesClient = rc
|
|
|
|
|
2017-01-04 13:00:14 +01:00
|
|
|
rgc := resources.NewGroupsClientWithBaseURI(endpoint, c.SubscriptionID)
|
2016-01-06 23:07:15 +01:00
|
|
|
setUserAgent(&rgc.Client)
|
2015-12-08 23:30:12 +01:00
|
|
|
rgc.Authorizer = spt
|
2015-12-09 02:25:05 +01:00
|
|
|
rgc.Sender = autorest.CreateSender(withRequestLogging())
|
2015-12-08 23:30:12 +01:00
|
|
|
client.resourceGroupClient = rgc
|
|
|
|
|
2017-01-04 13:00:14 +01:00
|
|
|
pc := resources.NewProvidersClientWithBaseURI(endpoint, c.SubscriptionID)
|
2016-01-06 23:07:15 +01:00
|
|
|
setUserAgent(&pc.Client)
|
2016-01-05 22:43:52 +01:00
|
|
|
pc.Authorizer = spt
|
|
|
|
pc.Sender = autorest.CreateSender(withRequestLogging())
|
|
|
|
client.providers = pc
|
|
|
|
|
2017-01-04 13:00:14 +01:00
|
|
|
tc := resources.NewTagsClientWithBaseURI(endpoint, c.SubscriptionID)
|
2016-01-06 23:07:15 +01:00
|
|
|
setUserAgent(&tc.Client)
|
2015-12-08 23:30:12 +01:00
|
|
|
tc.Authorizer = spt
|
2015-12-09 02:25:05 +01:00
|
|
|
tc.Sender = autorest.CreateSender(withRequestLogging())
|
2015-12-08 23:30:12 +01:00
|
|
|
client.tagsClient = tc
|
|
|
|
|
2017-02-23 17:14:55 +01:00
|
|
|
rf := resources.NewGroupClientWithBaseURI(endpoint, c.SubscriptionID)
|
2016-10-27 17:42:47 +02:00
|
|
|
setUserAgent(&rf.Client)
|
|
|
|
rf.Authorizer = spt
|
|
|
|
rf.Sender = autorest.CreateSender(withRequestLogging())
|
|
|
|
client.resourceFindClient = rf
|
|
|
|
|
2017-01-04 13:00:14 +01:00
|
|
|
jc := scheduler.NewJobsClientWithBaseURI(endpoint, c.SubscriptionID)
|
2016-01-06 23:07:15 +01:00
|
|
|
setUserAgent(&jc.Client)
|
2015-12-08 23:30:12 +01:00
|
|
|
jc.Authorizer = spt
|
2015-12-09 02:25:05 +01:00
|
|
|
jc.Sender = autorest.CreateSender(withRequestLogging())
|
2015-12-08 23:30:12 +01:00
|
|
|
client.jobsClient = jc
|
|
|
|
|
2017-01-04 13:00:14 +01:00
|
|
|
jcc := scheduler.NewJobCollectionsClientWithBaseURI(endpoint, c.SubscriptionID)
|
2016-01-06 23:07:15 +01:00
|
|
|
setUserAgent(&jcc.Client)
|
2015-12-08 23:30:12 +01:00
|
|
|
jcc.Authorizer = spt
|
2015-12-09 02:25:05 +01:00
|
|
|
jcc.Sender = autorest.CreateSender(withRequestLogging())
|
2015-12-08 23:30:12 +01:00
|
|
|
client.jobsCollectionsClient = jcc
|
|
|
|
|
2017-01-04 13:00:14 +01:00
|
|
|
ssc := storage.NewAccountsClientWithBaseURI(endpoint, c.SubscriptionID)
|
2016-01-06 23:07:15 +01:00
|
|
|
setUserAgent(&ssc.Client)
|
2015-12-08 23:30:12 +01:00
|
|
|
ssc.Authorizer = spt
|
2016-06-01 22:17:21 +02:00
|
|
|
ssc.Sender = autorest.CreateSender(withRequestLogging())
|
2015-12-08 23:30:12 +01:00
|
|
|
client.storageServiceClient = ssc
|
|
|
|
|
2017-01-04 13:00:14 +01:00
|
|
|
suc := storage.NewUsageOperationsClientWithBaseURI(endpoint, c.SubscriptionID)
|
2016-01-06 23:07:15 +01:00
|
|
|
setUserAgent(&suc.Client)
|
2015-12-08 23:30:12 +01:00
|
|
|
suc.Authorizer = spt
|
2015-12-09 02:25:05 +01:00
|
|
|
suc.Sender = autorest.CreateSender(withRequestLogging())
|
2015-12-08 23:30:12 +01:00
|
|
|
client.storageUsageClient = suc
|
|
|
|
|
2017-01-04 13:00:14 +01:00
|
|
|
cpc := cdn.NewProfilesClientWithBaseURI(endpoint, c.SubscriptionID)
|
2016-01-19 11:11:37 +01:00
|
|
|
setUserAgent(&cpc.Client)
|
|
|
|
cpc.Authorizer = spt
|
|
|
|
cpc.Sender = autorest.CreateSender(withRequestLogging())
|
|
|
|
client.cdnProfilesClient = cpc
|
|
|
|
|
2017-01-04 13:00:14 +01:00
|
|
|
cec := cdn.NewEndpointsClientWithBaseURI(endpoint, c.SubscriptionID)
|
2016-01-19 19:08:56 +01:00
|
|
|
setUserAgent(&cec.Client)
|
|
|
|
cec.Authorizer = spt
|
|
|
|
cec.Sender = autorest.CreateSender(withRequestLogging())
|
|
|
|
client.cdnEndpointsClient = cec
|
|
|
|
|
2017-01-04 13:00:14 +01:00
|
|
|
dc := resources.NewDeploymentsClientWithBaseURI(endpoint, c.SubscriptionID)
|
2016-03-21 16:49:48 +01:00
|
|
|
setUserAgent(&dc.Client)
|
|
|
|
dc.Authorizer = spt
|
|
|
|
dc.Sender = autorest.CreateSender(withRequestLogging())
|
|
|
|
client.deploymentsClient = dc
|
|
|
|
|
2017-01-04 13:00:14 +01:00
|
|
|
tmpc := trafficmanager.NewProfilesClientWithBaseURI(endpoint, c.SubscriptionID)
|
2016-08-01 00:46:15 +02:00
|
|
|
setUserAgent(&tmpc.Client)
|
|
|
|
tmpc.Authorizer = spt
|
|
|
|
tmpc.Sender = autorest.CreateSender(withRequestLogging())
|
|
|
|
client.trafficManagerProfilesClient = tmpc
|
|
|
|
|
2017-01-04 13:00:14 +01:00
|
|
|
tmec := trafficmanager.NewEndpointsClientWithBaseURI(endpoint, c.SubscriptionID)
|
2016-08-01 00:46:15 +02:00
|
|
|
setUserAgent(&tmec.Client)
|
|
|
|
tmec.Authorizer = spt
|
|
|
|
tmec.Sender = autorest.CreateSender(withRequestLogging())
|
|
|
|
client.trafficManagerEndpointsClient = tmec
|
|
|
|
|
2017-02-23 17:14:55 +01:00
|
|
|
rdc := redis.NewGroupClientWithBaseURI(endpoint, c.SubscriptionID)
|
2016-12-18 15:23:29 +01:00
|
|
|
setUserAgent(&rdc.Client)
|
|
|
|
rdc.Authorizer = spt
|
|
|
|
rdc.Sender = autorest.CreateSender(withRequestLogging())
|
|
|
|
client.redisClient = rdc
|
|
|
|
|
2017-01-04 13:00:14 +01:00
|
|
|
sbnc := servicebus.NewNamespacesClientWithBaseURI(endpoint, c.SubscriptionID)
|
2016-08-15 19:00:00 +02:00
|
|
|
setUserAgent(&sbnc.Client)
|
|
|
|
sbnc.Authorizer = spt
|
|
|
|
sbnc.Sender = autorest.CreateSender(withRequestLogging())
|
|
|
|
client.serviceBusNamespacesClient = sbnc
|
|
|
|
|
2017-01-04 13:00:14 +01:00
|
|
|
sbtc := servicebus.NewTopicsClientWithBaseURI(endpoint, c.SubscriptionID)
|
2016-09-29 19:07:25 +02:00
|
|
|
setUserAgent(&sbtc.Client)
|
|
|
|
sbtc.Authorizer = spt
|
|
|
|
sbtc.Sender = autorest.CreateSender(withRequestLogging())
|
|
|
|
client.serviceBusTopicsClient = sbtc
|
|
|
|
|
2017-01-04 13:00:14 +01:00
|
|
|
sbsc := servicebus.NewSubscriptionsClientWithBaseURI(endpoint, c.SubscriptionID)
|
2016-10-03 12:22:18 +02:00
|
|
|
setUserAgent(&sbsc.Client)
|
|
|
|
sbsc.Authorizer = spt
|
|
|
|
sbsc.Sender = autorest.CreateSender(withRequestLogging())
|
|
|
|
client.serviceBusSubscriptionsClient = sbsc
|
|
|
|
|
2017-01-04 13:00:14 +01:00
|
|
|
kvc := keyvault.NewVaultsClientWithBaseURI(endpoint, c.SubscriptionID)
|
2016-10-20 12:30:30 +02:00
|
|
|
setUserAgent(&kvc.Client)
|
|
|
|
kvc.Authorizer = spt
|
|
|
|
kvc.Sender = autorest.CreateSender(withRequestLogging())
|
|
|
|
client.keyVaultClient = kvc
|
|
|
|
|
2015-12-08 23:30:12 +01:00
|
|
|
return &client, nil
|
|
|
|
}
|
2016-01-26 21:45:18 +01:00
|
|
|
|
2016-05-25 00:01:26 +02:00
|
|
|
func (armClient *ArmClient) getKeyForStorageAccount(resourceGroupName, storageAccountName string) (string, bool, error) {
|
2016-06-30 16:36:08 +02:00
|
|
|
accountKeys, err := armClient.storageServiceClient.ListKeys(resourceGroupName, storageAccountName)
|
|
|
|
if accountKeys.StatusCode == http.StatusNotFound {
|
2016-05-25 00:01:26 +02:00
|
|
|
return "", false, nil
|
|
|
|
}
|
2016-01-26 21:45:18 +01:00
|
|
|
if err != nil {
|
2016-05-25 00:01:26 +02:00
|
|
|
// We assume this is a transient error rather than a 404 (which is caught above), so assume the
|
|
|
|
// account still exists.
|
|
|
|
return "", true, fmt.Errorf("Error retrieving keys for storage account %q: %s", storageAccountName, err)
|
2016-01-26 21:45:18 +01:00
|
|
|
}
|
|
|
|
|
2016-06-30 16:36:08 +02:00
|
|
|
if accountKeys.Keys == nil {
|
2016-05-25 00:01:26 +02:00
|
|
|
return "", false, fmt.Errorf("Nil key returned for storage account %q", storageAccountName)
|
2016-01-26 21:45:18 +01:00
|
|
|
}
|
|
|
|
|
2016-06-30 16:36:08 +02:00
|
|
|
keys := *accountKeys.Keys
|
|
|
|
return *keys[0].Value, true, nil
|
2016-01-26 21:45:18 +01:00
|
|
|
}
|
|
|
|
|
2016-05-25 00:01:26 +02:00
|
|
|
func (armClient *ArmClient) getBlobStorageClientForStorageAccount(resourceGroupName, storageAccountName string) (*mainStorage.BlobStorageClient, bool, error) {
|
|
|
|
key, accountExists, err := armClient.getKeyForStorageAccount(resourceGroupName, storageAccountName)
|
2016-01-26 21:45:18 +01:00
|
|
|
if err != nil {
|
2016-05-25 00:01:26 +02:00
|
|
|
return nil, accountExists, err
|
|
|
|
}
|
|
|
|
if accountExists == false {
|
|
|
|
return nil, false, nil
|
2016-01-26 21:45:18 +01:00
|
|
|
}
|
|
|
|
|
2017-01-17 17:28:24 +01:00
|
|
|
storageClient, err := mainStorage.NewClient(storageAccountName, key, armClient.environment.StorageEndpointSuffix,
|
|
|
|
mainStorage.DefaultAPIVersion, true)
|
2016-01-26 21:45:18 +01:00
|
|
|
if err != nil {
|
2016-05-25 00:01:26 +02:00
|
|
|
return nil, true, fmt.Errorf("Error creating storage client for storage account %q: %s", storageAccountName, err)
|
2016-01-26 21:45:18 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
blobClient := storageClient.GetBlobService()
|
2016-05-25 00:01:26 +02:00
|
|
|
return &blobClient, true, nil
|
2016-01-26 21:45:18 +01:00
|
|
|
}
|
2016-09-06 11:10:27 +02:00
|
|
|
|
|
|
|
func (armClient *ArmClient) getFileServiceClientForStorageAccount(resourceGroupName, storageAccountName string) (*mainStorage.FileServiceClient, bool, error) {
|
|
|
|
key, accountExists, err := armClient.getKeyForStorageAccount(resourceGroupName, storageAccountName)
|
|
|
|
if err != nil {
|
|
|
|
return nil, accountExists, err
|
|
|
|
}
|
|
|
|
if accountExists == false {
|
|
|
|
return nil, false, nil
|
|
|
|
}
|
|
|
|
|
2017-01-17 17:28:24 +01:00
|
|
|
storageClient, err := mainStorage.NewClient(storageAccountName, key, armClient.environment.StorageEndpointSuffix,
|
|
|
|
mainStorage.DefaultAPIVersion, true)
|
2016-09-06 11:10:27 +02:00
|
|
|
if err != nil {
|
|
|
|
return nil, true, fmt.Errorf("Error creating storage client for storage account %q: %s", storageAccountName, err)
|
|
|
|
}
|
|
|
|
|
|
|
|
fileClient := storageClient.GetFileService()
|
|
|
|
return &fileClient, true, nil
|
|
|
|
}
|
|
|
|
|
2016-07-27 23:49:43 +02:00
|
|
|
func (armClient *ArmClient) getTableServiceClientForStorageAccount(resourceGroupName, storageAccountName string) (*mainStorage.TableServiceClient, bool, error) {
|
|
|
|
key, accountExists, err := armClient.getKeyForStorageAccount(resourceGroupName, storageAccountName)
|
|
|
|
if err != nil {
|
|
|
|
return nil, accountExists, err
|
|
|
|
}
|
|
|
|
if accountExists == false {
|
|
|
|
return nil, false, nil
|
|
|
|
}
|
|
|
|
|
2017-01-17 17:28:24 +01:00
|
|
|
storageClient, err := mainStorage.NewClient(storageAccountName, key, armClient.environment.StorageEndpointSuffix,
|
|
|
|
mainStorage.DefaultAPIVersion, true)
|
2016-07-27 23:49:43 +02:00
|
|
|
if err != nil {
|
|
|
|
return nil, true, fmt.Errorf("Error creating storage client for storage account %q: %s", storageAccountName, err)
|
|
|
|
}
|
|
|
|
|
|
|
|
tableClient := storageClient.GetTableService()
|
|
|
|
return &tableClient, true, nil
|
|
|
|
}
|
2016-06-01 22:17:21 +02:00
|
|
|
|
2016-05-25 00:01:26 +02:00
|
|
|
func (armClient *ArmClient) getQueueServiceClientForStorageAccount(resourceGroupName, storageAccountName string) (*mainStorage.QueueServiceClient, bool, error) {
|
|
|
|
key, accountExists, err := armClient.getKeyForStorageAccount(resourceGroupName, storageAccountName)
|
2016-01-27 13:27:58 +01:00
|
|
|
if err != nil {
|
2016-05-25 00:01:26 +02:00
|
|
|
return nil, accountExists, err
|
|
|
|
}
|
|
|
|
if accountExists == false {
|
|
|
|
return nil, false, nil
|
2016-01-27 13:27:58 +01:00
|
|
|
}
|
|
|
|
|
2017-01-17 17:28:24 +01:00
|
|
|
storageClient, err := mainStorage.NewClient(storageAccountName, key, armClient.environment.StorageEndpointSuffix,
|
|
|
|
mainStorage.DefaultAPIVersion, true)
|
2016-01-27 13:27:58 +01:00
|
|
|
if err != nil {
|
2016-05-25 00:01:26 +02:00
|
|
|
return nil, true, fmt.Errorf("Error creating storage client for storage account %q: %s", storageAccountName, err)
|
2016-01-27 13:27:58 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
queueClient := storageClient.GetQueueService()
|
2016-05-25 00:01:26 +02:00
|
|
|
return &queueClient, true, nil
|
2016-01-27 13:27:58 +01:00
|
|
|
}
|