diff --git a/builtin/providers/cloudstack/resource_cloudstack_disk.go b/builtin/providers/cloudstack/resource_cloudstack_disk.go index 1c7ad36bd..c19cac8bc 100644 --- a/builtin/providers/cloudstack/resource_cloudstack_disk.go +++ b/builtin/providers/cloudstack/resource_cloudstack_disk.go @@ -61,6 +61,12 @@ func resourceCloudStackDisk() *schema.Resource { Required: true, ForceNew: true, }, + + "project": &schema.Schema{ + Type: schema.TypeString, + Optional: true, + ForceNew: true, + }, }, } } @@ -74,6 +80,17 @@ func resourceCloudStackDiskCreate(d *schema.ResourceData, meta interface{}) erro // Create a new parameter struct p := cs.Volume.NewCreateVolumeParams(name) + // If there is a project supplied, we retreive and set the project id + if project, ok := d.GetOk("project"); ok { + // Retrieve the project UUID + projectid, e := retrieveUUID(cs, "project", project.(string)) + if e != nil { + return e.Error() + } + // Set the default project ID + p.SetProjectid(projectid) + } + // Retrieve the disk_offering UUID diskofferingid, e := retrieveUUID(cs, "disk_offering", d.Get("disk_offering").(string)) if e != nil { @@ -144,6 +161,7 @@ func resourceCloudStackDiskRead(d *schema.ResourceData, meta interface{}) error setValueOrUUID(d, "disk_offering", v.Diskofferingname, v.Diskofferingid) setValueOrUUID(d, "zone", v.Zonename, v.Zoneid) + setValueOrUUID(d, "project", v.Project, v.Projectid) if v.Attached != "" { // Get the virtual machine details diff --git a/builtin/providers/cloudstack/resource_cloudstack_ipaddress.go b/builtin/providers/cloudstack/resource_cloudstack_ipaddress.go index 84e067f81..054c3bb74 100644 --- a/builtin/providers/cloudstack/resource_cloudstack_ipaddress.go +++ b/builtin/providers/cloudstack/resource_cloudstack_ipaddress.go @@ -32,6 +32,12 @@ func resourceCloudStackIPAddress() *schema.Resource { Type: schema.TypeString, Computed: true, }, + + "project": &schema.Schema{ + Type: schema.TypeString, + Optional: true, + ForceNew: true, + }, }, } } @@ -46,6 +52,17 @@ func resourceCloudStackIPAddressCreate(d *schema.ResourceData, meta interface{}) // Create a new parameter struct p := cs.Address.NewAssociateIpAddressParams() + // If there is a project supplied, we retreive and set the project id + if project, ok := d.GetOk("project"); ok { + // Retrieve the project UUID + projectid, e := retrieveUUID(cs, "project", project.(string)) + if e != nil { + return e.Error() + } + // Set the default project ID + p.SetProjectid(projectid) + } + if network, ok := d.GetOk("network"); ok { // Retrieve the network UUID networkid, e := retrieveUUID(cs, "network", network.(string)) @@ -118,6 +135,8 @@ func resourceCloudStackIPAddressRead(d *schema.ResourceData, meta interface{}) e setValueOrUUID(d, "vpc", v.Name, f.Vpcid) } + setValueOrUUID(d, "project", f.Project, f.Projectid) + return nil } diff --git a/builtin/providers/cloudstack/resource_cloudstack_network.go b/builtin/providers/cloudstack/resource_cloudstack_network.go index a23547896..eebac4d73 100644 --- a/builtin/providers/cloudstack/resource_cloudstack_network.go +++ b/builtin/providers/cloudstack/resource_cloudstack_network.go @@ -57,6 +57,12 @@ func resourceCloudStackNetwork() *schema.Resource { Required: true, ForceNew: true, }, + + "project": &schema.Schema{ + Type: schema.TypeString, + Optional: true, + ForceNew: true, + }, }, } } @@ -87,6 +93,17 @@ func resourceCloudStackNetworkCreate(d *schema.ResourceData, meta interface{}) e // Create a new parameter struct p := cs.Network.NewCreateNetworkParams(displaytext.(string), name, networkofferingid, zoneid) + // If there is a project supplied, we retreive and set the project id + if project, ok := d.GetOk("project"); ok { + // Retrieve the project UUID + projectid, e := retrieveUUID(cs, "project", project.(string)) + if e != nil { + return e.Error() + } + // Set the default project ID + p.SetProjectid(projectid) + } + // Get the network details from the CIDR m, err := parseCIDR(d.Get("cidr").(string)) if err != nil { @@ -152,6 +169,7 @@ func resourceCloudStackNetworkRead(d *schema.ResourceData, meta interface{}) err setValueOrUUID(d, "network_offering", n.Networkofferingname, n.Networkofferingid) setValueOrUUID(d, "zone", n.Zonename, n.Zoneid) + setValueOrUUID(d, "project", n.Project, n.Projectid) return nil } diff --git a/builtin/providers/cloudstack/resource_cloudstack_vpc.go b/builtin/providers/cloudstack/resource_cloudstack_vpc.go index cb829495b..8926b6e7f 100644 --- a/builtin/providers/cloudstack/resource_cloudstack_vpc.go +++ b/builtin/providers/cloudstack/resource_cloudstack_vpc.go @@ -45,6 +45,11 @@ func resourceCloudStackVPC() *schema.Resource { Required: true, ForceNew: true, }, + "project": &schema.Schema{ + Type: schema.TypeString, + Optional: true, + ForceNew: true, + }, }, } } @@ -75,6 +80,17 @@ func resourceCloudStackVPCCreate(d *schema.ResourceData, meta interface{}) error // Create a new parameter struct p := cs.VPC.NewCreateVPCParams(d.Get("cidr").(string), displaytext.(string), name, vpcofferingid, zoneid) + // If there is a project supplied, we retreive and set the project id + if project, ok := d.GetOk("project"); ok { + // Retrieve the project UUID + projectid, e := retrieveUUID(cs, "project", project.(string)) + if e != nil { + return e.Error() + } + // Set the default project ID + p.SetProjectid(projectid) + } + // Create the new VPC r, err := cs.VPC.CreateVPC(p) if err != nil { @@ -115,6 +131,7 @@ func resourceCloudStackVPCRead(d *schema.ResourceData, meta interface{}) error { } setValueOrUUID(d, "vpc_offering", o.Name, v.Vpcofferingid) + setValueOrUUID(d, "project", v.Project, v.Projectid) return nil }