in cloudstack/resource_cloudstack_autoscale_vm_profile.go [75:128]
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.SetExpungevmgraceperiod(int(duration.Seconds()))
}
if v, ok := d.GetOk("other_deploy_params"); ok {
nv := make(map[string]string)
for k, v := range v.(map[string]interface{}) {
nv[k] = v.(string)
}
p.SetOtherdeployparams(nv)
}
// 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
}