fixed project schema, added project support to retrieveUUID
This commit is contained in:
parent
a09afbb4aa
commit
7e49714c3d
|
@ -82,11 +82,13 @@ func resourceCloudStackInstance() *schema.Resource {
|
||||||
Optional: true,
|
Optional: true,
|
||||||
Default: false,
|
Default: false,
|
||||||
},
|
},
|
||||||
"project_name": &schema.Schema{
|
|
||||||
|
"project": &schema.Schema{
|
||||||
Type: schema.TypeString,
|
Type: schema.TypeString,
|
||||||
Optional: true,
|
Optional: true,
|
||||||
Default: nil,
|
ForceNew: true,
|
||||||
},
|
},
|
||||||
|
|
||||||
},
|
},
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -153,15 +155,14 @@ func resourceCloudStackInstanceCreate(d *schema.ResourceData, meta interface{})
|
||||||
p.SetUserdata(ud)
|
p.SetUserdata(ud)
|
||||||
}
|
}
|
||||||
|
|
||||||
// If the project_name contains any info, we retreive the project_id
|
// If project contains any info, we retreive the project id
|
||||||
if projectName, ok := d.GetOk("project_name"); ok {
|
if project, ok := d.GetOk("project"); ok {
|
||||||
project, _, err := cs.Project.GetProjectByName(projectName.(string))
|
projectid, e := retrieveUUID(cs, "project", project.(string))
|
||||||
if err != nil {
|
if e != nil {
|
||||||
return err
|
return e.Error()
|
||||||
}
|
}
|
||||||
log.Printf("[DEBUG] project id %s", project.Id)
|
log.Printf("[DEBUG] project id %s", projectid)
|
||||||
p.SetProjectid(project.Id)
|
p.SetProjectid(projectid)
|
||||||
d.Set("project_id", project.Id)
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// Create the new instance
|
// Create the new instance
|
||||||
|
@ -206,7 +207,8 @@ func resourceCloudStackInstanceRead(d *schema.ResourceData, meta interface{}) er
|
||||||
setValueOrUUID(d, "network", vm.Nic[0].Networkname, vm.Nic[0].Networkid)
|
setValueOrUUID(d, "network", vm.Nic[0].Networkname, vm.Nic[0].Networkid)
|
||||||
setValueOrUUID(d, "service_offering", vm.Serviceofferingname, vm.Serviceofferingid)
|
setValueOrUUID(d, "service_offering", vm.Serviceofferingname, vm.Serviceofferingid)
|
||||||
setValueOrUUID(d, "template", vm.Templatename, vm.Templateid)
|
setValueOrUUID(d, "template", vm.Templatename, vm.Templateid)
|
||||||
|
setValueOrUUID(d, "project", vm.Project, vm.Projectid)
|
||||||
|
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -79,6 +79,8 @@ func retrieveUUID(cs *cloudstack.CloudStackClient, name, value string) (uuid str
|
||||||
break
|
break
|
||||||
}
|
}
|
||||||
err = fmt.Errorf("Could not find UUID of OS Type: %s", value)
|
err = fmt.Errorf("Could not find UUID of OS Type: %s", value)
|
||||||
|
case "project":
|
||||||
|
uuid, err = cs.Project.GetProjectID(value)
|
||||||
default:
|
default:
|
||||||
return uuid, &retrieveError{name: name, value: value,
|
return uuid, &retrieveError{name: name, value: value,
|
||||||
err: fmt.Errorf("Unknown request: %s", name)}
|
err: fmt.Errorf("Unknown request: %s", name)}
|
||||||
|
|
Loading…
Reference in New Issue