in cloudstack/resource_cloudstack_autoscale_vm_profile.go [76:130]
func resourceCloudStackAutoScaleVMProfileCreate(d *schema.ResourceData, meta interface{}) error {
cs := meta.(*cloudstack.CloudStackClient)
// Retrieve the service_offering ID
serviceofferingid, e := retrieveID(cs, "service_offering", d.Get("service_offering").(string))
if e != nil {
return e.Error()
}
// Retrieve the zone ID
zoneid, e := retrieveID(cs, "zone", d.Get("zone").(string))
if e != nil {
return e.Error()
}
// Retrieve the template ID
templateid, e := retrieveTemplateID(cs, zoneid, d.Get("template").(string))
if e != nil {
return e.Error()
}
p := cs.AutoScale.NewCreateAutoScaleVmProfileParams(serviceofferingid, templateid, zoneid)
if v, ok := d.GetOk("destroy_vm_grace_period"); ok {
duration, err := time.ParseDuration(v.(string))
if err != nil {
return err
}
p.SetDestroyvmgraceperiod(int(duration.Seconds()))
}
if v, ok := d.GetOk("other_deploy_params"); ok {
otherMap := v.(map[string]interface{})
result := url.Values{}
for k, v := range otherMap {
result.Set(k, fmt.Sprint(v))
}
p.SetOtherdeployparams(result.Encode())
}
// Create the new vm profile
r, err := cs.AutoScale.CreateAutoScaleVmProfile(p)
if err != nil {
return fmt.Errorf("Error creating AutoScaleVmProfile %s: %s", d.Id(), err)
}
d.SetId(r.Id)
// Set metadata if necessary
if err = setMetadata(cs, d, "AutoScaleVmProfile"); err != nil {
return fmt.Errorf("Error setting metadata on the AutoScaleVmProfile %s: %s", d.Id(), err)
}
return nil
}