Add project parameter to VPC and network Cloudstack resources

This commit is contained in:
Hany Fahim 2015-08-19 17:56:57 -04:00
parent 9756946e3c
commit 228da7cf27
2 changed files with 35 additions and 0 deletions

View File

@ -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
}

View File

@ -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
}