Updated to work with the latest Azure SDK changes

This commit is contained in:
Sander van Harmelen 2015-05-22 22:02:48 +02:00
parent 83e3ab1fc7
commit 8c3cb400d7
5 changed files with 54 additions and 54 deletions

View File

@ -15,7 +15,7 @@ type Config struct {
}
// NewClient returns a new Azure management client
func (c *Config) NewClient() (*management.Client, error) {
func (c *Config) NewClient() (management.Client, error) {
if _, err := os.Stat(c.SettingsFile); os.IsNotExist(err) {
return nil, fmt.Errorf("Publish Settings file %q does not exist!", c.SettingsFile)
}
@ -25,5 +25,5 @@ func (c *Config) NewClient() (*management.Client, error) {
return nil, fmt.Errorf("Error creating management client: %s", err)
}
return &mc, nil
return mc, nil
}

View File

@ -70,7 +70,7 @@ func resourceAzureDataDisk() *schema.Resource {
}
func resourceAzureDataDiskCreate(d *schema.ResourceData, meta interface{}) error {
mc := meta.(*management.Client)
mc := meta.(management.Client)
if err := verifyDataDiskParameters(d); err != nil {
return err
@ -92,7 +92,7 @@ func resourceAzureDataDiskCreate(d *schema.ResourceData, meta interface{}) error
}
log.Printf("[DEBUG] Adding data disk %d to instance: %s", lun, vm)
req, err := virtualmachinedisk.NewClient(*mc).AddDataDisk(vm, vm, vm, p)
req, err := virtualmachinedisk.NewClient(mc).AddDataDisk(vm, vm, vm, p)
if err != nil {
return fmt.Errorf("Error adding data disk %d to instance %s: %s", lun, vm, err)
}
@ -104,7 +104,7 @@ func resourceAzureDataDiskCreate(d *schema.ResourceData, meta interface{}) error
}
log.Printf("[DEBUG] Retrieving data disk %d from instance %s", lun, vm)
disk, err := virtualmachinedisk.NewClient(*mc).GetDataDisk(vm, vm, vm, lun)
disk, err := virtualmachinedisk.NewClient(mc).GetDataDisk(vm, vm, vm, lun)
if err != nil {
return fmt.Errorf("Error retrieving data disk %d from instance %s: %s", lun, vm, err)
}
@ -115,13 +115,13 @@ func resourceAzureDataDiskCreate(d *schema.ResourceData, meta interface{}) error
}
func resourceAzureDataDiskRead(d *schema.ResourceData, meta interface{}) error {
mc := meta.(*management.Client)
mc := meta.(management.Client)
lun := d.Get("lun").(int)
vm := d.Get("virtual_machine").(string)
log.Printf("[DEBUG] Retrieving data disk: %s", d.Id())
datadisk, err := virtualmachinedisk.NewClient(*mc).GetDataDisk(vm, vm, vm, lun)
datadisk, err := virtualmachinedisk.NewClient(mc).GetDataDisk(vm, vm, vm, lun)
if err != nil {
return fmt.Errorf("Error retrieving data disk %s: %s", d.Id(), err)
}
@ -133,7 +133,7 @@ func resourceAzureDataDiskRead(d *schema.ResourceData, meta interface{}) error {
d.Set("media_link", datadisk.MediaLink)
log.Printf("[DEBUG] Retrieving disk: %s", d.Id())
disk, err := virtualmachinedisk.NewClient(*mc).GetDisk(d.Id())
disk, err := virtualmachinedisk.NewClient(mc).GetDisk(d.Id())
if err != nil {
return fmt.Errorf("Error retrieving disk %s: %s", d.Id(), err)
}
@ -144,7 +144,7 @@ func resourceAzureDataDiskRead(d *schema.ResourceData, meta interface{}) error {
}
func resourceAzureDataDiskUpdate(d *schema.ResourceData, meta interface{}) error {
mc := meta.(*management.Client)
mc := meta.(management.Client)
lun := d.Get("lun").(int)
vm := d.Get("virtual_machine").(string)
@ -158,7 +158,7 @@ func resourceAzureDataDiskUpdate(d *schema.ResourceData, meta interface{}) error
}
log.Printf("[DEBUG] Updating disk: %s", d.Id())
req, err := virtualmachinedisk.NewClient(*mc).UpdateDisk(d.Id(), p)
req, err := virtualmachinedisk.NewClient(mc).UpdateDisk(d.Id(), p)
if err != nil {
return fmt.Errorf("Error updating disk %s: %s", d.Id(), err)
}
@ -172,7 +172,7 @@ func resourceAzureDataDiskUpdate(d *schema.ResourceData, meta interface{}) error
if d.HasChange("virtual_machine") {
log.Printf("[DEBUG] Detaching data disk: %s", d.Id())
req, err := virtualmachinedisk.NewClient(*mc).DeleteDataDisk(vm, vm, vm, lun, false)
req, err := virtualmachinedisk.NewClient(mc).DeleteDataDisk(vm, vm, vm, lun, false)
if err != nil {
return fmt.Errorf("Error detaching data disk %s: %s", d.Id(), err)
}
@ -191,7 +191,7 @@ func resourceAzureDataDiskUpdate(d *schema.ResourceData, meta interface{}) error
}
log.Printf("[DEBUG] Attaching data disk: %s", d.Id())
req, err = virtualmachinedisk.NewClient(*mc).AddDataDisk(vm, vm, vm, p)
req, err = virtualmachinedisk.NewClient(mc).AddDataDisk(vm, vm, vm, p)
if err != nil {
return fmt.Errorf("Error attaching data disk %s to instance %s: %s", d.Id(), vm, err)
}
@ -216,7 +216,7 @@ func resourceAzureDataDiskUpdate(d *schema.ResourceData, meta interface{}) error
}
log.Printf("[DEBUG] Updating data disk: %s", d.Id())
req, err := virtualmachinedisk.NewClient(*mc).UpdateDataDisk(vm, vm, vm, lun, p)
req, err := virtualmachinedisk.NewClient(mc).UpdateDataDisk(vm, vm, vm, lun, p)
if err != nil {
return fmt.Errorf("Error updating data disk %s: %s", d.Id(), err)
}
@ -232,7 +232,7 @@ func resourceAzureDataDiskUpdate(d *schema.ResourceData, meta interface{}) error
}
func resourceAzureDataDiskDelete(d *schema.ResourceData, meta interface{}) error {
mc := meta.(*management.Client)
mc := meta.(management.Client)
lun := d.Get("lun").(int)
vm := d.Get("virtual_machine").(string)
@ -241,7 +241,7 @@ func resourceAzureDataDiskDelete(d *schema.ResourceData, meta interface{}) error
_, removeBlob := d.GetOk("name")
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 := virtualmachinedisk.NewClient(mc).DeleteDataDisk(vm, vm, vm, lun, removeBlob)
if err != nil {
return fmt.Errorf(
"Error detaching data disk %s with removeBlob = %t: %s", d.Id(), removeBlob, err)

View File

@ -165,7 +165,7 @@ func resourceAzureInstance() *schema.Resource {
}
func resourceAzureInstanceCreate(d *schema.ResourceData, meta interface{}) (err error) {
mc := meta.(*management.Client)
mc := meta.(management.Client)
name := d.Get("name").(string)
@ -199,16 +199,16 @@ func resourceAzureInstanceCreate(d *schema.ResourceData, meta interface{}) (err
}
log.Printf("[DEBUG] Creating Cloud Service for instance: %s", name)
err = hostedservice.NewClient(*mc).CreateHostedService(p)
err = hostedservice.NewClient(mc).CreateHostedService(p)
if err != nil {
return fmt.Errorf("Error creating Cloud Service for instance %s: %s", name, err)
}
// Put in this defer here, so we are sure to cleanup already created parts
// when we exit with an error
defer func(mc *management.Client) {
defer func(mc management.Client) {
if err != nil {
req, err := hostedservice.NewClient(*mc).DeleteHostedService(name, true)
req, err := hostedservice.NewClient(mc).DeleteHostedService(name, true)
if err != nil {
log.Printf("[DEBUG] Error cleaning up Cloud Service of instance %s: %s", name, err)
}
@ -305,7 +305,7 @@ func resourceAzureInstanceCreate(d *schema.ResourceData, meta interface{}) (err
}
log.Printf("[DEBUG] Creating the new instance...")
req, err := virtualmachine.NewClient(*mc).CreateDeployment(role, name, options)
req, err := virtualmachine.NewClient(mc).CreateDeployment(role, name, options)
if err != nil {
return fmt.Errorf("Error creating instance %s: %s", name, err)
}
@ -322,10 +322,10 @@ func resourceAzureInstanceCreate(d *schema.ResourceData, meta interface{}) (err
}
func resourceAzureInstanceRead(d *schema.ResourceData, meta interface{}) error {
mc := meta.(*management.Client)
mc := meta.(management.Client)
log.Printf("[DEBUG] Retrieving Cloud Service for instance: %s", d.Id())
cs, err := hostedservice.NewClient(*mc).GetHostedService(d.Id())
cs, err := hostedservice.NewClient(mc).GetHostedService(d.Id())
if err != nil {
return fmt.Errorf("Error retrieving Cloud Service of instance %s: %s", d.Id(), err)
}
@ -334,7 +334,7 @@ func resourceAzureInstanceRead(d *schema.ResourceData, meta interface{}) error {
d.Set("location", cs.Location)
log.Printf("[DEBUG] Retrieving instance: %s", d.Id())
dpmt, err := virtualmachine.NewClient(*mc).GetDeployment(d.Id(), d.Id())
dpmt, err := virtualmachine.NewClient(mc).GetDeployment(d.Id(), d.Id())
if err != nil {
return fmt.Errorf("Error retrieving instance %s: %s", d.Id(), err)
}
@ -412,7 +412,7 @@ func resourceAzureInstanceRead(d *schema.ResourceData, meta interface{}) error {
}
func resourceAzureInstanceUpdate(d *schema.ResourceData, meta interface{}) error {
mc := meta.(*management.Client)
mc := meta.(management.Client)
// First check if anything we can update changed, and if not just return
if !d.HasChange("size") && !d.HasChange("endpoint") && !d.HasChange("security_group") {
@ -420,7 +420,7 @@ func resourceAzureInstanceUpdate(d *schema.ResourceData, meta interface{}) error
}
// Get the current role
role, err := virtualmachine.NewClient(*mc).GetRole(d.Id(), d.Id(), d.Id())
role, err := virtualmachine.NewClient(mc).GetRole(d.Id(), d.Id(), d.Id())
if err != nil {
return fmt.Errorf("Error retrieving role of instance %s: %s", d.Id(), err)
}
@ -474,7 +474,7 @@ func resourceAzureInstanceUpdate(d *schema.ResourceData, meta interface{}) error
}
// Update the adjusted role
req, err := virtualmachine.NewClient(*mc).UpdateRole(d.Id(), d.Id(), d.Id(), *role)
req, err := virtualmachine.NewClient(mc).UpdateRole(d.Id(), d.Id(), d.Id(), *role)
if err != nil {
return fmt.Errorf("Error updating role of instance %s: %s", d.Id(), err)
}
@ -488,10 +488,10 @@ func resourceAzureInstanceUpdate(d *schema.ResourceData, meta interface{}) error
}
func resourceAzureInstanceDelete(d *schema.ResourceData, meta interface{}) error {
mc := meta.(*management.Client)
mc := meta.(management.Client)
log.Printf("[DEBUG] Deleting instance: %s", d.Id())
req, err := hostedservice.NewClient(*mc).DeleteHostedService(d.Id(), true)
req, err := hostedservice.NewClient(mc).DeleteHostedService(d.Id(), true)
if err != nil {
return fmt.Errorf("Error deleting instance %s: %s", d.Id(), err)
}
@ -519,7 +519,7 @@ func resourceAzureEndpointHash(v interface{}) int {
}
func retrieveImageDetails(
mc *management.Client,
mc management.Client,
label string,
storage string) (func(*virtualmachine.Role) error, string, error) {
configureForImage, osType, err := retrieveVMImageDetails(mc, label)
@ -536,9 +536,9 @@ func retrieveImageDetails(
}
func retrieveVMImageDetails(
mc *management.Client,
mc management.Client,
label string) (func(*virtualmachine.Role) error, string, error) {
imgs, err := virtualmachineimage.NewClient(*mc).ListVirtualMachineImages()
imgs, err := virtualmachineimage.NewClient(mc).ListVirtualMachineImages()
if err != nil {
return nil, "", fmt.Errorf("Error retrieving image details: %s", err)
}
@ -566,10 +566,10 @@ func retrieveVMImageDetails(
}
func retrieveOSImageDetails(
mc *management.Client,
mc management.Client,
label,
storage string) (func(*virtualmachine.Role) error, string, error) {
imgs, err := osimage.NewClient(*mc).ListOSImages()
imgs, err := osimage.NewClient(mc).ListOSImages()
if err != nil {
return nil, "", fmt.Errorf("Error retrieving image details: %s", err)
}

View File

@ -105,7 +105,7 @@ func resourceAzureSecurityGroup() *schema.Resource {
}
func resourceAzureSecurityGroupCreate(d *schema.ResourceData, meta interface{}) (err error) {
mc := meta.(*management.Client)
mc := meta.(management.Client)
name := d.Get("name").(string)
@ -115,7 +115,7 @@ func resourceAzureSecurityGroupCreate(d *schema.ResourceData, meta interface{})
label = name
}
req, err := networksecuritygroup.NewClient(*mc).CreateNetworkSecurityGroup(
req, err := networksecuritygroup.NewClient(mc).CreateNetworkSecurityGroup(
name,
label,
d.Get("location").(string),
@ -158,7 +158,7 @@ func resourceAzureSecurityGroupCreate(d *schema.ResourceData, meta interface{})
func resourceAzureSecurityGroupRuleCreate(
d *schema.ResourceData, meta interface{}, rule map[string]interface{}) error {
mc := meta.(*management.Client)
mc := meta.(management.Client)
// Make sure all required parameters are there
if err := verifySecurityGroupRuleParams(rule); err != nil {
@ -168,7 +168,7 @@ func resourceAzureSecurityGroupRuleCreate(
name := rule["name"].(string)
// Create the rule
req, err := networksecuritygroup.NewClient(*mc).SetNetworkSecurityGroupRule(d.Id(),
req, err := networksecuritygroup.NewClient(mc).SetNetworkSecurityGroupRule(d.Id(),
networksecuritygroup.RuleRequest{
Name: name,
Type: networksecuritygroup.RuleType(rule["type"].(string)),
@ -194,9 +194,9 @@ func resourceAzureSecurityGroupRuleCreate(
}
func resourceAzureSecurityGroupRead(d *schema.ResourceData, meta interface{}) error {
mc := meta.(*management.Client)
mc := meta.(management.Client)
sg, err := networksecuritygroup.NewClient(*mc).GetNetworkSecurityGroup(d.Id())
sg, err := networksecuritygroup.NewClient(mc).GetNetworkSecurityGroup(d.Id())
if err != nil {
return fmt.Errorf("Error retrieving Network Security Group %s: %s", d.Id(), err)
}
@ -269,10 +269,10 @@ func resourceAzureSecurityGroupUpdate(d *schema.ResourceData, meta interface{})
}
func resourceAzureSecurityGroupDelete(d *schema.ResourceData, meta interface{}) error {
mc := meta.(*management.Client)
mc := meta.(management.Client)
log.Printf("[DEBUG] Deleting Network Security Group: %s", d.Id())
req, err := networksecuritygroup.NewClient(*mc).DeleteNetworkSecurityGroup(d.Id())
req, err := networksecuritygroup.NewClient(mc).DeleteNetworkSecurityGroup(d.Id())
if err != nil {
return fmt.Errorf("Error deleting Network Security Group %s: %s", d.Id(), err)
}
@ -290,12 +290,12 @@ func resourceAzureSecurityGroupDelete(d *schema.ResourceData, meta interface{})
func resourceAzureSecurityGroupRuleDelete(
d *schema.ResourceData, meta interface{}, rule map[string]interface{}) error {
mc := meta.(*management.Client)
mc := meta.(management.Client)
name := rule["name"].(string)
// Delete the rule
req, err := networksecuritygroup.NewClient(*mc).DeleteNetworkSecurityGroupRule(d.Id(), name)
req, err := networksecuritygroup.NewClient(mc).DeleteNetworkSecurityGroupRule(d.Id(), name)
if err != nil {
return fmt.Errorf("Error deleting Network Security Group rule %s: %s", name, err)
}

View File

@ -50,11 +50,11 @@ func resourceAzureVirtualNetwork() *schema.Resource {
}
func resourceAzureVirtualNetworkCreate(d *schema.ResourceData, meta interface{}) error {
mc := meta.(*management.Client)
mc := meta.(management.Client)
name := d.Get("name").(string)
nc, err := virtualnetwork.NewClient(*mc).GetVirtualNetworkConfiguration()
nc, err := virtualnetwork.NewClient(mc).GetVirtualNetworkConfiguration()
if err != nil {
if strings.Contains(err.Error(), "ResourceNotFound") {
nc = virtualnetwork.NetworkConfiguration{}
@ -76,7 +76,7 @@ func resourceAzureVirtualNetworkCreate(d *schema.ResourceData, meta interface{})
nc.Configuration.VirtualNetworkSites = append(nc.Configuration.VirtualNetworkSites, network)
req, err := virtualnetwork.NewClient(*mc).SetVirtualNetworkConfiguration(nc)
req, err := virtualnetwork.NewClient(mc).SetVirtualNetworkConfiguration(nc)
if err != nil {
return fmt.Errorf("Error creating Virtual Network %s: %s", name, err)
}
@ -93,9 +93,9 @@ func resourceAzureVirtualNetworkCreate(d *schema.ResourceData, meta interface{})
}
func resourceAzureVirtualNetworkRead(d *schema.ResourceData, meta interface{}) error {
mc := meta.(*management.Client)
mc := meta.(management.Client)
nc, err := virtualnetwork.NewClient(*mc).GetVirtualNetworkConfiguration()
nc, err := virtualnetwork.NewClient(mc).GetVirtualNetworkConfiguration()
if err != nil {
return fmt.Errorf(virtualNetworkRetrievalError, err)
}
@ -123,9 +123,9 @@ func resourceAzureVirtualNetworkRead(d *schema.ResourceData, meta interface{}) e
}
func resourceAzureVirtualNetworkUpdate(d *schema.ResourceData, meta interface{}) error {
mc := meta.(*management.Client)
mc := meta.(management.Client)
nc, err := virtualnetwork.NewClient(*mc).GetVirtualNetworkConfiguration()
nc, err := virtualnetwork.NewClient(mc).GetVirtualNetworkConfiguration()
if err != nil {
return fmt.Errorf(virtualNetworkRetrievalError, err)
}
@ -148,7 +148,7 @@ func resourceAzureVirtualNetworkUpdate(d *schema.ResourceData, meta interface{})
return fmt.Errorf("Virtual Network %s does not exists!", d.Id())
}
req, err := virtualnetwork.NewClient(*mc).SetVirtualNetworkConfiguration(nc)
req, err := virtualnetwork.NewClient(mc).SetVirtualNetworkConfiguration(nc)
if err != nil {
return fmt.Errorf("Error updating Virtual Network %s: %s", d.Id(), err)
}
@ -163,9 +163,9 @@ func resourceAzureVirtualNetworkUpdate(d *schema.ResourceData, meta interface{})
}
func resourceAzureVirtualNetworkDelete(d *schema.ResourceData, meta interface{}) error {
mc := meta.(*management.Client)
mc := meta.(management.Client)
nc, err := virtualnetwork.NewClient(*mc).GetVirtualNetworkConfiguration()
nc, err := virtualnetwork.NewClient(mc).GetVirtualNetworkConfiguration()
if err != nil {
return fmt.Errorf(virtualNetworkRetrievalError, err)
}
@ -179,7 +179,7 @@ func resourceAzureVirtualNetworkDelete(d *schema.ResourceData, meta interface{})
nc.Configuration.VirtualNetworkSites = filtered
req, err := virtualnetwork.NewClient(*mc).SetVirtualNetworkConfiguration(nc)
req, err := virtualnetwork.NewClient(mc).SetVirtualNetworkConfiguration(nc)
if err != nil {
return fmt.Errorf("Error deleting Virtual Network %s: %s", d.Id(), err)
}