Cleaned up client creation and handling.

This commit is contained in:
aznashwan 2015-06-16 20:54:52 +03:00
parent db3a22f4f4
commit 58dd568da9
26 changed files with 282 additions and 267 deletions

View File

@ -6,6 +6,15 @@ import (
"sync" "sync"
"github.com/Azure/azure-sdk-for-go/management" "github.com/Azure/azure-sdk-for-go/management"
"github.com/Azure/azure-sdk-for-go/management/hostedservice"
"github.com/Azure/azure-sdk-for-go/management/networksecuritygroup"
"github.com/Azure/azure-sdk-for-go/management/osimage"
"github.com/Azure/azure-sdk-for-go/management/storageservice"
"github.com/Azure/azure-sdk-for-go/management/virtualmachine"
"github.com/Azure/azure-sdk-for-go/management/virtualmachinedisk"
"github.com/Azure/azure-sdk-for-go/management/virtualmachineimage"
"github.com/Azure/azure-sdk-for-go/management/virtualnetwork"
"github.com/Azure/azure-sdk-for-go/storage"
) )
// Config is the configuration structure used to instantiate a // Config is the configuration structure used to instantiate a
@ -19,10 +28,66 @@ type Config struct {
// Client contains all the handles required for managing Azure services. // Client contains all the handles required for managing Azure services.
type Client struct { type Client struct {
// unfortunately; because of how Azure's network API works; doing networking operations
// concurrently is very hazardous, and we need a mutex to guard the management.Client.
mutex *sync.Mutex
mgmtClient management.Client mgmtClient management.Client
hostedServiceClient hostedservice.HostedServiceClient
secGroupClient networksecuritygroup.SecurityGroupClient
osImageClient osimage.OSImageClient
storageServiceClient storageservice.StorageServiceClient
vmClient virtualmachine.VirtualMachineClient
vmDiskClient virtualmachinedisk.DiskClient
vmImageClient virtualmachineimage.Client
// unfortunately; because of how Azure's network API works; doing networking operations
// concurrently is very hazardous, and we need a mutex to guard the VirtualNetworkClient.
vnetClient virtualnetwork.VirtualNetworkClient
mutex *sync.Mutex
}
// getStorageClientForStorageService is helper method which returns the
// storage.Client associated to the given storage service name.
func (c Client) getStorageClientForStorageService(serviceName string) (storage.Client, error) {
var storageClient storage.Client
keys, err := c.storageServiceClient.GetStorageServiceKeys(serviceName)
if err != nil {
return storageClient, fmt.Errorf("Failed getting Storage Service keys for %s: %s", serviceName, err)
}
storageClient, err = storage.NewBasicClient(serviceName, keys.PrimaryKey)
if err != nil {
return storageClient, fmt.Errorf("Failed creating Storage Service client for %s: %s", serviceName, err)
}
return storageClient, err
}
// getStorageServiceBlobClient is a helper method which returns the
// storage.BlobStorageClient associated to the given storage service name.
func (c Client) getStorageServiceBlobClient(serviceName string) (storage.BlobStorageClient, error) {
storageClient, err := c.getStorageClientForStorageService(serviceName)
if err != nil {
return storage.BlobStorageClient{}, err
}
return storageClient.GetBlobService(), nil
}
// getStorageServiceQueueClient is a helper method which returns the
// storage.QueueServiceClient associated to the given storage service name.
func (c Client) getStorageServiceQueueClient(serviceName string) (storage.QueueServiceClient, error) {
storageClient, err := c.getStorageClientForStorageService(serviceName)
if err != nil {
return storage.QueueServiceClient{}, err
}
return storageClient.GetQueueService(), err
} }
// NewClientFromSettingsFile returns a new Azure management // NewClientFromSettingsFile returns a new Azure management
@ -38,8 +103,16 @@ func (c *Config) NewClientFromSettingsFile() (*Client, error) {
} }
return &Client{ return &Client{
mutex: &sync.Mutex{}, mgmtClient: mc,
mgmtClient: mc, hostedServiceClient: hostedservice.NewClient(mc),
secGroupClient: networksecuritygroup.NewClient(mc),
osImageClient: osimage.NewClient(mc),
storageServiceClient: storageservice.NewClient(mc),
vmClient: virtualmachine.NewClient(mc),
vmDiskClient: virtualmachinedisk.NewClient(mc),
vmImageClient: virtualmachineimage.NewClient(mc),
vnetClient: virtualnetwork.NewClient(mc),
mutex: &sync.Mutex{},
}, nil }, nil
} }
@ -52,7 +125,15 @@ func (c *Config) NewClient() (*Client, error) {
} }
return &Client{ return &Client{
mutex: &sync.Mutex{}, mgmtClient: mc,
mgmtClient: mc, hostedServiceClient: hostedservice.NewClient(mc),
secGroupClient: networksecuritygroup.NewClient(mc),
osImageClient: osimage.NewClient(mc),
storageServiceClient: storageservice.NewClient(mc),
vmClient: virtualmachine.NewClient(mc),
vmDiskClient: virtualmachinedisk.NewClient(mc),
vmImageClient: virtualmachineimage.NewClient(mc),
vnetClient: virtualnetwork.NewClient(mc),
mutex: &sync.Mutex{},
}, nil }, nil
} }

View File

@ -79,6 +79,7 @@ func resourceAzureDataDisk() *schema.Resource {
func resourceAzureDataDiskCreate(d *schema.ResourceData, meta interface{}) error { func resourceAzureDataDiskCreate(d *schema.ResourceData, meta interface{}) error {
mc := meta.(*Client).mgmtClient mc := meta.(*Client).mgmtClient
vmDiskClient := meta.(*Client).vmDiskClient
if err := verifyDataDiskParameters(d); err != nil { if err := verifyDataDiskParameters(d); err != nil {
return err return err
@ -106,7 +107,7 @@ func resourceAzureDataDiskCreate(d *schema.ResourceData, meta interface{}) error
} }
log.Printf("[DEBUG] Adding data disk %d to instance: %s", lun, vm) log.Printf("[DEBUG] Adding data disk %d to instance: %s", lun, vm)
req, err := virtualmachinedisk.NewClient(mc).AddDataDisk(vm, vm, vm, p) req, err := vmDiskClient.AddDataDisk(vm, vm, vm, p)
if err != nil { if err != nil {
return fmt.Errorf("Error adding data disk %d to instance %s: %s", lun, vm, err) return fmt.Errorf("Error adding data disk %d to instance %s: %s", lun, vm, err)
} }
@ -118,7 +119,7 @@ func resourceAzureDataDiskCreate(d *schema.ResourceData, meta interface{}) error
} }
log.Printf("[DEBUG] Retrieving data disk %d from instance %s", lun, vm) log.Printf("[DEBUG] Retrieving data disk %d from instance %s", lun, vm)
disk, err := virtualmachinedisk.NewClient(mc).GetDataDisk(vm, vm, vm, lun) disk, err := vmDiskClient.GetDataDisk(vm, vm, vm, lun)
if err != nil { if err != nil {
return fmt.Errorf("Error retrieving data disk %d from instance %s: %s", lun, vm, err) return fmt.Errorf("Error retrieving data disk %d from instance %s: %s", lun, vm, err)
} }
@ -129,13 +130,13 @@ func resourceAzureDataDiskCreate(d *schema.ResourceData, meta interface{}) error
} }
func resourceAzureDataDiskRead(d *schema.ResourceData, meta interface{}) error { func resourceAzureDataDiskRead(d *schema.ResourceData, meta interface{}) error {
mc := meta.(*Client).mgmtClient vmDiskClient := meta.(*Client).vmDiskClient
lun := d.Get("lun").(int) lun := d.Get("lun").(int)
vm := d.Get("virtual_machine").(string) vm := d.Get("virtual_machine").(string)
log.Printf("[DEBUG] Retrieving data disk: %s", d.Id()) log.Printf("[DEBUG] Retrieving data disk: %s", d.Id())
datadisk, err := virtualmachinedisk.NewClient(mc).GetDataDisk(vm, vm, vm, lun) datadisk, err := vmDiskClient.GetDataDisk(vm, vm, vm, lun)
if err != nil { if err != nil {
if management.IsResourceNotFoundError(err) { if management.IsResourceNotFoundError(err) {
d.SetId("") d.SetId("")
@ -152,7 +153,7 @@ func resourceAzureDataDiskRead(d *schema.ResourceData, meta interface{}) error {
d.Set("media_link", datadisk.MediaLink) d.Set("media_link", datadisk.MediaLink)
log.Printf("[DEBUG] Retrieving disk: %s", d.Id()) log.Printf("[DEBUG] Retrieving disk: %s", d.Id())
disk, err := virtualmachinedisk.NewClient(mc).GetDisk(d.Id()) disk, err := vmDiskClient.GetDisk(d.Id())
if err != nil { if err != nil {
return fmt.Errorf("Error retrieving disk %s: %s", d.Id(), err) return fmt.Errorf("Error retrieving disk %s: %s", d.Id(), err)
} }
@ -164,7 +165,7 @@ func resourceAzureDataDiskRead(d *schema.ResourceData, meta interface{}) error {
func resourceAzureDataDiskUpdate(d *schema.ResourceData, meta interface{}) error { func resourceAzureDataDiskUpdate(d *schema.ResourceData, meta interface{}) error {
mc := meta.(*Client).mgmtClient mc := meta.(*Client).mgmtClient
diskClient := virtualmachinedisk.NewClient(mc) vmDiskClient := meta.(*Client).vmDiskClient
lun := d.Get("lun").(int) lun := d.Get("lun").(int)
vm := d.Get("virtual_machine").(string) vm := d.Get("virtual_machine").(string)
@ -174,7 +175,7 @@ func resourceAzureDataDiskUpdate(d *schema.ResourceData, meta interface{}) error
ovm, _ := d.GetChange("virtual_machine") ovm, _ := d.GetChange("virtual_machine")
log.Printf("[DEBUG] Detaching data disk: %s", d.Id()) log.Printf("[DEBUG] Detaching data disk: %s", d.Id())
req, err := diskClient. req, err := vmDiskClient.
DeleteDataDisk(ovm.(string), ovm.(string), ovm.(string), olun.(int), false) DeleteDataDisk(ovm.(string), ovm.(string), ovm.(string), olun.(int), false)
if err != nil { if err != nil {
return fmt.Errorf("Error detaching data disk %s: %s", d.Id(), err) return fmt.Errorf("Error detaching data disk %s: %s", d.Id(), err)
@ -188,7 +189,7 @@ func resourceAzureDataDiskUpdate(d *schema.ResourceData, meta interface{}) error
log.Printf("[DEBUG] Verifying data disk %s is properly detached...", d.Id()) log.Printf("[DEBUG] Verifying data disk %s is properly detached...", d.Id())
for i := 0; i < 6; i++ { for i := 0; i < 6; i++ {
disk, err := diskClient.GetDisk(d.Id()) disk, err := vmDiskClient.GetDisk(d.Id())
if err != nil { if err != nil {
return fmt.Errorf("Error retrieving disk %s: %s", d.Id(), err) return fmt.Errorf("Error retrieving disk %s: %s", d.Id(), err)
} }
@ -210,7 +211,7 @@ func resourceAzureDataDiskUpdate(d *schema.ResourceData, meta interface{}) error
} }
log.Printf("[DEBUG] Updating disk: %s", d.Id()) log.Printf("[DEBUG] Updating disk: %s", d.Id())
req, err := diskClient.UpdateDisk(d.Id(), p) req, err := vmDiskClient.UpdateDisk(d.Id(), p)
if err != nil { if err != nil {
return fmt.Errorf("Error updating disk %s: %s", d.Id(), err) return fmt.Errorf("Error updating disk %s: %s", d.Id(), err)
} }
@ -230,7 +231,7 @@ func resourceAzureDataDiskUpdate(d *schema.ResourceData, meta interface{}) error
} }
log.Printf("[DEBUG] Attaching data disk: %s", d.Id()) log.Printf("[DEBUG] Attaching data disk: %s", d.Id())
req, err = diskClient.AddDataDisk(vm, vm, vm, p) req, err = vmDiskClient.AddDataDisk(vm, vm, vm, p)
if err != nil { if err != nil {
return fmt.Errorf("Error attaching data disk %s to instance %s: %s", d.Id(), vm, err) return fmt.Errorf("Error attaching data disk %s to instance %s: %s", d.Id(), vm, err)
} }
@ -255,7 +256,7 @@ func resourceAzureDataDiskUpdate(d *schema.ResourceData, meta interface{}) error
} }
log.Printf("[DEBUG] Updating data disk: %s", d.Id()) log.Printf("[DEBUG] Updating data disk: %s", d.Id())
req, err := diskClient.UpdateDataDisk(vm, vm, vm, lun, p) req, err := vmDiskClient.UpdateDataDisk(vm, vm, vm, lun, p)
if err != nil { if err != nil {
return fmt.Errorf("Error updating data disk %s: %s", d.Id(), err) return fmt.Errorf("Error updating data disk %s: %s", d.Id(), err)
} }
@ -272,6 +273,7 @@ func resourceAzureDataDiskUpdate(d *schema.ResourceData, meta interface{}) error
func resourceAzureDataDiskDelete(d *schema.ResourceData, meta interface{}) error { func resourceAzureDataDiskDelete(d *schema.ResourceData, meta interface{}) error {
mc := meta.(*Client).mgmtClient mc := meta.(*Client).mgmtClient
vmDiskClient := meta.(*Client).vmDiskClient
lun := d.Get("lun").(int) lun := d.Get("lun").(int)
vm := d.Get("virtual_machine").(string) vm := d.Get("virtual_machine").(string)
@ -281,7 +283,7 @@ func resourceAzureDataDiskDelete(d *schema.ResourceData, meta interface{}) error
_, removeBlob := d.GetOk("name") _, removeBlob := d.GetOk("name")
log.Printf("[DEBUG] Detaching data disk %s with removeBlob = %t", d.Id(), removeBlob) log.Printf("[DEBUG] Detaching data disk %s with removeBlob = %t", d.Id(), removeBlob)
req, err := virtualmachinedisk.NewClient(mc).DeleteDataDisk(vm, vm, vm, lun, removeBlob) req, err := vmDiskClient.DeleteDataDisk(vm, vm, vm, lun, removeBlob)
if err != nil { if err != nil {
return fmt.Errorf( return fmt.Errorf(
"Error detaching data disk %s with removeBlob = %t: %s", d.Id(), removeBlob, err) "Error detaching data disk %s with removeBlob = %t: %s", d.Id(), removeBlob, err)

View File

@ -101,8 +101,8 @@ func testAccCheckAzureDataDiskExists(
return err return err
} }
mc := testAccProvider.Meta().(*Client).mgmtClient vmDiskClient := testAccProvider.Meta().(*Client).vmDiskClient
d, err := virtualmachinedisk.NewClient(mc).GetDataDisk(vm, vm, vm, lun) d, err := vmDiskClient.GetDataDisk(vm, vm, vm, lun)
if err != nil { if err != nil {
return err return err
} }
@ -138,7 +138,7 @@ func testAccCheckAzureDataDiskAttributes(
} }
func testAccCheckAzureDataDiskDestroy(s *terraform.State) error { func testAccCheckAzureDataDiskDestroy(s *terraform.State) error {
mc := testAccProvider.Meta().(*Client).mgmtClient vmDiskClient := testAccProvider.Meta().(*Client).vmDiskClient
for _, rs := range s.RootModule().Resources { for _, rs := range s.RootModule().Resources {
if rs.Type != "azure_data_disk" { if rs.Type != "azure_data_disk" {
@ -155,7 +155,7 @@ func testAccCheckAzureDataDiskDestroy(s *terraform.State) error {
return err return err
} }
_, err = virtualmachinedisk.NewClient(mc).GetDataDisk(vm, vm, vm, lun) _, err = vmDiskClient.GetDataDisk(vm, vm, vm, lun)
if err == nil { if err == nil {
return fmt.Errorf("Data disk %s still exists", rs.Primary.ID) return fmt.Errorf("Data disk %s still exists", rs.Primary.ID)
} }

View File

@ -37,23 +37,14 @@ func resourceAzureDnsServer() *schema.Resource {
// resourceAzureDnsServerCreate does all the necessary API calls // resourceAzureDnsServerCreate does all the necessary API calls
// to create a new DNS server definition on Azure. // to create a new DNS server definition on Azure.
func resourceAzureDnsServerCreate(d *schema.ResourceData, meta interface{}) error { func resourceAzureDnsServerCreate(d *schema.ResourceData, meta interface{}) error {
// first; check for the existence of the resource:
exists, err := resourceAzureDnsServerExists(d, meta)
if err != nil {
return err
}
if exists {
return fmt.Errorf("Azure DNS server definition already exists.")
}
azureClient := meta.(*Client) azureClient := meta.(*Client)
mgmtClient := azureClient.mgmtClient mgmtClient := azureClient.mgmtClient
networkClient := virtualnetwork.NewClient(mgmtClient) vnetClient := azureClient.vnetClient
log.Println("[INFO] Fetching current network configuration from Azure.") log.Println("[INFO] Fetching current network configuration from Azure.")
azureClient.mutex.Lock() azureClient.mutex.Lock()
defer azureClient.mutex.Unlock() defer azureClient.mutex.Unlock()
netConf, err := networkClient.GetVirtualNetworkConfiguration() netConf, err := vnetClient.GetVirtualNetworkConfiguration()
if err != nil { if err != nil {
return fmt.Errorf("Failed to get the current network configuration from Azure: %s", err) return fmt.Errorf("Failed to get the current network configuration from Azure: %s", err)
} }
@ -70,7 +61,7 @@ func resourceAzureDnsServerCreate(d *schema.ResourceData, meta interface{}) erro
// send the configuration back to Azure: // send the configuration back to Azure:
log.Println("[INFO] Sending updated network configuration back to Azure.") log.Println("[INFO] Sending updated network configuration back to Azure.")
reqID, err := networkClient.SetVirtualNetworkConfiguration(netConf) reqID, err := vnetClient.SetVirtualNetworkConfiguration(netConf)
if err != nil { if err != nil {
return fmt.Errorf("Failed issuing update to network configuration: %s", err) return fmt.Errorf("Failed issuing update to network configuration: %s", err)
} }
@ -86,12 +77,10 @@ func resourceAzureDnsServerCreate(d *schema.ResourceData, meta interface{}) erro
// resourceAzureDnsServerRead does all the necessary API calls to read // resourceAzureDnsServerRead does all the necessary API calls to read
// the state of the DNS server off Azure. // the state of the DNS server off Azure.
func resourceAzureDnsServerRead(d *schema.ResourceData, meta interface{}) error { func resourceAzureDnsServerRead(d *schema.ResourceData, meta interface{}) error {
azureClient := meta.(*Client) vnetClient := meta.(*Client).vnetClient
mgmtClient := azureClient.mgmtClient
networkClient := virtualnetwork.NewClient(mgmtClient)
log.Println("[INFO] Fetching current network configuration from Azure.") log.Println("[INFO] Fetching current network configuration from Azure.")
netConf, err := networkClient.GetVirtualNetworkConfiguration() netConf, err := vnetClient.GetVirtualNetworkConfiguration()
if err != nil { if err != nil {
return fmt.Errorf("Failed to get the current network configuration from Azure: %s", err) return fmt.Errorf("Failed to get the current network configuration from Azure: %s", err)
} }
@ -121,7 +110,7 @@ func resourceAzureDnsServerRead(d *schema.ResourceData, meta interface{}) error
func resourceAzureDnsServerUpdate(d *schema.ResourceData, meta interface{}) error { func resourceAzureDnsServerUpdate(d *schema.ResourceData, meta interface{}) error {
azureClient := meta.(*Client) azureClient := meta.(*Client)
mgmtClient := azureClient.mgmtClient mgmtClient := azureClient.mgmtClient
networkClient := virtualnetwork.NewClient(mgmtClient) vnetClient := azureClient.vnetClient
var found bool var found bool
name := d.Get("name").(string) name := d.Get("name").(string)
@ -131,7 +120,7 @@ func resourceAzureDnsServerUpdate(d *schema.ResourceData, meta interface{}) erro
log.Println("[INFO] Fetching current network configuration from Azure.") log.Println("[INFO] Fetching current network configuration from Azure.")
azureClient.mutex.Lock() azureClient.mutex.Lock()
defer azureClient.mutex.Unlock() defer azureClient.mutex.Unlock()
netConf, err := networkClient.GetVirtualNetworkConfiguration() netConf, err := vnetClient.GetVirtualNetworkConfiguration()
if err != nil { if err != nil {
return fmt.Errorf("Failed to get the current network configuration from Azure: %s", err) return fmt.Errorf("Failed to get the current network configuration from Azure: %s", err)
} }
@ -148,7 +137,7 @@ func resourceAzureDnsServerUpdate(d *schema.ResourceData, meta interface{}) erro
// if the config has changes, send the configuration back to Azure: // if the config has changes, send the configuration back to Azure:
if found { if found {
log.Println("[INFO] Sending updated network configuration back to Azure.") log.Println("[INFO] Sending updated network configuration back to Azure.")
reqID, err := networkClient.SetVirtualNetworkConfiguration(netConf) reqID, err := vnetClient.SetVirtualNetworkConfiguration(netConf)
if err != nil { if err != nil {
return fmt.Errorf("Failed issuing update to network configuration: %s", err) return fmt.Errorf("Failed issuing update to network configuration: %s", err)
} }
@ -173,11 +162,10 @@ func resourceAzureDnsServerUpdate(d *schema.ResourceData, meta interface{}) erro
// check if the DNS server definition alredy exists on Azure. // check if the DNS server definition alredy exists on Azure.
func resourceAzureDnsServerExists(d *schema.ResourceData, meta interface{}) (bool, error) { func resourceAzureDnsServerExists(d *schema.ResourceData, meta interface{}) (bool, error) {
azureClient := meta.(*Client) azureClient := meta.(*Client)
mgmtClient := azureClient.mgmtClient vnetClient := azureClient.vnetClient
networkClient := virtualnetwork.NewClient(mgmtClient)
log.Println("[INFO] Fetching current network configuration from Azure.") log.Println("[INFO] Fetching current network configuration from Azure.")
netConf, err := networkClient.GetVirtualNetworkConfiguration() netConf, err := vnetClient.GetVirtualNetworkConfiguration()
if err != nil { if err != nil {
return false, fmt.Errorf("Failed to get the current network configuration from Azure: %s", err) return false, fmt.Errorf("Failed to get the current network configuration from Azure: %s", err)
} }
@ -201,12 +189,12 @@ func resourceAzureDnsServerExists(d *schema.ResourceData, meta interface{}) (boo
func resourceAzureDnsServerDelete(d *schema.ResourceData, meta interface{}) error { func resourceAzureDnsServerDelete(d *schema.ResourceData, meta interface{}) error {
azureClient := meta.(*Client) azureClient := meta.(*Client)
mgmtClient := azureClient.mgmtClient mgmtClient := azureClient.mgmtClient
networkClient := virtualnetwork.NewClient(mgmtClient) vnetClient := azureClient.vnetClient
log.Println("[INFO] Fetching current network configuration from Azure.") log.Println("[INFO] Fetching current network configuration from Azure.")
azureClient.mutex.Lock() azureClient.mutex.Lock()
defer azureClient.mutex.Unlock() defer azureClient.mutex.Unlock()
netConf, err := networkClient.GetVirtualNetworkConfiguration() netConf, err := vnetClient.GetVirtualNetworkConfiguration()
if err != nil { if err != nil {
return fmt.Errorf("Failed to get the current network configuration from Azure: %s", err) return fmt.Errorf("Failed to get the current network configuration from Azure: %s", err)
} }
@ -233,7 +221,7 @@ func resourceAzureDnsServerDelete(d *schema.ResourceData, meta interface{}) erro
// send the configuration back to Azure: // send the configuration back to Azure:
log.Println("[INFO] Sending updated network configuration back to Azure.") log.Println("[INFO] Sending updated network configuration back to Azure.")
reqID, err := networkClient.SetVirtualNetworkConfiguration(netConf) reqID, err := vnetClient.SetVirtualNetworkConfiguration(netConf)
if err != nil { if err != nil {
return fmt.Errorf("Failed issuing update to network configuration: %s", err) return fmt.Errorf("Failed issuing update to network configuration: %s", err)
} }

View File

@ -4,7 +4,6 @@ import (
"fmt" "fmt"
"testing" "testing"
"github.com/Azure/azure-sdk-for-go/management/virtualnetwork"
"github.com/hashicorp/terraform/helper/resource" "github.com/hashicorp/terraform/helper/resource"
"github.com/hashicorp/terraform/terraform" "github.com/hashicorp/terraform/terraform"
) )
@ -69,8 +68,8 @@ func testAccCheckAzureDnsServerExists(name string) resource.TestCheckFunc {
return fmt.Errorf("No DNS Server ID set.") return fmt.Errorf("No DNS Server ID set.")
} }
mgmtClient := testAccProvider.Meta().(*Client).mgmtClient vnetClient := testAccProvider.Meta().(*Client).vnetClient
netConf, err := virtualnetwork.NewClient(mgmtClient).GetVirtualNetworkConfiguration() netConf, err := vnetClient.GetVirtualNetworkConfiguration()
if err != nil { if err != nil {
return fmt.Errorf("Failed fetching networking configuration: %s", err) return fmt.Errorf("Failed fetching networking configuration: %s", err)
} }
@ -86,7 +85,7 @@ func testAccCheckAzureDnsServerExists(name string) resource.TestCheckFunc {
} }
func testAccCheckAzureDnsServerDestroy(s *terraform.State) error { func testAccCheckAzureDnsServerDestroy(s *terraform.State) error {
mgmtClient := testAccProvider.Meta().(*Client).mgmtClient vnetClient := testAccProvider.Meta().(*Client).vnetClient
for _, resource := range s.RootModule().Resources { for _, resource := range s.RootModule().Resources {
if resource.Type != "azure_dns_server" { if resource.Type != "azure_dns_server" {
@ -97,8 +96,7 @@ func testAccCheckAzureDnsServerDestroy(s *terraform.State) error {
return fmt.Errorf("No DNS Server ID is set.") return fmt.Errorf("No DNS Server ID is set.")
} }
networkClient := virtualnetwork.NewClient(mgmtClient) netConf, err := vnetClient.GetVirtualNetworkConfiguration()
netConf, err := networkClient.GetVirtualNetworkConfiguration()
if err != nil { if err != nil {
return fmt.Errorf("Error retrieving networking configuration from Azure: %s", err) return fmt.Errorf("Error retrieving networking configuration from Azure: %s", err)
} }

View File

@ -76,9 +76,7 @@ func resourceAzureHostedService() *schema.Resource {
// resourceAzureHostedServiceCreate does all the necessary API calls // resourceAzureHostedServiceCreate does all the necessary API calls
// to create a hosted service on Azure. // to create a hosted service on Azure.
func resourceAzureHostedServiceCreate(d *schema.ResourceData, meta interface{}) error { func resourceAzureHostedServiceCreate(d *schema.ResourceData, meta interface{}) error {
azureClient := meta.(*Client) hostedServiceClient := meta.(*Client).hostedServiceClient
mgmtClient := azureClient.mgmtClient
hostedServiceClient := hostedservice.NewClient(mgmtClient)
serviceName := d.Get("name").(string) serviceName := d.Get("name").(string)
location := d.Get("location").(string) location := d.Get("location").(string)
@ -106,8 +104,7 @@ func resourceAzureHostedServiceCreate(d *schema.ResourceData, meta interface{})
// resourceAzureHostedServiceRead does all the necessary API calls // resourceAzureHostedServiceRead does all the necessary API calls
// to read the state of a hosted service from Azure. // to read the state of a hosted service from Azure.
func resourceAzureHostedServiceRead(d *schema.ResourceData, meta interface{}) error { func resourceAzureHostedServiceRead(d *schema.ResourceData, meta interface{}) error {
azureClient := meta.(*Client) hostedServiceClient := meta.(*Client).hostedServiceClient
hostedServiceClient := hostedservice.NewClient(azureClient.mgmtClient)
log.Println("[INFO] Querying for hosted service info.") log.Println("[INFO] Querying for hosted service info.")
serviceName := d.Get("name").(string) serviceName := d.Get("name").(string)
@ -151,7 +148,7 @@ func resourceAzureHostedServiceUpdate(d *schema.ResourceData, meta interface{})
func resourceAzureHostedServiceDelete(d *schema.ResourceData, meta interface{}) error { func resourceAzureHostedServiceDelete(d *schema.ResourceData, meta interface{}) error {
azureClient := meta.(*Client) azureClient := meta.(*Client)
mgmtClient := azureClient.mgmtClient mgmtClient := azureClient.mgmtClient
hostedServiceClient := hostedservice.NewClient(mgmtClient) hostedServiceClient := azureClient.hostedServiceClient
log.Println("[INFO] Issuing hosted service deletion.") log.Println("[INFO] Issuing hosted service deletion.")
serviceName := d.Get("name").(string) serviceName := d.Get("name").(string)

View File

@ -4,7 +4,6 @@ import (
"fmt" "fmt"
"testing" "testing"
"github.com/Azure/azure-sdk-for-go/management/hostedservice"
"github.com/hashicorp/terraform/helper/resource" "github.com/hashicorp/terraform/helper/resource"
"github.com/hashicorp/terraform/terraform" "github.com/hashicorp/terraform/terraform"
) )
@ -78,14 +77,14 @@ func testAccCheckAzureHostedServiceExists(name string) resource.TestCheckFunc {
return fmt.Errorf("Resource's ID is not set.") return fmt.Errorf("Resource's ID is not set.")
} }
mgmtClient := testAccProvider.Meta().(*Client).mgmtClient hostedServiceClient := testAccProvider.Meta().(*Client).hostedServiceClient
_, err := hostedservice.NewClient(mgmtClient).GetHostedService(resource.Primary.ID) _, err := hostedServiceClient.GetHostedService(resource.Primary.ID)
return err return err
} }
} }
func testAccCheckAzureHostedServiceDestroyed(s *terraform.State) error { func testAccCheckAzureHostedServiceDestroyed(s *terraform.State) error {
mgmtClient := testAccProvider.Meta().(*Client).mgmtClient hostedServiceClient := testAccProvider.Meta().(*Client).hostedServiceClient
for _, resource := range s.RootModule().Resources { for _, resource := range s.RootModule().Resources {
if resource.Type != "azure_hosted_service" { if resource.Type != "azure_hosted_service" {
@ -96,7 +95,7 @@ func testAccCheckAzureHostedServiceDestroyed(s *terraform.State) error {
return fmt.Errorf("No Azure Hosted Service Resource found.") return fmt.Errorf("No Azure Hosted Service Resource found.")
} }
_, err := hostedservice.NewClient(mgmtClient).GetHostedService(resource.Primary.ID) _, err := hostedServiceClient.GetHostedService(resource.Primary.ID)
return testAccResourceDestroyedErrorFilter("Hosted Service", err) return testAccResourceDestroyedErrorFilter("Hosted Service", err)
} }

View File

@ -168,7 +168,10 @@ func resourceAzureInstance() *schema.Resource {
} }
func resourceAzureInstanceCreate(d *schema.ResourceData, meta interface{}) (err error) { func resourceAzureInstanceCreate(d *schema.ResourceData, meta interface{}) (err error) {
mc := meta.(*Client).mgmtClient azureClient := meta.(*Client)
mc := azureClient.mgmtClient
hostedServiceClient := azureClient.hostedServiceClient
vmClient := azureClient.vmClient
name := d.Get("name").(string) name := d.Get("name").(string)
@ -180,7 +183,7 @@ func resourceAzureInstanceCreate(d *schema.ResourceData, meta interface{}) (err
// Retrieve the needed details of the image // Retrieve the needed details of the image
configureForImage, osType, err := retrieveImageDetails( configureForImage, osType, err := retrieveImageDetails(
mc, meta,
d.Get("image").(string), d.Get("image").(string),
name, name,
d.Get("storage_service_name").(string), d.Get("storage_service_name").(string),
@ -203,7 +206,7 @@ func resourceAzureInstanceCreate(d *schema.ResourceData, meta interface{}) (err
} }
log.Printf("[DEBUG] Creating Cloud Service for instance: %s", name) log.Printf("[DEBUG] Creating Cloud Service for instance: %s", name)
err = hostedservice.NewClient(mc).CreateHostedService(p) err = hostedServiceClient.CreateHostedService(p)
if err != nil { if err != nil {
return fmt.Errorf("Error creating Cloud Service for instance %s: %s", name, err) return fmt.Errorf("Error creating Cloud Service for instance %s: %s", name, err)
} }
@ -212,7 +215,7 @@ func resourceAzureInstanceCreate(d *schema.ResourceData, meta interface{}) (err
// when we exit with an error // when we exit with an error
defer func(mc management.Client) { defer func(mc management.Client) {
if err != nil { if err != nil {
req, err := hostedservice.NewClient(mc).DeleteHostedService(name, true) req, err := hostedServiceClient.DeleteHostedService(name, true)
if err != nil { if err != nil {
log.Printf("[DEBUG] Error cleaning up Cloud Service of instance %s: %s", name, err) log.Printf("[DEBUG] Error cleaning up Cloud Service of instance %s: %s", name, err)
} }
@ -309,7 +312,7 @@ func resourceAzureInstanceCreate(d *schema.ResourceData, meta interface{}) (err
} }
log.Printf("[DEBUG] Creating the new instance...") log.Printf("[DEBUG] Creating the new instance...")
req, err := virtualmachine.NewClient(mc).CreateDeployment(role, name, options) req, err := vmClient.CreateDeployment(role, name, options)
if err != nil { if err != nil {
return fmt.Errorf("Error creating instance %s: %s", name, err) return fmt.Errorf("Error creating instance %s: %s", name, err)
} }
@ -326,10 +329,12 @@ func resourceAzureInstanceCreate(d *schema.ResourceData, meta interface{}) (err
} }
func resourceAzureInstanceRead(d *schema.ResourceData, meta interface{}) error { func resourceAzureInstanceRead(d *schema.ResourceData, meta interface{}) error {
mc := meta.(*Client).mgmtClient azureClient := meta.(*Client)
hostedServiceClient := azureClient.hostedServiceClient
vmClient := azureClient.vmClient
log.Printf("[DEBUG] Retrieving Cloud Service for instance: %s", d.Id()) log.Printf("[DEBUG] Retrieving Cloud Service for instance: %s", d.Id())
cs, err := hostedservice.NewClient(mc).GetHostedService(d.Id()) cs, err := hostedServiceClient.GetHostedService(d.Id())
if err != nil { if err != nil {
return fmt.Errorf("Error retrieving Cloud Service of instance %s: %s", d.Id(), err) return fmt.Errorf("Error retrieving Cloud Service of instance %s: %s", d.Id(), err)
} }
@ -338,7 +343,7 @@ func resourceAzureInstanceRead(d *schema.ResourceData, meta interface{}) error {
d.Set("location", cs.Location) d.Set("location", cs.Location)
log.Printf("[DEBUG] Retrieving instance: %s", d.Id()) log.Printf("[DEBUG] Retrieving instance: %s", d.Id())
dpmt, err := virtualmachine.NewClient(mc).GetDeployment(d.Id(), d.Id()) dpmt, err := vmClient.GetDeployment(d.Id(), d.Id())
if err != nil { if err != nil {
if management.IsResourceNotFoundError(err) { if management.IsResourceNotFoundError(err) {
d.SetId("") d.SetId("")
@ -420,7 +425,9 @@ func resourceAzureInstanceRead(d *schema.ResourceData, meta interface{}) error {
} }
func resourceAzureInstanceUpdate(d *schema.ResourceData, meta interface{}) error { func resourceAzureInstanceUpdate(d *schema.ResourceData, meta interface{}) error {
mc := meta.(*Client).mgmtClient azureClient := meta.(*Client)
mc := azureClient.mgmtClient
vmClient := azureClient.vmClient
// First check if anything we can update changed, and if not just return // First check if anything we can update changed, and if not just return
if !d.HasChange("size") && !d.HasChange("endpoint") && !d.HasChange("security_group") { if !d.HasChange("size") && !d.HasChange("endpoint") && !d.HasChange("security_group") {
@ -428,7 +435,7 @@ func resourceAzureInstanceUpdate(d *schema.ResourceData, meta interface{}) error
} }
// Get the current role // Get the current role
role, err := virtualmachine.NewClient(mc).GetRole(d.Id(), d.Id(), d.Id()) role, err := vmClient.GetRole(d.Id(), d.Id(), d.Id())
if err != nil { if err != nil {
return fmt.Errorf("Error retrieving role of instance %s: %s", d.Id(), err) return fmt.Errorf("Error retrieving role of instance %s: %s", d.Id(), err)
} }
@ -482,7 +489,7 @@ func resourceAzureInstanceUpdate(d *schema.ResourceData, meta interface{}) error
} }
// Update the adjusted role // Update the adjusted role
req, err := virtualmachine.NewClient(mc).UpdateRole(d.Id(), d.Id(), d.Id(), *role) req, err := vmClient.UpdateRole(d.Id(), d.Id(), d.Id(), *role)
if err != nil { if err != nil {
return fmt.Errorf("Error updating role of instance %s: %s", d.Id(), err) return fmt.Errorf("Error updating role of instance %s: %s", d.Id(), err)
} }
@ -496,10 +503,12 @@ func resourceAzureInstanceUpdate(d *schema.ResourceData, meta interface{}) error
} }
func resourceAzureInstanceDelete(d *schema.ResourceData, meta interface{}) error { func resourceAzureInstanceDelete(d *schema.ResourceData, meta interface{}) error {
mc := meta.(*Client).mgmtClient azureClient := meta.(*Client)
mc := azureClient.mgmtClient
hostedServiceClient := azureClient.hostedServiceClient
log.Printf("[DEBUG] Deleting instance: %s", d.Id()) log.Printf("[DEBUG] Deleting instance: %s", d.Id())
req, err := hostedservice.NewClient(mc).DeleteHostedService(d.Id(), true) req, err := hostedServiceClient.DeleteHostedService(d.Id(), true)
if err != nil { if err != nil {
return fmt.Errorf("Error deleting instance %s: %s", d.Id(), err) return fmt.Errorf("Error deleting instance %s: %s", d.Id(), err)
} }
@ -527,16 +536,21 @@ func resourceAzureEndpointHash(v interface{}) int {
} }
func retrieveImageDetails( func retrieveImageDetails(
mc management.Client, meta interface{},
label string, label string,
name string, name string,
storage string) (func(*virtualmachine.Role) error, string, error) { storage string) (func(*virtualmachine.Role) error, string, error) {
configureForImage, osType, VMLabels, err := retrieveVMImageDetails(mc, label)
azureClient := meta.(*Client)
vmImageClient := azureClient.vmImageClient
osImageClient := azureClient.osImageClient
configureForImage, osType, VMLabels, err := retrieveVMImageDetails(vmImageClient, label)
if err == nil { if err == nil {
return configureForImage, osType, nil return configureForImage, osType, nil
} }
configureForImage, osType, OSLabels, err := retrieveOSImageDetails(mc, label, name, storage) configureForImage, osType, OSLabels, err := retrieveOSImageDetails(osImageClient, label, name, storage)
if err == nil { if err == nil {
return configureForImage, osType, nil return configureForImage, osType, nil
} }
@ -546,9 +560,9 @@ func retrieveImageDetails(
} }
func retrieveVMImageDetails( func retrieveVMImageDetails(
mc management.Client, vmImageClient virtualmachineimage.Client,
label string) (func(*virtualmachine.Role) error, string, []string, error) { label string) (func(*virtualmachine.Role) error, string, []string, error) {
imgs, err := virtualmachineimage.NewClient(mc).ListVirtualMachineImages() imgs, err := vmImageClient.ListVirtualMachineImages()
if err != nil { if err != nil {
return nil, "", nil, fmt.Errorf("Error retrieving image details: %s", err) return nil, "", nil, fmt.Errorf("Error retrieving image details: %s", err)
} }
@ -579,11 +593,11 @@ func retrieveVMImageDetails(
} }
func retrieveOSImageDetails( func retrieveOSImageDetails(
mc management.Client, osImageClient osimage.OSImageClient,
label string, label string,
name string, name string,
storage string) (func(*virtualmachine.Role) error, string, []string, error) { storage string) (func(*virtualmachine.Role) error, string, []string, error) {
imgs, err := osimage.NewClient(mc).ListOSImages() imgs, err := osImageClient.ListOSImages()
if err != nil { if err != nil {
return nil, "", nil, fmt.Errorf("Error retrieving image details: %s", err) return nil, "", nil, fmt.Errorf("Error retrieving image details: %s", err)
} }

View File

@ -5,7 +5,6 @@ import (
"testing" "testing"
"github.com/Azure/azure-sdk-for-go/management" "github.com/Azure/azure-sdk-for-go/management"
"github.com/Azure/azure-sdk-for-go/management/hostedservice"
"github.com/Azure/azure-sdk-for-go/management/virtualmachine" "github.com/Azure/azure-sdk-for-go/management/virtualmachine"
"github.com/hashicorp/terraform/helper/resource" "github.com/hashicorp/terraform/helper/resource"
"github.com/hashicorp/terraform/terraform" "github.com/hashicorp/terraform/terraform"
@ -131,8 +130,8 @@ func testAccCheckAzureInstanceExists(
return fmt.Errorf("No instance ID is set") return fmt.Errorf("No instance ID is set")
} }
mc := testAccProvider.Meta().(*Client).mgmtClient vmClient := testAccProvider.Meta().(*Client).vmClient
vm, err := virtualmachine.NewClient(mc).GetDeployment(rs.Primary.ID, rs.Primary.ID) vm, err := vmClient.GetDeployment(rs.Primary.ID, rs.Primary.ID)
if err != nil { if err != nil {
return err return err
} }
@ -283,7 +282,7 @@ func testAccCheckAzureInstanceUpdatedAttributes(
} }
func testAccCheckAzureInstanceDestroy(s *terraform.State) error { func testAccCheckAzureInstanceDestroy(s *terraform.State) error {
mc := testAccProvider.Meta().(*Client).mgmtClient hostedServiceClient := testAccProvider.Meta().(*Client).hostedServiceClient
for _, rs := range s.RootModule().Resources { for _, rs := range s.RootModule().Resources {
if rs.Type != "azure_instance" { if rs.Type != "azure_instance" {
@ -294,7 +293,7 @@ func testAccCheckAzureInstanceDestroy(s *terraform.State) error {
return fmt.Errorf("No instance ID is set") return fmt.Errorf("No instance ID is set")
} }
_, err := hostedservice.NewClient(mc).GetHostedService(rs.Primary.ID) _, err := hostedServiceClient.GetHostedService(rs.Primary.ID)
if err == nil { if err == nil {
return fmt.Errorf("Instance %s still exists", rs.Primary.ID) return fmt.Errorf("Instance %s still exists", rs.Primary.ID)
} }

View File

@ -47,12 +47,12 @@ func resourceAzureLocalNetworkConnection() *schema.Resource {
func resourceAzureLocalNetworkConnectionCreate(d *schema.ResourceData, meta interface{}) error { func resourceAzureLocalNetworkConnectionCreate(d *schema.ResourceData, meta interface{}) error {
azureClient := meta.(*Client) azureClient := meta.(*Client)
mgmtClient := azureClient.mgmtClient mgmtClient := azureClient.mgmtClient
networkClient := virtualnetwork.NewClient(mgmtClient) vnetClient := azureClient.vnetClient
log.Println("[INFO] Fetching current network configuration from Azure.") log.Println("[INFO] Fetching current network configuration from Azure.")
azureClient.mutex.Lock() azureClient.mutex.Lock()
defer azureClient.mutex.Unlock() defer azureClient.mutex.Unlock()
netConf, err := networkClient.GetVirtualNetworkConfiguration() netConf, err := vnetClient.GetVirtualNetworkConfiguration()
if err != nil { if err != nil {
return fmt.Errorf("Failed to get the current network configuration from Azure: %s", err) return fmt.Errorf("Failed to get the current network configuration from Azure: %s", err)
} }
@ -77,7 +77,7 @@ func resourceAzureLocalNetworkConnectionCreate(d *schema.ResourceData, meta inte
// send the configuration back to Azure: // send the configuration back to Azure:
log.Println("[INFO] Sending updated network configuration back to Azure.") log.Println("[INFO] Sending updated network configuration back to Azure.")
reqID, err := networkClient.SetVirtualNetworkConfiguration(netConf) reqID, err := vnetClient.SetVirtualNetworkConfiguration(netConf)
if err != nil { if err != nil {
return fmt.Errorf("Failed setting updated network configuration: %s", err) return fmt.Errorf("Failed setting updated network configuration: %s", err)
} }
@ -94,11 +94,10 @@ func resourceAzureLocalNetworkConnectionCreate(d *schema.ResourceData, meta inte
// read the state of our local natwork from Azure. // read the state of our local natwork from Azure.
func resourceAzureLocalNetworkConnectionRead(d *schema.ResourceData, meta interface{}) error { func resourceAzureLocalNetworkConnectionRead(d *schema.ResourceData, meta interface{}) error {
azureClient := meta.(*Client) azureClient := meta.(*Client)
mgmtClient := azureClient.mgmtClient vnetClient := azureClient.vnetClient
networkClient := virtualnetwork.NewClient(mgmtClient)
log.Println("[INFO] Fetching current network configuration from Azure.") log.Println("[INFO] Fetching current network configuration from Azure.")
netConf, err := networkClient.GetVirtualNetworkConfiguration() netConf, err := vnetClient.GetVirtualNetworkConfiguration()
if err != nil { if err != nil {
return fmt.Errorf("Failed to get the current network configuration from Azure: %s", err) return fmt.Errorf("Failed to get the current network configuration from Azure: %s", err)
} }
@ -130,12 +129,12 @@ func resourceAzureLocalNetworkConnectionRead(d *schema.ResourceData, meta interf
func resourceAzureLocalNetworkConnectionUpdate(d *schema.ResourceData, meta interface{}) error { func resourceAzureLocalNetworkConnectionUpdate(d *schema.ResourceData, meta interface{}) error {
azureClient := meta.(*Client) azureClient := meta.(*Client)
mgmtClient := azureClient.mgmtClient mgmtClient := azureClient.mgmtClient
networkClient := virtualnetwork.NewClient(mgmtClient) vnetClient := azureClient.vnetClient
log.Println("[INFO] Fetching current network configuration from Azure.") log.Println("[INFO] Fetching current network configuration from Azure.")
azureClient.mutex.Lock() azureClient.mutex.Lock()
defer azureClient.mutex.Unlock() defer azureClient.mutex.Unlock()
netConf, err := networkClient.GetVirtualNetworkConfiguration() netConf, err := vnetClient.GetVirtualNetworkConfiguration()
if err != nil { if err != nil {
return fmt.Errorf("Failed to get the current network configuration from Azure: %s", err) return fmt.Errorf("Failed to get the current network configuration from Azure: %s", err)
} }
@ -169,7 +168,7 @@ func resourceAzureLocalNetworkConnectionUpdate(d *schema.ResourceData, meta inte
} else if cvpn || cprefixes { } else if cvpn || cprefixes {
// else, send the configuration back to Azure: // else, send the configuration back to Azure:
log.Println("[INFO] Sending updated network configuration back to Azure.") log.Println("[INFO] Sending updated network configuration back to Azure.")
reqID, err := networkClient.SetVirtualNetworkConfiguration(netConf) reqID, err := vnetClient.SetVirtualNetworkConfiguration(netConf)
if err != nil { if err != nil {
return fmt.Errorf("Failed setting updated network configuration: %s", err) return fmt.Errorf("Failed setting updated network configuration: %s", err)
} }
@ -185,12 +184,10 @@ func resourceAzureLocalNetworkConnectionUpdate(d *schema.ResourceData, meta inte
// resourceAzureLocalNetworkConnectionExists does all the necessary API calls // resourceAzureLocalNetworkConnectionExists does all the necessary API calls
// to check if the local network already exists on Azure. // to check if the local network already exists on Azure.
func resourceAzureLocalNetworkConnectionExists(d *schema.ResourceData, meta interface{}) (bool, error) { func resourceAzureLocalNetworkConnectionExists(d *schema.ResourceData, meta interface{}) (bool, error) {
azureClient := meta.(*Client) vnetClient := meta.(*Client).vnetClient
mgmtClient := azureClient.mgmtClient
networkClient := virtualnetwork.NewClient(mgmtClient)
log.Println("[INFO] Fetching current network configuration from Azure.") log.Println("[INFO] Fetching current network configuration from Azure.")
netConf, err := networkClient.GetVirtualNetworkConfiguration() netConf, err := vnetClient.GetVirtualNetworkConfiguration()
if err != nil { if err != nil {
return false, fmt.Errorf("Failed to get the current network configuration from Azure: %s", err) return false, fmt.Errorf("Failed to get the current network configuration from Azure: %s", err)
} }
@ -211,12 +208,12 @@ func resourceAzureLocalNetworkConnectionExists(d *schema.ResourceData, meta inte
func resourceAzureLocalNetworkConnectionDelete(d *schema.ResourceData, meta interface{}) error { func resourceAzureLocalNetworkConnectionDelete(d *schema.ResourceData, meta interface{}) error {
azureClient := meta.(*Client) azureClient := meta.(*Client)
mgmtClient := azureClient.mgmtClient mgmtClient := azureClient.mgmtClient
networkClient := virtualnetwork.NewClient(mgmtClient) vnetClient := azureClient.vnetClient
log.Println("[INFO] Fetching current network configuration from Azure.") log.Println("[INFO] Fetching current network configuration from Azure.")
azureClient.mutex.Lock() azureClient.mutex.Lock()
defer azureClient.mutex.Unlock() defer azureClient.mutex.Unlock()
netConf, err := networkClient.GetVirtualNetworkConfiguration() netConf, err := vnetClient.GetVirtualNetworkConfiguration()
if err != nil { if err != nil {
return fmt.Errorf("Failed to get the current network configuration from Azure: %s", err) return fmt.Errorf("Failed to get the current network configuration from Azure: %s", err)
} }
@ -236,7 +233,7 @@ func resourceAzureLocalNetworkConnectionDelete(d *schema.ResourceData, meta inte
// send the configuration back to Azure: // send the configuration back to Azure:
log.Println("[INFO] Sending updated network configuration back to Azure.") log.Println("[INFO] Sending updated network configuration back to Azure.")
reqID, err := networkClient.SetVirtualNetworkConfiguration(netConf) reqID, err := vnetClient.SetVirtualNetworkConfiguration(netConf)
if err != nil { if err != nil {
return fmt.Errorf("Failed setting updated network configuration: %s", err) return fmt.Errorf("Failed setting updated network configuration: %s", err)
} }

View File

@ -4,7 +4,6 @@ import (
"fmt" "fmt"
"testing" "testing"
"github.com/Azure/azure-sdk-for-go/management/virtualnetwork"
"github.com/hashicorp/terraform/helper/resource" "github.com/hashicorp/terraform/helper/resource"
"github.com/hashicorp/terraform/terraform" "github.com/hashicorp/terraform/terraform"
) )
@ -77,8 +76,8 @@ func testAccAzureLocalNetworkConnectionExists(name string) resource.TestCheckFun
return fmt.Errorf("Azure Local Network Connection ID not set.") return fmt.Errorf("Azure Local Network Connection ID not set.")
} }
mgmtClient := testAccProvider.Meta().(*Client).mgmtClient vnetClient := testAccProvider.Meta().(*Client).vnetClient
netConf, err := virtualnetwork.NewClient(mgmtClient).GetVirtualNetworkConfiguration() netConf, err := vnetClient.GetVirtualNetworkConfiguration()
if err != nil { if err != nil {
return err return err
} }
@ -97,7 +96,7 @@ func testAccAzureLocalNetworkConnectionExists(name string) resource.TestCheckFun
// testAccAzureLocalNetworkConnectionDestroyed checks whether the local network // testAccAzureLocalNetworkConnectionDestroyed checks whether the local network
// connection has been destroyed on Azure or not. // connection has been destroyed on Azure or not.
func testAccAzureLocalNetworkConnectionDestroyed(s *terraform.State) error { func testAccAzureLocalNetworkConnectionDestroyed(s *terraform.State) error {
mgmtClient := testAccProvider.Meta().(*Client).mgmtClient vnetClient := testAccProvider.Meta().(*Client).vnetClient
for _, resource := range s.RootModule().Resources { for _, resource := range s.RootModule().Resources {
if resource.Type != "azure_local_network_connection" { if resource.Type != "azure_local_network_connection" {
@ -108,7 +107,7 @@ func testAccAzureLocalNetworkConnectionDestroyed(s *terraform.State) error {
return fmt.Errorf("Azure Local Network Connection ID not set.") return fmt.Errorf("Azure Local Network Connection ID not set.")
} }
netConf, err := virtualnetwork.NewClient(mgmtClient).GetVirtualNetworkConfiguration() netConf, err := vnetClient.GetVirtualNetworkConfiguration()
if err != nil { if err != nil {
return err return err
} }

View File

@ -5,7 +5,6 @@ import (
"log" "log"
"github.com/Azure/azure-sdk-for-go/management" "github.com/Azure/azure-sdk-for-go/management"
"github.com/Azure/azure-sdk-for-go/management/networksecuritygroup"
"github.com/hashicorp/terraform/helper/schema" "github.com/hashicorp/terraform/helper/schema"
) )
@ -39,7 +38,9 @@ func resourceAzureSecurityGroup() *schema.Resource {
} }
func resourceAzureSecurityGroupCreate(d *schema.ResourceData, meta interface{}) (err error) { func resourceAzureSecurityGroupCreate(d *schema.ResourceData, meta interface{}) (err error) {
mc := meta.(*Client).mgmtClient azureClient := meta.(*Client)
mc := azureClient.mgmtClient
secGroupClient := azureClient.secGroupClient
name := d.Get("name").(string) name := d.Get("name").(string)
@ -49,7 +50,7 @@ func resourceAzureSecurityGroupCreate(d *schema.ResourceData, meta interface{})
label = name label = name
} }
req, err := networksecuritygroup.NewClient(mc).CreateNetworkSecurityGroup( req, err := secGroupClient.CreateNetworkSecurityGroup(
name, name,
label, label,
d.Get("location").(string), d.Get("location").(string),
@ -69,9 +70,9 @@ func resourceAzureSecurityGroupCreate(d *schema.ResourceData, meta interface{})
} }
func resourceAzureSecurityGroupRead(d *schema.ResourceData, meta interface{}) error { func resourceAzureSecurityGroupRead(d *schema.ResourceData, meta interface{}) error {
mc := meta.(*Client).mgmtClient secGroupClient := meta.(*Client).secGroupClient
sg, err := networksecuritygroup.NewClient(mc).GetNetworkSecurityGroup(d.Id()) sg, err := secGroupClient.GetNetworkSecurityGroup(d.Id())
if err != nil { if err != nil {
if management.IsResourceNotFoundError(err) { if management.IsResourceNotFoundError(err) {
d.SetId("") d.SetId("")
@ -87,10 +88,12 @@ func resourceAzureSecurityGroupRead(d *schema.ResourceData, meta interface{}) er
} }
func resourceAzureSecurityGroupDelete(d *schema.ResourceData, meta interface{}) error { func resourceAzureSecurityGroupDelete(d *schema.ResourceData, meta interface{}) error {
mc := meta.(*Client).mgmtClient azureClient := meta.(*Client)
mc := azureClient.mgmtClient
secGroupClient := azureClient.secGroupClient
log.Printf("[DEBUG] Deleting Network Security Group: %s", d.Id()) log.Printf("[DEBUG] Deleting Network Security Group: %s", d.Id())
req, err := networksecuritygroup.NewClient(mc).DeleteNetworkSecurityGroup(d.Id()) req, err := secGroupClient.DeleteNetworkSecurityGroup(d.Id())
if err != nil { if err != nil {
return fmt.Errorf("Error deleting Network Security Group %s: %s", d.Id(), err) return fmt.Errorf("Error deleting Network Security Group %s: %s", d.Id(), err)
} }

View File

@ -81,7 +81,7 @@ func resourceAzureSecurityGroupRule() *schema.Resource {
func resourceAzureSecurityGroupRuleCreate(d *schema.ResourceData, meta interface{}) error { func resourceAzureSecurityGroupRuleCreate(d *schema.ResourceData, meta interface{}) error {
azureClient := meta.(*Client) azureClient := meta.(*Client)
mgmtClient := azureClient.mgmtClient mgmtClient := azureClient.mgmtClient
netSecClient := netsecgroup.NewClient(mgmtClient) secGroupClient := azureClient.secGroupClient
// create and configure the RuleResponse: // create and configure the RuleResponse:
name := d.Get("name").(string) name := d.Get("name").(string)
@ -99,7 +99,7 @@ func resourceAzureSecurityGroupRuleCreate(d *schema.ResourceData, meta interface
// send the create request to Azure: // send the create request to Azure:
log.Println("[INFO] Sending network security group rule creation request to Azure.") log.Println("[INFO] Sending network security group rule creation request to Azure.")
reqID, err := netSecClient.SetNetworkSecurityGroupRule( reqID, err := secGroupClient.SetNetworkSecurityGroupRule(
d.Get("security_group_name").(string), d.Get("security_group_name").(string),
rule, rule,
) )
@ -119,14 +119,13 @@ func resourceAzureSecurityGroupRuleCreate(d *schema.ResourceData, meta interface
// read the state of a network security group ruke off Azure. // read the state of a network security group ruke off Azure.
func resourceAzureSecurityGroupRuleRead(d *schema.ResourceData, meta interface{}) error { func resourceAzureSecurityGroupRuleRead(d *schema.ResourceData, meta interface{}) error {
azureClient := meta.(*Client) azureClient := meta.(*Client)
mgmtClient := azureClient.mgmtClient secGroupClient := azureClient.secGroupClient
netSecClient := netsecgroup.NewClient(mgmtClient)
secGroupName := d.Get("security_group_name").(string) secGroupName := d.Get("security_group_name").(string)
// get info on the network security group and check its rules for this one: // get info on the network security group and check its rules for this one:
log.Println("[INFO] Sending network security group rule query to Azure.") log.Println("[INFO] Sending network security group rule query to Azure.")
secgroup, err := netSecClient.GetNetworkSecurityGroup(secGroupName) secgroup, err := secGroupClient.GetNetworkSecurityGroup(secGroupName)
if err != nil { if err != nil {
if !management.IsResourceNotFoundError(err) { if !management.IsResourceNotFoundError(err) {
return fmt.Errorf("Error issuing network security group rules query: %s", err) return fmt.Errorf("Error issuing network security group rules query: %s", err)
@ -171,13 +170,13 @@ func resourceAzureSecurityGroupRuleRead(d *schema.ResourceData, meta interface{}
func resourceAzureSecurityGroupRuleUpdate(d *schema.ResourceData, meta interface{}) error { func resourceAzureSecurityGroupRuleUpdate(d *schema.ResourceData, meta interface{}) error {
azureClient := meta.(*Client) azureClient := meta.(*Client)
mgmtClient := azureClient.mgmtClient mgmtClient := azureClient.mgmtClient
netSecClient := netsecgroup.NewClient(mgmtClient) secGroupClient := azureClient.secGroupClient
secGroupName := d.Get("security_group_name").(string) secGroupName := d.Get("security_group_name").(string)
// get info on the network security group and check its rules for this one: // get info on the network security group and check its rules for this one:
log.Println("[INFO] Sending network security group rule query for update to Azure.") log.Println("[INFO] Sending network security group rule query for update to Azure.")
secgroup, err := netSecClient.GetNetworkSecurityGroup(secGroupName) secgroup, err := secGroupClient.GetNetworkSecurityGroup(secGroupName)
if err != nil { if err != nil {
if !management.IsResourceNotFoundError(err) { if !management.IsResourceNotFoundError(err) {
return fmt.Errorf("Error issuing network security group rules query: %s", err) return fmt.Errorf("Error issuing network security group rules query: %s", err)
@ -219,7 +218,7 @@ func resourceAzureSecurityGroupRuleUpdate(d *schema.ResourceData, meta interface
// send the create request to Azure: // send the create request to Azure:
log.Println("[INFO] Sending network security group rule update request to Azure.") log.Println("[INFO] Sending network security group rule update request to Azure.")
reqID, err := netSecClient.SetNetworkSecurityGroupRule( reqID, err := secGroupClient.SetNetworkSecurityGroupRule(
secGroupName, secGroupName,
newRule, newRule,
) )
@ -237,15 +236,13 @@ func resourceAzureSecurityGroupRuleUpdate(d *schema.ResourceData, meta interface
// resourceAzureSecurityGroupRuleExists does all the necessary API calls to // resourceAzureSecurityGroupRuleExists does all the necessary API calls to
// check for the existence of the network security group rule on Azure. // check for the existence of the network security group rule on Azure.
func resourceAzureSecurityGroupRuleExists(d *schema.ResourceData, meta interface{}) (bool, error) { func resourceAzureSecurityGroupRuleExists(d *schema.ResourceData, meta interface{}) (bool, error) {
azureClient := meta.(*Client) secGroupClient := meta.(*Client).secGroupClient
mgmtClient := azureClient.mgmtClient
netSecClient := netsecgroup.NewClient(mgmtClient)
secGroupName := d.Get("security_group_name").(string) secGroupName := d.Get("security_group_name").(string)
// get info on the network security group and search for our rule: // get info on the network security group and search for our rule:
log.Println("[INFO] Sending network security group rule query for existence check to Azure.") log.Println("[INFO] Sending network security group rule query for existence check to Azure.")
secgroup, err := netSecClient.GetNetworkSecurityGroup(secGroupName) secgroup, err := secGroupClient.GetNetworkSecurityGroup(secGroupName)
if err != nil { if err != nil {
if !management.IsResourceNotFoundError(err) { if !management.IsResourceNotFoundError(err) {
return false, fmt.Errorf("Error issuing network security group rules query: %s", err) return false, fmt.Errorf("Error issuing network security group rules query: %s", err)
@ -277,13 +274,13 @@ func resourceAzureSecurityGroupRuleExists(d *schema.ResourceData, meta interface
func resourceAzureSecurityGroupRuleDelete(d *schema.ResourceData, meta interface{}) error { func resourceAzureSecurityGroupRuleDelete(d *schema.ResourceData, meta interface{}) error {
azureClient := meta.(*Client) azureClient := meta.(*Client)
mgmtClient := azureClient.mgmtClient mgmtClient := azureClient.mgmtClient
netSecClient := netsecgroup.NewClient(mgmtClient) secGroupClient := azureClient.secGroupClient
secGroupName := d.Get("security_group_name").(string) secGroupName := d.Get("security_group_name").(string)
// get info on the network security group and search for our rule: // get info on the network security group and search for our rule:
log.Println("[INFO] Sending network security group rule query for deletion to Azure.") log.Println("[INFO] Sending network security group rule query for deletion to Azure.")
secgroup, err := netSecClient.GetNetworkSecurityGroup(secGroupName) secgroup, err := secGroupClient.GetNetworkSecurityGroup(secGroupName)
if err != nil { if err != nil {
if management.IsResourceNotFoundError(err) { if management.IsResourceNotFoundError(err) {
// it meants that the network security group this rule belonged to has // it meants that the network security group this rule belonged to has
@ -300,7 +297,7 @@ func resourceAzureSecurityGroupRuleDelete(d *schema.ResourceData, meta interface
for _, rule := range secgroup.Rules { for _, rule := range secgroup.Rules {
if rule.Name == name { if rule.Name == name {
// if not; we shall issue the delete: // if not; we shall issue the delete:
reqID, err := netSecClient.DeleteNetworkSecurityGroupRule(secGroupName, name) reqID, err := secGroupClient.DeleteNetworkSecurityGroupRule(secGroupName, name)
if err != nil { if err != nil {
return fmt.Errorf("Error sending network security group rule delete request to Azure: %s", err) return fmt.Errorf("Error sending network security group rule delete request to Azure: %s", err)
} }

View File

@ -4,7 +4,6 @@ import (
"fmt" "fmt"
"testing" "testing"
netsecgroup "github.com/Azure/azure-sdk-for-go/management/networksecuritygroup"
"github.com/hashicorp/terraform/helper/resource" "github.com/hashicorp/terraform/helper/resource"
"github.com/hashicorp/terraform/terraform" "github.com/hashicorp/terraform/terraform"
) )
@ -47,8 +46,7 @@ func testAccCheckAzureSecurityGroupRuleExists(name string) resource.TestCheckFun
return fmt.Errorf("Azure network security group rule ID not set: %s", name) return fmt.Errorf("Azure network security group rule ID not set: %s", name)
} }
mgmtClient := testAccProvider.Meta().(*Client).mgmtClient secGroupClient := testAccProvider.Meta().(*Client).secGroupClient
secGroupClient := netsecgroup.NewClient(mgmtClient)
secGroup, err := secGroupClient.GetNetworkSecurityGroup(testAccSecurityGroupName) secGroup, err := secGroupClient.GetNetworkSecurityGroup(testAccSecurityGroupName)
if err != nil { if err != nil {
@ -75,8 +73,7 @@ func testAccCheckAzureSecurityGroupRuleDeleted(s *terraform.State) error {
return fmt.Errorf("Azure network security group ID not set.") return fmt.Errorf("Azure network security group ID not set.")
} }
mgmtClient := testAccProvider.Meta().(*Client).mgmtClient secGroupClient := testAccProvider.Meta().(*Client).secGroupClient
secGroupClient := netsecgroup.NewClient(mgmtClient)
secGroup, err := secGroupClient.GetNetworkSecurityGroup(testAccSecurityGroupName) secGroup, err := secGroupClient.GetNetworkSecurityGroup(testAccSecurityGroupName)
if err != nil { if err != nil {

View File

@ -48,8 +48,8 @@ func testAccCheckAzureSecurityGroupExists(
return fmt.Errorf("No Network Security Group ID is set") return fmt.Errorf("No Network Security Group ID is set")
} }
mc := testAccProvider.Meta().(*Client).mgmtClient secGroupClient := testAccProvider.Meta().(*Client).secGroupClient
sg, err := networksecuritygroup.NewClient(mc).GetNetworkSecurityGroup(rs.Primary.ID) sg, err := secGroupClient.GetNetworkSecurityGroup(rs.Primary.ID)
if err != nil { if err != nil {
return err return err
} }
@ -65,7 +65,7 @@ func testAccCheckAzureSecurityGroupExists(
} }
func testAccCheckAzureSecurityGroupDestroy(s *terraform.State) error { func testAccCheckAzureSecurityGroupDestroy(s *terraform.State) error {
mc := testAccProvider.Meta().(*Client).mgmtClient secGroupClient := testAccProvider.Meta().(*Client).secGroupClient
for _, rs := range s.RootModule().Resources { for _, rs := range s.RootModule().Resources {
if rs.Type != "azure_security_group" { if rs.Type != "azure_security_group" {
@ -76,7 +76,7 @@ func testAccCheckAzureSecurityGroupDestroy(s *terraform.State) error {
return fmt.Errorf("No Network Security Group ID is set") return fmt.Errorf("No Network Security Group ID is set")
} }
_, err := networksecuritygroup.NewClient(mc).GetNetworkSecurityGroup(rs.Primary.ID) _, err := secGroupClient.GetNetworkSecurityGroup(rs.Primary.ID)
if err == nil { if err == nil {
return fmt.Errorf("Network Security Group %s still exists", rs.Primary.ID) return fmt.Errorf("Network Security Group %s still exists", rs.Primary.ID)
} }

View File

@ -62,10 +62,10 @@ func resourceAzureStorageBlob() *schema.Resource {
// resourceAzureStorageBlobCreate does all the necessary API calls to // resourceAzureStorageBlobCreate does all the necessary API calls to
// create the storage blob on Azure. // create the storage blob on Azure.
func resourceAzureStorageBlobCreate(d *schema.ResourceData, meta interface{}) error { func resourceAzureStorageBlobCreate(d *schema.ResourceData, meta interface{}) error {
mgmtClient := meta.(*Client).mgmtClient azureClient := meta.(*Client)
storName := d.Get("storage_service_name").(string) storName := d.Get("storage_service_name").(string)
blobClient, err := getStorageServiceBlobClient(mgmtClient, storName) blobClient, err := azureClient.getStorageServiceBlobClient(storName)
if err != nil { if err != nil {
return err return err
} }
@ -94,6 +94,8 @@ func resourceAzureStorageBlobCreate(d *schema.ResourceData, meta interface{}) er
// resourceAzureStorageBlobRead does all the necessary API calls to // resourceAzureStorageBlobRead does all the necessary API calls to
// read the status of the storage blob off Azure. // read the status of the storage blob off Azure.
func resourceAzureStorageBlobRead(d *schema.ResourceData, meta interface{}) error { func resourceAzureStorageBlobRead(d *schema.ResourceData, meta interface{}) error {
azureClient := meta.(*Client)
// check for it's existence: // check for it's existence:
exists, err := resourceAzureStorageBlobExists(d, meta) exists, err := resourceAzureStorageBlobExists(d, meta)
if err != nil { if err != nil {
@ -102,10 +104,9 @@ func resourceAzureStorageBlobRead(d *schema.ResourceData, meta interface{}) erro
// if it exists; read relevant information: // if it exists; read relevant information:
if exists { if exists {
mgmtClient := meta.(*Client).mgmtClient
storName := d.Get("storage_service_name").(string) storName := d.Get("storage_service_name").(string)
blobClient, err := getStorageServiceBlobClient(mgmtClient, storName) blobClient, err := azureClient.getStorageServiceBlobClient(storName)
if err != nil { if err != nil {
return err return err
} }
@ -135,10 +136,10 @@ func resourceAzureStorageBlobUpdate(d *schema.ResourceData, meta interface{}) er
// resourceAzureStorageBlobExists does all the necessary API calls to // resourceAzureStorageBlobExists does all the necessary API calls to
// check for the existence of the blob on Azure. // check for the existence of the blob on Azure.
func resourceAzureStorageBlobExists(d *schema.ResourceData, meta interface{}) (bool, error) { func resourceAzureStorageBlobExists(d *schema.ResourceData, meta interface{}) (bool, error) {
mgmtClient := meta.(*Client).mgmtClient azureClient := meta.(*Client)
storName := d.Get("storage_service_name").(string) storName := d.Get("storage_service_name").(string)
blobClient, err := getStorageServiceBlobClient(mgmtClient, storName) blobClient, err := azureClient.getStorageServiceBlobClient(storName)
if err != nil { if err != nil {
return false, err return false, err
} }
@ -163,10 +164,10 @@ func resourceAzureStorageBlobExists(d *schema.ResourceData, meta interface{}) (b
// resourceAzureStorageBlobDelete does all the necessary API calls to // resourceAzureStorageBlobDelete does all the necessary API calls to
// delete the blob off Azure. // delete the blob off Azure.
func resourceAzureStorageBlobDelete(d *schema.ResourceData, meta interface{}) error { func resourceAzureStorageBlobDelete(d *schema.ResourceData, meta interface{}) error {
mgmtClient := meta.(*Client).mgmtClient azureClient := meta.(*Client)
storName := d.Get("storage_service_name").(string) storName := d.Get("storage_service_name").(string)
blobClient, err := getStorageServiceBlobClient(mgmtClient, storName) blobClient, err := azureClient.getStorageServiceBlobClient(storName)
if err != nil { if err != nil {
return err return err
} }

View File

@ -66,8 +66,8 @@ func testAccCheckAzureStorageBlobExists(name, typ string) resource.TestCheckFunc
return fmt.Errorf("Azure Storage Container ID not set: %s", name) return fmt.Errorf("Azure Storage Container ID not set: %s", name)
} }
mgmtClient := testAccProvider.Meta().(*Client).mgmtClient azureClient := testAccProvider.Meta().(*Client)
blobClient, err := getStorageServiceBlobClient(mgmtClient, testAccStorageServiceName) blobClient, err := azureClient.getStorageServiceBlobClient(testAccStorageServiceName)
if err != nil { if err != nil {
return err return err
} }
@ -92,8 +92,8 @@ func testAccCheckAzureStorageBlobDeleted(typ string) resource.TestCheckFunc {
continue continue
} }
mgmtClient := testAccProvider.Meta().(*Client).mgmtClient azureClient := testAccProvider.Meta().(*Client)
blobClient, err := getStorageServiceBlobClient(mgmtClient, testAccStorageServiceName) blobClient, err := azureClient.getStorageServiceBlobClient(testAccStorageServiceName)
if err != nil { if err != nil {
return err return err
} }

View File

@ -49,10 +49,10 @@ func resourceAzureStorageContainer() *schema.Resource {
// resourceAzureStorageContainerCreate does all the necessary API calls to // resourceAzureStorageContainerCreate does all the necessary API calls to
// create the storage container on Azure. // create the storage container on Azure.
func resourceAzureStorageContainerCreate(d *schema.ResourceData, meta interface{}) error { func resourceAzureStorageContainerCreate(d *schema.ResourceData, meta interface{}) error {
mgmtClient := meta.(*Client).mgmtClient azureClient := meta.(*Client)
storName := d.Get("storage_service_name").(string) storName := d.Get("storage_service_name").(string)
blobClient, err := getStorageServiceBlobClient(mgmtClient, storName) blobClient, err := azureClient.getStorageServiceBlobClient(storName)
if err != nil { if err != nil {
return err return err
} }
@ -72,10 +72,10 @@ func resourceAzureStorageContainerCreate(d *schema.ResourceData, meta interface{
// resourceAzureStorageContainerRead does all the necessary API calls to // resourceAzureStorageContainerRead does all the necessary API calls to
// read the status of the storage container off Azure. // read the status of the storage container off Azure.
func resourceAzureStorageContainerRead(d *schema.ResourceData, meta interface{}) error { func resourceAzureStorageContainerRead(d *schema.ResourceData, meta interface{}) error {
mgmtClient := meta.(*Client).mgmtClient azureClient := meta.(*Client)
storName := d.Get("storage_service_name").(string) storName := d.Get("storage_service_name").(string)
blobClient, err := getStorageServiceBlobClient(mgmtClient, storName) blobClient, err := azureClient.getStorageServiceBlobClient(storName)
if err != nil { if err != nil {
return err return err
} }
@ -119,10 +119,10 @@ func resourceAzureStorageContainerRead(d *schema.ResourceData, meta interface{})
// resourceAzureStorageContainerExists does all the necessary API calls to // resourceAzureStorageContainerExists does all the necessary API calls to
// check if the storage container already exists on Azure. // check if the storage container already exists on Azure.
func resourceAzureStorageContainerExists(d *schema.ResourceData, meta interface{}) (bool, error) { func resourceAzureStorageContainerExists(d *schema.ResourceData, meta interface{}) (bool, error) {
mgmtClient := meta.(*Client).mgmtClient azureClient := meta.(*Client)
storName := d.Get("storage_service_name").(string) storName := d.Get("storage_service_name").(string)
blobClient, err := getStorageServiceBlobClient(mgmtClient, storName) blobClient, err := azureClient.getStorageServiceBlobClient(storName)
if err != nil { if err != nil {
return false, err return false, err
} }
@ -144,10 +144,10 @@ func resourceAzureStorageContainerExists(d *schema.ResourceData, meta interface{
// resourceAzureStorageContainerDelete does all the necessary API calls to // resourceAzureStorageContainerDelete does all the necessary API calls to
// delete a storage container off Azure. // delete a storage container off Azure.
func resourceAzureStorageContainerDelete(d *schema.ResourceData, meta interface{}) error { func resourceAzureStorageContainerDelete(d *schema.ResourceData, meta interface{}) error {
mgmtClient := meta.(*Client).mgmtClient azureClient := meta.(*Client)
storName := d.Get("storage_service_name").(string) storName := d.Get("storage_service_name").(string)
blobClient, err := getStorageServiceBlobClient(mgmtClient, storName) blobClient, err := azureClient.getStorageServiceBlobClient(storName)
if err != nil { if err != nil {
return err return err
} }

View File

@ -44,8 +44,8 @@ func testAccCheckAzureStorageContainerExists(name string) resource.TestCheckFunc
return fmt.Errorf("Azure Storage Container ID not set: %s", name) return fmt.Errorf("Azure Storage Container ID not set: %s", name)
} }
mgmtClient := testAccProvider.Meta().(*Client).mgmtClient azureClient := testAccProvider.Meta().(*Client)
blobClient, err := getStorageServiceBlobClient(mgmtClient, testAccStorageServiceName) blobClient, err := azureClient.getStorageServiceBlobClient(testAccStorageServiceName)
if err != nil { if err != nil {
return err return err
} }
@ -68,8 +68,8 @@ func testAccCheckAzureStorageContainerDestroyed(s *terraform.State) error {
continue continue
} }
mgmtClient := testAccProvider.Meta().(*Client).mgmtClient azureClient := testAccProvider.Meta().(*Client)
blobClient, err := getStorageServiceBlobClient(mgmtClient, testAccStorageServiceName) blobClient, err := azureClient.getStorageServiceBlobClient(testAccStorageServiceName)
if err != nil { if err != nil {
return err return err
} }

View File

@ -35,9 +35,9 @@ func resourceAzureStorageQueue() *schema.Resource {
// resourceAzureStorageQueueCreate does all the necessary API calls to // resourceAzureStorageQueueCreate does all the necessary API calls to
// create a storage queue on Azure. // create a storage queue on Azure.
func resourceAzureStorageQueueCreate(d *schema.ResourceData, meta interface{}) error { func resourceAzureStorageQueueCreate(d *schema.ResourceData, meta interface{}) error {
mgmtClient := meta.(*Client).mgmtClient azureClient := meta.(*Client)
storServName := d.Get("storage_service_name").(string) storServName := d.Get("storage_service_name").(string)
queueClient, err := getStorageServiceQueueClient(mgmtClient, storServName) queueClient, err := azureClient.getStorageServiceQueueClient(storServName)
if err != nil { if err != nil {
return err return err
} }
@ -57,9 +57,9 @@ func resourceAzureStorageQueueCreate(d *schema.ResourceData, meta interface{}) e
// resourceAzureStorageQueueRead does all the necessary API calls to // resourceAzureStorageQueueRead does all the necessary API calls to
// read the state of the storage queue off Azure. // read the state of the storage queue off Azure.
func resourceAzureStorageQueueRead(d *schema.ResourceData, meta interface{}) error { func resourceAzureStorageQueueRead(d *schema.ResourceData, meta interface{}) error {
mgmtClient := meta.(*Client).mgmtClient azureClient := meta.(*Client)
storServName := d.Get("storage_service_name").(string) storServName := d.Get("storage_service_name").(string)
queueClient, err := getStorageServiceQueueClient(mgmtClient, storServName) queueClient, err := azureClient.getStorageServiceQueueClient(storServName)
if err != nil { if err != nil {
return err return err
} }
@ -84,9 +84,9 @@ func resourceAzureStorageQueueRead(d *schema.ResourceData, meta interface{}) err
// resourceAzureStorageQueueDelete does all the necessary API calls to // resourceAzureStorageQueueDelete does all the necessary API calls to
// delete the storage queue off Azure. // delete the storage queue off Azure.
func resourceAzureStorageQueueDelete(d *schema.ResourceData, meta interface{}) error { func resourceAzureStorageQueueDelete(d *schema.ResourceData, meta interface{}) error {
mgmtClient := meta.(*Client).mgmtClient azureClient := meta.(*Client)
storServName := d.Get("storage_service_name").(string) storServName := d.Get("storage_service_name").(string)
queueClient, err := getStorageServiceQueueClient(mgmtClient, storServName) queueClient, err := azureClient.getStorageServiceQueueClient(storServName)
if err != nil { if err != nil {
return err return err
} }

View File

@ -39,8 +39,8 @@ func testAccCheckAzureStorageQueueExists(name string) resource.TestCheckFunc {
return fmt.Errorf("Azure Storage Service Queue ID %s is missing.", name) return fmt.Errorf("Azure Storage Service Queue ID %s is missing.", name)
} }
mgmtClient := testAccProvider.Meta().(*Client).mgmtClient azureClient := testAccProvider.Meta().(*Client)
queueClient, err := getStorageServiceQueueClient(mgmtClient, testAccStorageServiceName) queueClient, err := azureClient.getStorageServiceQueueClient(testAccStorageServiceName)
if err != nil { if err != nil {
return err return err
} }
@ -67,8 +67,8 @@ func testAccCheckAzureStorageQueueDeleted(s *terraform.State) error {
return fmt.Errorf("Azure Storage Service Queue ID %s is missing.", resource.Primary.ID) return fmt.Errorf("Azure Storage Service Queue ID %s is missing.", resource.Primary.ID)
} }
mgmtClient := testAccProvider.Meta().(*Client).mgmtClient azureClient := testAccProvider.Meta().(*Client)
queueClient, err := getStorageServiceQueueClient(mgmtClient, testAccStorageServiceName) queueClient, err := azureClient.getStorageServiceQueueClient(testAccStorageServiceName)
if err != nil { if err != nil {
return err return err
} }

View File

@ -88,7 +88,7 @@ func resourceAzureStorageService() *schema.Resource {
func resourceAzureStorageServiceCreate(d *schema.ResourceData, meta interface{}) error { func resourceAzureStorageServiceCreate(d *schema.ResourceData, meta interface{}) error {
azureClient := meta.(*Client) azureClient := meta.(*Client)
mgmtClient := azureClient.mgmtClient mgmtClient := azureClient.mgmtClient
storageServiceClient := storageservice.NewClient(mgmtClient) storageServiceClient := azureClient.storageServiceClient
// get all the values: // get all the values:
log.Println("[INFO] Creating Azure Storage Service creation parameters.") log.Println("[INFO] Creating Azure Storage Service creation parameters.")
@ -138,9 +138,7 @@ func resourceAzureStorageServiceCreate(d *schema.ResourceData, meta interface{})
// resourceAzureStorageServiceRead does all the necessary API calls to // resourceAzureStorageServiceRead does all the necessary API calls to
// read the state of the storage service off Azure. // read the state of the storage service off Azure.
func resourceAzureStorageServiceRead(d *schema.ResourceData, meta interface{}) error { func resourceAzureStorageServiceRead(d *schema.ResourceData, meta interface{}) error {
azureClient := meta.(*Client) storageServiceClient := meta.(*Client).storageServiceClient
mgmtClient := azureClient.mgmtClient
storageServiceClient := storageservice.NewClient(mgmtClient)
// get our storage service: // get our storage service:
log.Println("[INFO] Sending query about storage service to Azure.") log.Println("[INFO] Sending query about storage service to Azure.")
@ -174,12 +172,7 @@ func resourceAzureStorageServiceRead(d *schema.ResourceData, meta interface{}) e
// resourceAzureStorageServiceExists does all the necessary API calls to // resourceAzureStorageServiceExists does all the necessary API calls to
// check if the storage service exists on Azure. // check if the storage service exists on Azure.
func resourceAzureStorageServiceExists(d *schema.ResourceData, meta interface{}) (bool, error) { func resourceAzureStorageServiceExists(d *schema.ResourceData, meta interface{}) (bool, error) {
azureClient, ok := meta.(*Client) storageServiceClient := meta.(*Client).storageServiceClient
if !ok {
return false, fmt.Errorf("Failed to convert to *Client, got: %T", meta)
}
mgmtClient := azureClient.mgmtClient
storageServiceClient := storageservice.NewClient(mgmtClient)
// get our storage service: // get our storage service:
log.Println("[INFO] Sending query about storage service to Azure.") log.Println("[INFO] Sending query about storage service to Azure.")
@ -203,17 +196,14 @@ func resourceAzureStorageServiceExists(d *schema.ResourceData, meta interface{})
// resourceAzureStorageServiceDelete does all the necessary API calls to // resourceAzureStorageServiceDelete does all the necessary API calls to
// delete the storage service off Azure. // delete the storage service off Azure.
func resourceAzureStorageServiceDelete(d *schema.ResourceData, meta interface{}) error { func resourceAzureStorageServiceDelete(d *schema.ResourceData, meta interface{}) error {
azureClient, ok := meta.(*Client) azureClient := meta.(*Client)
if !ok {
return fmt.Errorf("Failed to convert to *Client, got: %T", meta)
}
mgmtClient := azureClient.mgmtClient mgmtClient := azureClient.mgmtClient
storageClient := storageservice.NewClient(mgmtClient) storageServiceClient := azureClient.storageServiceClient
// issue the deletion: // issue the deletion:
name := d.Get("name").(string) name := d.Get("name").(string)
log.Println("[INFO] Issuing delete of storage service off Azure.") log.Println("[INFO] Issuing delete of storage service off Azure.")
reqID, err := storageClient.DeleteStorageService(name) reqID, err := storageServiceClient.DeleteStorageService(name)
if err != nil { if err != nil {
return fmt.Errorf("Error whilst issuing deletion of storage service off Azure: %s", err) return fmt.Errorf("Error whilst issuing deletion of storage service off Azure: %s", err)
} }

View File

@ -1,50 +0,0 @@
package azure
import (
"fmt"
"github.com/Azure/azure-sdk-for-go/management"
"github.com/Azure/azure-sdk-for-go/management/storageservice"
"github.com/Azure/azure-sdk-for-go/storage"
)
// getStorageClientForStorageService is helper function which returns the
// storage.Client associated to the given storage service name.
func getStorageClientForStorageService(mgmtClient management.Client, serviceName string) (storage.Client, error) {
var storageClient storage.Client
storageServiceClient := storageservice.NewClient(mgmtClient)
keys, err := storageServiceClient.GetStorageServiceKeys(serviceName)
if err != nil {
return storageClient, fmt.Errorf("Failed getting Storage Service keys for %s: %s", serviceName, err)
}
storageClient, err = storage.NewBasicClient(serviceName, keys.PrimaryKey)
if err != nil {
return storageClient, fmt.Errorf("Failed creating Storage Service client for %s: %s", serviceName, err)
}
return storageClient, err
}
// getStorageServiceBlobClient is a helper function which returns the
// storage.BlobStorageClient associated to the given storage service name.
func getStorageServiceBlobClient(mgmtClient management.Client, serviceName string) (storage.BlobStorageClient, error) {
storageClient, err := getStorageClientForStorageService(mgmtClient, serviceName)
if err != nil {
return storage.BlobStorageClient{}, err
}
return storageClient.GetBlobService(), nil
}
// getStorageServiceQueueClient is a helper function which returns the
// storage.QueueServiceClient associated to the given storage service name.
func getStorageServiceQueueClient(mgmtClient management.Client, serviceName string) (storage.QueueServiceClient, error) {
storageClient, err := getStorageClientForStorageService(mgmtClient, serviceName)
if err != nil {
return storage.QueueServiceClient{}, err
}
return storageClient.GetQueueService(), err
}

View File

@ -4,7 +4,6 @@ import (
"fmt" "fmt"
"testing" "testing"
"github.com/Azure/azure-sdk-for-go/management/storageservice"
"github.com/hashicorp/terraform/helper/resource" "github.com/hashicorp/terraform/helper/resource"
"github.com/hashicorp/terraform/terraform" "github.com/hashicorp/terraform/terraform"
) )
@ -42,15 +41,15 @@ func testAccAzureStorageServiceExists(name string) resource.TestCheckFunc {
return fmt.Errorf("Azure Storage Service ID not set.") return fmt.Errorf("Azure Storage Service ID not set.")
} }
mgmtClient := testAccProvider.Meta().(*Client).mgmtClient storageServiceClient := testAccProvider.Meta().(*Client).storageServiceClient
_, err := storageservice.NewClient(mgmtClient).GetStorageService(resource.Primary.ID) _, err := storageServiceClient.GetStorageService(resource.Primary.ID)
return err return err
} }
} }
func testAccAzureStorageServiceDestroyed(s *terraform.State) error { func testAccAzureStorageServiceDestroyed(s *terraform.State) error {
mgmgClient := testAccProvider.Meta().(*Client).mgmtClient storageServiceClient := testAccProvider.Meta().(*Client).storageServiceClient
for _, resource := range s.RootModule().Resources { for _, resource := range s.RootModule().Resources {
if resource.Type != "azure_storage_service" { if resource.Type != "azure_storage_service" {
@ -61,7 +60,7 @@ func testAccAzureStorageServiceDestroyed(s *terraform.State) error {
return fmt.Errorf("Azure Storage Service ID not set.") return fmt.Errorf("Azure Storage Service ID not set.")
} }
_, err := storageservice.NewClient(mgmgClient).GetStorageService(resource.Primary.ID) _, err := storageServiceClient.GetStorageService(resource.Primary.ID)
return testAccResourceDestroyedErrorFilter("Storage Service", err) return testAccResourceDestroyedErrorFilter("Storage Service", err)
} }

View File

@ -6,7 +6,6 @@ import (
"strings" "strings"
"github.com/Azure/azure-sdk-for-go/management" "github.com/Azure/azure-sdk-for-go/management"
"github.com/Azure/azure-sdk-for-go/management/networksecuritygroup"
"github.com/Azure/azure-sdk-for-go/management/virtualnetwork" "github.com/Azure/azure-sdk-for-go/management/virtualnetwork"
"github.com/hashicorp/terraform/helper/hashcode" "github.com/hashicorp/terraform/helper/hashcode"
"github.com/hashicorp/terraform/helper/schema" "github.com/hashicorp/terraform/helper/schema"
@ -78,6 +77,7 @@ func resourceAzureVirtualNetwork() *schema.Resource {
func resourceAzureVirtualNetworkCreate(d *schema.ResourceData, meta interface{}) error { func resourceAzureVirtualNetworkCreate(d *schema.ResourceData, meta interface{}) error {
ac := meta.(*Client) ac := meta.(*Client)
mc := ac.mgmtClient mc := ac.mgmtClient
vnetClient := ac.vnetClient
name := d.Get("name").(string) name := d.Get("name").(string)
@ -86,7 +86,7 @@ func resourceAzureVirtualNetworkCreate(d *schema.ResourceData, meta interface{})
ac.mutex.Lock() ac.mutex.Lock()
defer ac.mutex.Unlock() defer ac.mutex.Unlock()
nc, err := virtualnetwork.NewClient(mc).GetVirtualNetworkConfiguration() nc, err := vnetClient.GetVirtualNetworkConfiguration()
if err != nil { if err != nil {
if strings.Contains(err.Error(), "ResourceNotFound") { if strings.Contains(err.Error(), "ResourceNotFound") {
nc = virtualnetwork.NetworkConfiguration{} nc = virtualnetwork.NetworkConfiguration{}
@ -104,7 +104,7 @@ func resourceAzureVirtualNetworkCreate(d *schema.ResourceData, meta interface{})
network := createVirtualNetwork(d) network := createVirtualNetwork(d)
nc.Configuration.VirtualNetworkSites = append(nc.Configuration.VirtualNetworkSites, network) nc.Configuration.VirtualNetworkSites = append(nc.Configuration.VirtualNetworkSites, network)
req, err := virtualnetwork.NewClient(mc).SetVirtualNetworkConfiguration(nc) req, err := vnetClient.SetVirtualNetworkConfiguration(nc)
if err != nil { if err != nil {
return fmt.Errorf("Error creating Virtual Network %s: %s", name, err) return fmt.Errorf("Error creating Virtual Network %s: %s", name, err)
} }
@ -124,9 +124,11 @@ func resourceAzureVirtualNetworkCreate(d *schema.ResourceData, meta interface{})
} }
func resourceAzureVirtualNetworkRead(d *schema.ResourceData, meta interface{}) error { func resourceAzureVirtualNetworkRead(d *schema.ResourceData, meta interface{}) error {
mc := meta.(*Client).mgmtClient ac := meta.(*Client)
vnetClient := ac.vnetClient
secGroupClient := ac.secGroupClient
nc, err := virtualnetwork.NewClient(mc).GetVirtualNetworkConfiguration() nc, err := vnetClient.GetVirtualNetworkConfiguration()
if err != nil { if err != nil {
return fmt.Errorf(virtualNetworkRetrievalError, err) return fmt.Errorf(virtualNetworkRetrievalError, err)
} }
@ -146,8 +148,7 @@ func resourceAzureVirtualNetworkRead(d *schema.ResourceData, meta interface{}) e
subnet := map[string]interface{}{} subnet := map[string]interface{}{}
// Get the associated (if any) security group // Get the associated (if any) security group
sg, err := networksecuritygroup.NewClient(mc). sg, err := secGroupClient.GetNetworkSecurityGroupForSubnet(s.Name, d.Id())
GetNetworkSecurityGroupForSubnet(s.Name, d.Id())
if err != nil && !management.IsResourceNotFoundError(err) { if err != nil && !management.IsResourceNotFoundError(err) {
return fmt.Errorf( return fmt.Errorf(
"Error retrieving Network Security Group associations of subnet %s: %s", s.Name, err) "Error retrieving Network Security Group associations of subnet %s: %s", s.Name, err)
@ -176,13 +177,14 @@ func resourceAzureVirtualNetworkRead(d *schema.ResourceData, meta interface{}) e
func resourceAzureVirtualNetworkUpdate(d *schema.ResourceData, meta interface{}) error { func resourceAzureVirtualNetworkUpdate(d *schema.ResourceData, meta interface{}) error {
ac := meta.(*Client) ac := meta.(*Client)
mc := ac.mgmtClient mc := ac.mgmtClient
vnetClient := ac.vnetClient
// Lock the client just before we get the virtual network configuration and immediately // Lock the client just before we get the virtual network configuration and immediately
// set an defer to unlock the client again whenever this function exits // set an defer to unlock the client again whenever this function exits
ac.mutex.Lock() ac.mutex.Lock()
defer ac.mutex.Unlock() defer ac.mutex.Unlock()
nc, err := virtualnetwork.NewClient(mc).GetVirtualNetworkConfiguration() nc, err := vnetClient.GetVirtualNetworkConfiguration()
if err != nil { if err != nil {
return fmt.Errorf(virtualNetworkRetrievalError, err) return fmt.Errorf(virtualNetworkRetrievalError, err)
} }
@ -201,7 +203,7 @@ func resourceAzureVirtualNetworkUpdate(d *schema.ResourceData, meta interface{})
return fmt.Errorf("Virtual Network %s does not exists!", d.Id()) return fmt.Errorf("Virtual Network %s does not exists!", d.Id())
} }
req, err := virtualnetwork.NewClient(mc).SetVirtualNetworkConfiguration(nc) req, err := vnetClient.SetVirtualNetworkConfiguration(nc)
if err != nil { if err != nil {
return fmt.Errorf("Error updating Virtual Network %s: %s", d.Id(), err) return fmt.Errorf("Error updating Virtual Network %s: %s", d.Id(), err)
} }
@ -221,13 +223,14 @@ func resourceAzureVirtualNetworkUpdate(d *schema.ResourceData, meta interface{})
func resourceAzureVirtualNetworkDelete(d *schema.ResourceData, meta interface{}) error { func resourceAzureVirtualNetworkDelete(d *schema.ResourceData, meta interface{}) error {
ac := meta.(*Client) ac := meta.(*Client)
mc := ac.mgmtClient mc := ac.mgmtClient
vnetClient := ac.vnetClient
// Lock the client just before we get the virtual network configuration and immediately // Lock the client just before we get the virtual network configuration and immediately
// set an defer to unlock the client again whenever this function exits // set an defer to unlock the client again whenever this function exits
ac.mutex.Lock() ac.mutex.Lock()
defer ac.mutex.Unlock() defer ac.mutex.Unlock()
nc, err := virtualnetwork.NewClient(mc).GetVirtualNetworkConfiguration() nc, err := vnetClient.GetVirtualNetworkConfiguration()
if err != nil { if err != nil {
return fmt.Errorf(virtualNetworkRetrievalError, err) return fmt.Errorf(virtualNetworkRetrievalError, err)
} }
@ -241,7 +244,7 @@ func resourceAzureVirtualNetworkDelete(d *schema.ResourceData, meta interface{})
nc.Configuration.VirtualNetworkSites = filtered nc.Configuration.VirtualNetworkSites = filtered
req, err := virtualnetwork.NewClient(mc).SetVirtualNetworkConfiguration(nc) req, err := vnetClient.SetVirtualNetworkConfiguration(nc)
if err != nil { if err != nil {
return fmt.Errorf("Error deleting Virtual Network %s: %s", d.Id(), err) return fmt.Errorf("Error deleting Virtual Network %s: %s", d.Id(), err)
} }
@ -301,8 +304,9 @@ func createVirtualNetwork(d *schema.ResourceData) virtualnetwork.VirtualNetworkS
} }
func associateSecurityGroups(d *schema.ResourceData, meta interface{}) error { func associateSecurityGroups(d *schema.ResourceData, meta interface{}) error {
mc := meta.(*Client).mgmtClient azureClient := meta.(*Client)
nsgClient := networksecuritygroup.NewClient(mc) mc := azureClient.mgmtClient
secGroupClient := azureClient.secGroupClient
virtualNetwork := d.Get("name").(string) virtualNetwork := d.Get("name").(string)
@ -313,7 +317,7 @@ func associateSecurityGroups(d *schema.ResourceData, meta interface{}) error {
subnetName := subnet["name"].(string) subnetName := subnet["name"].(string)
// Get the associated (if any) security group // Get the associated (if any) security group
sg, err := nsgClient.GetNetworkSecurityGroupForSubnet(subnetName, d.Id()) sg, err := secGroupClient.GetNetworkSecurityGroupForSubnet(subnetName, d.Id())
if err != nil && !management.IsResourceNotFoundError(err) { if err != nil && !management.IsResourceNotFoundError(err) {
return fmt.Errorf( return fmt.Errorf(
"Error retrieving Network Security Group associations of subnet %s: %s", subnetName, err) "Error retrieving Network Security Group associations of subnet %s: %s", subnetName, err)
@ -326,7 +330,7 @@ func associateSecurityGroups(d *schema.ResourceData, meta interface{}) error {
// If there is an associated security group, make sure we first remove it from the subnet // If there is an associated security group, make sure we first remove it from the subnet
if sg.Name != "" { if sg.Name != "" {
req, err := nsgClient.RemoveNetworkSecurityGroupFromSubnet(sg.Name, subnetName, virtualNetwork) req, err := secGroupClient.RemoveNetworkSecurityGroupFromSubnet(sg.Name, subnetName, virtualNetwork)
if err != nil { if err != nil {
return fmt.Errorf("Error removing Network Security Group %s from subnet %s: %s", return fmt.Errorf("Error removing Network Security Group %s from subnet %s: %s",
securityGroup, subnetName, err) securityGroup, subnetName, err)
@ -342,7 +346,7 @@ func associateSecurityGroups(d *schema.ResourceData, meta interface{}) error {
// If the desired security group is not empty, assign the security group to the subnet // If the desired security group is not empty, assign the security group to the subnet
if securityGroup != "" { if securityGroup != "" {
req, err := nsgClient.AddNetworkSecurityToSubnet(securityGroup, subnetName, virtualNetwork) req, err := secGroupClient.AddNetworkSecurityToSubnet(securityGroup, subnetName, virtualNetwork)
if err != nil { if err != nil {
return fmt.Errorf("Error associating Network Security Group %s to subnet %s: %s", return fmt.Errorf("Error associating Network Security Group %s to subnet %s: %s",
securityGroup, subnetName, err) securityGroup, subnetName, err)

View File

@ -137,8 +137,8 @@ func testAccCheckAzureVirtualNetworkExists(
return fmt.Errorf("No Virtual Network ID is set") return fmt.Errorf("No Virtual Network ID is set")
} }
mc := testAccProvider.Meta().(*Client).mgmtClient vnetClient := testAccProvider.Meta().(*Client).vnetClient
nc, err := virtualnetwork.NewClient(mc).GetVirtualNetworkConfiguration() nc, err := vnetClient.GetVirtualNetworkConfiguration()
if err != nil { if err != nil {
return err return err
} }
@ -172,7 +172,7 @@ func testAccCheckAzureVirtualNetworkAttributes(
} }
func testAccCheckAzureVirtualNetworkDestroy(s *terraform.State) error { func testAccCheckAzureVirtualNetworkDestroy(s *terraform.State) error {
mc := testAccProvider.Meta().(*Client).mgmtClient vnetClient := testAccProvider.Meta().(*Client).vnetClient
for _, rs := range s.RootModule().Resources { for _, rs := range s.RootModule().Resources {
if rs.Type != "azure_virtual_network" { if rs.Type != "azure_virtual_network" {
@ -183,7 +183,7 @@ func testAccCheckAzureVirtualNetworkDestroy(s *terraform.State) error {
return fmt.Errorf("No Virtual Network ID is set") return fmt.Errorf("No Virtual Network ID is set")
} }
nc, err := virtualnetwork.NewClient(mc).GetVirtualNetworkConfiguration() nc, err := vnetClient.GetVirtualNetworkConfiguration()
if err != nil { if err != nil {
return fmt.Errorf("Error retrieving Virtual Network Configuration: %s", err) return fmt.Errorf("Error retrieving Virtual Network Configuration: %s", err)
} }