in cloudstack/resource_cloudstack_disk.go [106:165]
func resourceCloudStackDiskCreate(d *schema.ResourceData, meta interface{}) error {
cs := meta.(*cloudstack.CloudStackClient)
name := d.Get("name").(string)
// Create a new parameter struct
p := cs.Volume.NewCreateVolumeParams()
p.SetName(name)
// Retrieve the disk_offering ID
diskofferingid, e := retrieveID(cs, "disk_offering", d.Get("disk_offering").(string))
if e != nil {
return e.Error()
}
// Set the disk_offering ID
p.SetDiskofferingid(diskofferingid)
if d.Get("size").(int) != 0 {
// Set the volume size
p.SetSize(int64(d.Get("size").(int)))
}
// If there is a project supplied, we retrieve and set the project id
if err := setProjectid(p, cs, d); err != nil {
return err
}
// Retrieve the zone ID
zoneid, e := retrieveID(cs, "zone", d.Get("zone").(string))
if e != nil {
return e.Error()
}
// Set the zone ID
p.SetZoneid(zoneid)
// Create the new volume
r, err := cs.Volume.CreateVolume(p)
if err != nil {
return fmt.Errorf("Error creating the new disk %s: %s", name, err)
}
// Set the volume ID and partials
d.SetId(r.Id)
// Set tags if necessary
err = setTags(cs, d, "Volume")
if err != nil {
return fmt.Errorf("Error setting tags on the new disk %s: %s", name, err)
}
if d.Get("attach").(bool) {
if err := resourceCloudStackDiskAttach(d, meta); err != nil {
return fmt.Errorf("Error attaching the new disk %s to virtual machine: %s", name, err)
}
// Set the additional partial
}
return resourceCloudStackDiskRead(d, meta)
}