Skip to content

Commit

Permalink
Minor instance fixes
Browse files Browse the repository at this point in the history
  • Loading branch information
aznashwan committed May 28, 2015
1 parent e8cd854 commit c1e7bff
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 30 deletions.
2 changes: 1 addition & 1 deletion builtin/providers/azure/resource_azure_hosted_service.go
Original file line number Diff line number Diff line change
Expand Up @@ -87,7 +87,7 @@ func resourceAzureHostedServiceCreate(d *schema.ResourceData, meta interface{})
description := d.Get("description").(string)

// set the label as the resource's ID:
label := getRandomStringLabel(50)
label := getRandomStringLabel(20)
d.SetId(label)

err := hostedServiceClient.CreateHostedService(
Expand Down
55 changes: 26 additions & 29 deletions builtin/providers/azure/resource_azure_instance.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ import (
"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/vmutils"
"github.com/Azure/azure-sdk-for-go/management/vmutils"
"github.com/hashicorp/terraform/helper/schema"
)

Expand Down Expand Up @@ -153,10 +153,9 @@ func resourceAzureInstanceCreate(d *schema.ResourceData, meta interface{}) error
// general variables:
label := getRandomStringLabel(50)
d.SetId(label)
// image := d.Get("image").(string)
image := d.Get("image").(string)
name := d.Get("name").(string)
location := d.Get("location").(string)
description := d.Get("descriptiom").(string)
serviceName := d.Get("service_name").(string)

// create the hosted service:
Expand All @@ -173,52 +172,50 @@ func resourceAzureInstanceCreate(d *schema.ResourceData, meta interface{}) error
Location: location,
ReverseDNSFqdn: "",
Label: label,
Description: description,
},
)
if err != nil {
return fmt.Errorf("Error defining new Azure hosted service: %s", err)
}

// err = managementClient.WaitForOperation(reqID, nil)
// if err != nil {
// return fmt.Errorf("Error creating new Azure hosted service: %s", err)
// }
} else {
fmt.Errorf("Error querying for existing hosted service.")
}
}

// create VM configuration:
// role := vmutils.NewVmConfiguration(name, d.Get("size").(string))
role := vmutils.NewVMConfiguration(name, d.Get("size").(string))

// configure the VM's storage:
// TODO(aznashwan): put things right here:
// storAccount := d.Get("storage_account").(string)
// storContainer := d.Get("storage_container").(string)
// vhdURL := fmt.Sprintf("http://%s.blob.core.windows.net/%s/%s.vhd", storAccount, storContainer, name)
storAccount := d.Get("storage_account").(string)
storContainer := d.Get("storage_container").(string)
vhdURL := fmt.Sprintf("http://%s.blob.core.windows.net/%s/%s.vhd", storAccount, storContainer, name)

// err = vmutils.ConfigureDeploymentFromPlatformImage(&role, image, vhdURL, label)
// if err != nil {
// return fmt.Errorf("Failed to configure deployment: %s", err)
//}
err = vmutils.ConfigureDeploymentFromPlatformImage(&role, image, vhdURL, label)
if err != nil {
return fmt.Errorf("Failed to configure deployment: %s", err)
}

// configure VM details:
//userName := d.Get("user_name").(string)
//userPass := d.Get("user_password").(string)
//vmutils.ConfigureForLinux(&role, name, userName, userPass)
//vmutils.ConfigureWithPublicSSH(&role)
userName := d.Get("user_name").(string)
userPass := d.Get("user_password").(string)
vmutils.ConfigureForLinux(&role, name, userName, userPass)
vmutils.ConfigureWithPublicSSH(&role)

// deploy the VM:
// reqID, err := virtualmachine.NewClient(managementClient).CreateDeployment(role, serviceName)
// if err != nil {
// return fmt.Errorf("Failed to initiate deployment creation: %s", err)
// }
reqID, err := virtualmachine.NewClient(managementClient).CreateDeployment(
role,
serviceName,
virtualmachine.CreateDeploymentOptions{},
)
if err != nil {
return fmt.Errorf("Failed to initiate deployment creation: %s", err)
}

// err = managementClient.WaitForOperation(reqID, nil)
// if err != nil {
// return fmt.Errorf("Deployment creation failed: ", err)
// }
err = managementClient.WaitForOperation(reqID, nil)
if err != nil {
return fmt.Errorf("Deployment creation failed: %s", err)
}

return resourceAzureInstanceRead(d, meta)
}
Expand Down

0 comments on commit c1e7bff

Please sign in to comment.