diff --git a/builtin/providers/cloudstack/resource_cloudstack_instance.go b/builtin/providers/cloudstack/resource_cloudstack_instance.go index eb4f2fc05..a37661f45 100644 --- a/builtin/providers/cloudstack/resource_cloudstack_instance.go +++ b/builtin/providers/cloudstack/resource_cloudstack_instance.go @@ -82,11 +82,13 @@ func resourceCloudStackInstance() *schema.Resource { Optional: true, Default: false, }, - "project_name": &schema.Schema{ + + "project": &schema.Schema{ Type: schema.TypeString, Optional: true, - Default: nil, + ForceNew: true, }, + }, } } @@ -153,15 +155,14 @@ func resourceCloudStackInstanceCreate(d *schema.ResourceData, meta interface{}) p.SetUserdata(ud) } - // If the project_name contains any info, we retreive the project_id - if projectName, ok := d.GetOk("project_name"); ok { - project, _, err := cs.Project.GetProjectByName(projectName.(string)) - if err != nil { - return err + // If project contains any info, we retreive the project id + if project, ok := d.GetOk("project"); ok { + projectid, e := retrieveUUID(cs, "project", project.(string)) + if e != nil { + return e.Error() } - log.Printf("[DEBUG] project id %s", project.Id) - p.SetProjectid(project.Id) - d.Set("project_id", project.Id) + log.Printf("[DEBUG] project id %s", projectid) + p.SetProjectid(projectid) } // 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, "service_offering", vm.Serviceofferingname, vm.Serviceofferingid) setValueOrUUID(d, "template", vm.Templatename, vm.Templateid) - + setValueOrUUID(d, "project", vm.Project, vm.Projectid) + return nil } diff --git a/builtin/providers/cloudstack/resources.go b/builtin/providers/cloudstack/resources.go index 85fa0bd5a..5d0e5eb55 100644 --- a/builtin/providers/cloudstack/resources.go +++ b/builtin/providers/cloudstack/resources.go @@ -79,6 +79,8 @@ func retrieveUUID(cs *cloudstack.CloudStackClient, name, value string) (uuid str break } err = fmt.Errorf("Could not find UUID of OS Type: %s", value) + case "project": + uuid, err = cs.Project.GetProjectID(value) default: return uuid, &retrieveError{name: name, value: value, err: fmt.Errorf("Unknown request: %s", name)}