Small refactor of the UUID/UnlimitedResourceID logic

This makes things a little more generic and robust.
This commit is contained in:
Sander van Harmelen 2015-10-05 14:05:21 +02:00
parent 6fb61e3d98
commit 350b8e2df2
26 changed files with 206 additions and 207 deletions

View File

@ -32,18 +32,18 @@ func testSetValueOnResourceData(t *testing.T) {
d := schema.ResourceData{} d := schema.ResourceData{}
d.Set("id", "name") d.Set("id", "name")
setValueOrUUID(&d, "id", "name", "54711781-274e-41b2-83c0-17194d0108f7") setValueOrID(&d, "id", "name", "54711781-274e-41b2-83c0-17194d0108f7")
if d.Get("id").(string) != "name" { if d.Get("id").(string) != "name" {
t.Fatal("err: 'id' does not match 'name'") t.Fatal("err: 'id' does not match 'name'")
} }
} }
func testSetUUIDOnResourceData(t *testing.T) { func testSetIDOnResourceData(t *testing.T) {
d := schema.ResourceData{} d := schema.ResourceData{}
d.Set("id", "54711781-274e-41b2-83c0-17194d0108f7") d.Set("id", "54711781-274e-41b2-83c0-17194d0108f7")
setValueOrUUID(&d, "id", "name", "54711781-274e-41b2-83c0-17194d0108f7") setValueOrID(&d, "id", "name", "54711781-274e-41b2-83c0-17194d0108f7")
if d.Get("id").(string) != "54711781-274e-41b2-83c0-17194d0108f7" { if d.Get("id").(string) != "54711781-274e-41b2-83c0-17194d0108f7" {
t.Fatal("err: 'id' doest not match '54711781-274e-41b2-83c0-17194d0108f7'") t.Fatal("err: 'id' doest not match '54711781-274e-41b2-83c0-17194d0108f7'")

View File

@ -80,12 +80,12 @@ func resourceCloudStackDiskCreate(d *schema.ResourceData, meta interface{}) erro
// Create a new parameter struct // Create a new parameter struct
p := cs.Volume.NewCreateVolumeParams(name) p := cs.Volume.NewCreateVolumeParams(name)
// Retrieve the disk_offering UUID // Retrieve the disk_offering ID
diskofferingid, e := retrieveUUID(cs, "disk_offering", d.Get("disk_offering").(string)) diskofferingid, e := retrieveID(cs, "disk_offering", d.Get("disk_offering").(string))
if e != nil { if e != nil {
return e.Error() return e.Error()
} }
// Set the disk_offering UUID // Set the disk_offering ID
p.SetDiskofferingid(diskofferingid) p.SetDiskofferingid(diskofferingid)
if d.Get("size").(int) != 0 { if d.Get("size").(int) != 0 {
@ -95,8 +95,8 @@ func resourceCloudStackDiskCreate(d *schema.ResourceData, meta interface{}) erro
// If there is a project supplied, we retrieve and set the project id // If there is a project supplied, we retrieve and set the project id
if project, ok := d.GetOk("project"); ok { if project, ok := d.GetOk("project"); ok {
// Retrieve the project UUID // Retrieve the project ID
projectid, e := retrieveUUID(cs, "project", project.(string)) projectid, e := retrieveID(cs, "project", project.(string))
if e != nil { if e != nil {
return e.Error() return e.Error()
} }
@ -104,8 +104,8 @@ func resourceCloudStackDiskCreate(d *schema.ResourceData, meta interface{}) erro
p.SetProjectid(projectid) p.SetProjectid(projectid)
} }
// Retrieve the zone UUID // Retrieve the zone ID
zoneid, e := retrieveUUID(cs, "zone", d.Get("zone").(string)) zoneid, e := retrieveID(cs, "zone", d.Get("zone").(string))
if e != nil { if e != nil {
return e.Error() return e.Error()
} }
@ -118,7 +118,7 @@ func resourceCloudStackDiskCreate(d *schema.ResourceData, meta interface{}) erro
return fmt.Errorf("Error creating the new disk %s: %s", name, err) return fmt.Errorf("Error creating the new disk %s: %s", name, err)
} }
// Set the volume UUID and partials // Set the volume ID and partials
d.SetId(r.Id) d.SetId(r.Id)
d.SetPartial("name") d.SetPartial("name")
d.SetPartial("device") d.SetPartial("device")
@ -160,9 +160,9 @@ func resourceCloudStackDiskRead(d *schema.ResourceData, meta interface{}) error
d.Set("attach", v.Attached != "") // If attached this will contain a timestamp when attached d.Set("attach", v.Attached != "") // If attached this will contain a timestamp when attached
d.Set("size", int(v.Size/(1024*1024*1024))) // Needed to get GB's again d.Set("size", int(v.Size/(1024*1024*1024))) // Needed to get GB's again
setValueOrUUID(d, "disk_offering", v.Diskofferingname, v.Diskofferingid) setValueOrID(d, "disk_offering", v.Diskofferingname, v.Diskofferingid)
setValueOrUUID(d, "project", v.Project, v.Projectid) setValueOrID(d, "project", v.Project, v.Projectid)
setValueOrUUID(d, "zone", v.Zonename, v.Zoneid) setValueOrID(d, "zone", v.Zonename, v.Zoneid)
if v.Attached != "" { if v.Attached != "" {
// Get the virtual machine details // Get the virtual machine details
@ -184,7 +184,7 @@ func resourceCloudStackDiskRead(d *schema.ResourceData, meta interface{}) error
} }
d.Set("device", retrieveDeviceName(v.Deviceid, c.Name)) d.Set("device", retrieveDeviceName(v.Deviceid, c.Name))
setValueOrUUID(d, "virtual_machine", v.Vmname, v.Virtualmachineid) setValueOrID(d, "virtual_machine", v.Vmname, v.Virtualmachineid)
} }
return nil return nil
@ -205,13 +205,13 @@ func resourceCloudStackDiskUpdate(d *schema.ResourceData, meta interface{}) erro
// Create a new parameter struct // Create a new parameter struct
p := cs.Volume.NewResizeVolumeParams(d.Id()) p := cs.Volume.NewResizeVolumeParams(d.Id())
// Retrieve the disk_offering UUID // Retrieve the disk_offering ID
diskofferingid, e := retrieveUUID(cs, "disk_offering", d.Get("disk_offering").(string)) diskofferingid, e := retrieveID(cs, "disk_offering", d.Get("disk_offering").(string))
if e != nil { if e != nil {
return e.Error() return e.Error()
} }
// Set the disk_offering UUID // Set the disk_offering ID
p.SetDiskofferingid(diskofferingid) p.SetDiskofferingid(diskofferingid)
if d.Get("size").(int) != 0 { if d.Get("size").(int) != 0 {
@ -228,7 +228,7 @@ func resourceCloudStackDiskUpdate(d *schema.ResourceData, meta interface{}) erro
return fmt.Errorf("Error changing disk offering/size for disk %s: %s", name, err) return fmt.Errorf("Error changing disk offering/size for disk %s: %s", name, err)
} }
// Update the volume UUID and set partials // Update the volume ID and set partials
d.SetId(r.Id) d.SetId(r.Id)
d.SetPartial("disk_offering") d.SetPartial("disk_offering")
d.SetPartial("size") d.SetPartial("size")
@ -278,7 +278,7 @@ func resourceCloudStackDiskDelete(d *schema.ResourceData, meta interface{}) erro
// Delete the voluem // Delete the voluem
if _, err := cs.Volume.DeleteVolume(p); err != nil { if _, err := cs.Volume.DeleteVolume(p); err != nil {
// This is a very poor way to be told the UUID does no longer exist :( // This is a very poor way to be told the ID does no longer exist :(
if strings.Contains(err.Error(), fmt.Sprintf( if strings.Contains(err.Error(), fmt.Sprintf(
"Invalid parameter id value=%s due to incorrect long value format, "+ "Invalid parameter id value=%s due to incorrect long value format, "+
"or entity does not exist", d.Id())) { "or entity does not exist", d.Id())) {
@ -299,8 +299,8 @@ func resourceCloudStackDiskAttach(d *schema.ResourceData, meta interface{}) erro
return err return err
} }
// Retrieve the virtual_machine UUID // Retrieve the virtual_machine ID
virtualmachineid, e := retrieveUUID(cs, "virtual_machine", d.Get("virtual_machine").(string)) virtualmachineid, e := retrieveID(cs, "virtual_machine", d.Get("virtual_machine").(string))
if e != nil { if e != nil {
return e.Error() return e.Error()
} }
@ -341,13 +341,13 @@ func resourceCloudStackDiskDetach(d *schema.ResourceData, meta interface{}) erro
// Create a new parameter struct // Create a new parameter struct
p := cs.Volume.NewDetachVolumeParams() p := cs.Volume.NewDetachVolumeParams()
// Set the volume UUID // Set the volume ID
p.SetId(d.Id()) p.SetId(d.Id())
// Detach the currently attached volume // Detach the currently attached volume
if _, err := cs.Volume.DetachVolume(p); err != nil { if _, err := cs.Volume.DetachVolume(p); err != nil {
// Retrieve the virtual_machine UUID // Retrieve the virtual_machine ID
virtualmachineid, e := retrieveUUID(cs, "virtual_machine", d.Get("virtual_machine").(string)) virtualmachineid, e := retrieveID(cs, "virtual_machine", d.Get("virtual_machine").(string))
if e != nil { if e != nil {
return e.Error() return e.Error()
} }

View File

@ -89,8 +89,8 @@ func resourceCloudStackEgressFirewallCreate(d *schema.ResourceData, meta interfa
return err return err
} }
// Retrieve the network UUID // Retrieve the network ID
networkid, e := retrieveUUID(cs, "network", d.Get("network").(string)) networkid, e := retrieveID(cs, "network", d.Get("network").(string))
if e != nil { if e != nil {
return e.Error() return e.Error()
} }
@ -222,7 +222,7 @@ func resourceCloudStackEgressFirewallRead(d *schema.ResourceData, meta interface
// Get the rule // Get the rule
r, count, err := cs.Firewall.GetEgressFirewallRuleByID(id.(string)) r, count, err := cs.Firewall.GetEgressFirewallRuleByID(id.(string))
// If the count == 0, there is no object found for this UUID // If the count == 0, there is no object found for this ID
if err != nil { if err != nil {
if count == 0 { if count == 0 {
delete(uuids, "icmp") delete(uuids, "icmp")
@ -415,7 +415,7 @@ func resourceCloudStackEgressFirewallDeleteRule(
// Delete the rule // Delete the rule
if _, err := cs.Firewall.DeleteEgressFirewallRule(p); err != nil { if _, err := cs.Firewall.DeleteEgressFirewallRule(p); err != nil {
// This is a very poor way to be told the UUID does no longer exist :( // This is a very poor way to be told the ID does no longer exist :(
if strings.Contains(err.Error(), fmt.Sprintf( if strings.Contains(err.Error(), fmt.Sprintf(
"Invalid parameter id value=%s due to incorrect long value format, "+ "Invalid parameter id value=%s due to incorrect long value format, "+
"or entity does not exist", id.(string))) { "or entity does not exist", id.(string))) {

View File

@ -123,13 +123,13 @@ func testAccCheckCloudStackEgressFirewallRulesExist(n string) resource.TestCheck
return fmt.Errorf("No firewall ID is set") return fmt.Errorf("No firewall ID is set")
} }
for k, uuid := range rs.Primary.Attributes { for k, id := range rs.Primary.Attributes {
if !strings.Contains(k, ".uuids.") || strings.HasSuffix(k, ".uuids.#") { if !strings.Contains(k, ".uuids.") || strings.HasSuffix(k, ".uuids.#") {
continue continue
} }
cs := testAccProvider.Meta().(*cloudstack.CloudStackClient) cs := testAccProvider.Meta().(*cloudstack.CloudStackClient)
_, count, err := cs.Firewall.GetEgressFirewallRuleByID(uuid) _, count, err := cs.Firewall.GetEgressFirewallRuleByID(id)
if err != nil { if err != nil {
return err return err
@ -156,12 +156,12 @@ func testAccCheckCloudStackEgressFirewallDestroy(s *terraform.State) error {
return fmt.Errorf("No instance ID is set") return fmt.Errorf("No instance ID is set")
} }
for k, uuid := range rs.Primary.Attributes { for k, id := range rs.Primary.Attributes {
if !strings.Contains(k, ".uuids.") || strings.HasSuffix(k, ".uuids.#") { if !strings.Contains(k, ".uuids.") || strings.HasSuffix(k, ".uuids.#") {
continue continue
} }
_, _, err := cs.Firewall.GetEgressFirewallRuleByID(uuid) _, _, err := cs.Firewall.GetEgressFirewallRuleByID(id)
if err == nil { if err == nil {
return fmt.Errorf("Egress rule %s still exists", rs.Primary.ID) return fmt.Errorf("Egress rule %s still exists", rs.Primary.ID)
} }

View File

@ -89,8 +89,8 @@ func resourceCloudStackFirewallCreate(d *schema.ResourceData, meta interface{})
return err return err
} }
// Retrieve the ipaddress UUID // Retrieve the ipaddress ID
ipaddressid, e := retrieveUUID(cs, "ipaddress", d.Get("ipaddress").(string)) ipaddressid, e := retrieveID(cs, "ipaddress", d.Get("ipaddress").(string))
if e != nil { if e != nil {
return e.Error() return e.Error()
} }
@ -222,7 +222,7 @@ func resourceCloudStackFirewallRead(d *schema.ResourceData, meta interface{}) er
// Get the rule // Get the rule
r, count, err := cs.Firewall.GetFirewallRuleByID(id.(string)) r, count, err := cs.Firewall.GetFirewallRuleByID(id.(string))
// If the count == 0, there is no object found for this UUID // If the count == 0, there is no object found for this ID
if err != nil { if err != nil {
if count == 0 { if count == 0 {
delete(uuids, "icmp") delete(uuids, "icmp")
@ -415,7 +415,7 @@ func resourceCloudStackFirewallDeleteRule(
// Delete the rule // Delete the rule
if _, err := cs.Firewall.DeleteFirewallRule(p); err != nil { if _, err := cs.Firewall.DeleteFirewallRule(p); err != nil {
// This is a very poor way to be told the UUID does no longer exist :( // This is a very poor way to be told the ID does no longer exist :(
if strings.Contains(err.Error(), fmt.Sprintf( if strings.Contains(err.Error(), fmt.Sprintf(
"Invalid parameter id value=%s due to incorrect long value format, "+ "Invalid parameter id value=%s due to incorrect long value format, "+
"or entity does not exist", id.(string))) { "or entity does not exist", id.(string))) {

View File

@ -110,13 +110,13 @@ func testAccCheckCloudStackFirewallRulesExist(n string) resource.TestCheckFunc {
return fmt.Errorf("No firewall ID is set") return fmt.Errorf("No firewall ID is set")
} }
for k, uuid := range rs.Primary.Attributes { for k, id := range rs.Primary.Attributes {
if !strings.Contains(k, ".uuids.") || strings.HasSuffix(k, ".uuids.#") { if !strings.Contains(k, ".uuids.") || strings.HasSuffix(k, ".uuids.#") {
continue continue
} }
cs := testAccProvider.Meta().(*cloudstack.CloudStackClient) cs := testAccProvider.Meta().(*cloudstack.CloudStackClient)
_, count, err := cs.Firewall.GetFirewallRuleByID(uuid) _, count, err := cs.Firewall.GetFirewallRuleByID(id)
if err != nil { if err != nil {
return err return err
@ -143,12 +143,12 @@ func testAccCheckCloudStackFirewallDestroy(s *terraform.State) error {
return fmt.Errorf("No instance ID is set") return fmt.Errorf("No instance ID is set")
} }
for k, uuid := range rs.Primary.Attributes { for k, id := range rs.Primary.Attributes {
if !strings.Contains(k, ".uuids.") || strings.HasSuffix(k, ".uuids.#") { if !strings.Contains(k, ".uuids.") || strings.HasSuffix(k, ".uuids.#") {
continue continue
} }
_, _, err := cs.Firewall.GetFirewallRuleByID(uuid) _, _, err := cs.Firewall.GetFirewallRuleByID(id)
if err == nil { if err == nil {
return fmt.Errorf("Firewall rule %s still exists", rs.Primary.ID) return fmt.Errorf("Firewall rule %s still exists", rs.Primary.ID)
} }

View File

@ -100,14 +100,14 @@ func resourceCloudStackInstance() *schema.Resource {
func resourceCloudStackInstanceCreate(d *schema.ResourceData, meta interface{}) error { func resourceCloudStackInstanceCreate(d *schema.ResourceData, meta interface{}) error {
cs := meta.(*cloudstack.CloudStackClient) cs := meta.(*cloudstack.CloudStackClient)
// Retrieve the service_offering UUID // Retrieve the service_offering ID
serviceofferingid, e := retrieveUUID(cs, "service_offering", d.Get("service_offering").(string)) serviceofferingid, e := retrieveID(cs, "service_offering", d.Get("service_offering").(string))
if e != nil { if e != nil {
return e.Error() return e.Error()
} }
// Retrieve the zone UUID // Retrieve the zone ID
zoneid, e := retrieveUUID(cs, "zone", d.Get("zone").(string)) zoneid, e := retrieveID(cs, "zone", d.Get("zone").(string))
if e != nil { if e != nil {
return e.Error() return e.Error()
} }
@ -118,8 +118,8 @@ func resourceCloudStackInstanceCreate(d *schema.ResourceData, meta interface{})
return err return err
} }
// Retrieve the template UUID // Retrieve the template ID
templateid, e := retrieveTemplateUUID(cs, zone.Id, d.Get("template").(string)) templateid, e := retrieveTemplateID(cs, zone.Id, d.Get("template").(string))
if e != nil { if e != nil {
return e.Error() return e.Error()
} }
@ -139,8 +139,8 @@ func resourceCloudStackInstanceCreate(d *schema.ResourceData, meta interface{})
} }
if zone.Networktype == "Advanced" { if zone.Networktype == "Advanced" {
// Retrieve the network UUID // Retrieve the network ID
networkid, e := retrieveUUID(cs, "network", d.Get("network").(string)) networkid, e := retrieveID(cs, "network", d.Get("network").(string))
if e != nil { if e != nil {
return e.Error() return e.Error()
} }
@ -155,8 +155,8 @@ func resourceCloudStackInstanceCreate(d *schema.ResourceData, meta interface{})
// If there is a project supplied, we retrieve and set the project id // If there is a project supplied, we retrieve and set the project id
if project, ok := d.GetOk("project"); ok { if project, ok := d.GetOk("project"); ok {
// Retrieve the project UUID // Retrieve the project ID
projectid, e := retrieveUUID(cs, "project", project.(string)) projectid, e := retrieveID(cs, "project", project.(string))
if e != nil { if e != nil {
return e.Error() return e.Error()
} }
@ -229,11 +229,11 @@ func resourceCloudStackInstanceRead(d *schema.ResourceData, meta interface{}) er
d.Set("ipaddress", vm.Nic[0].Ipaddress) d.Set("ipaddress", vm.Nic[0].Ipaddress)
//NB cloudstack sometimes sends back the wrong keypair name, so dont update it //NB cloudstack sometimes sends back the wrong keypair name, so dont update it
setValueOrUUID(d, "network", vm.Nic[0].Networkname, vm.Nic[0].Networkid) setValueOrID(d, "network", vm.Nic[0].Networkname, vm.Nic[0].Networkid)
setValueOrUUID(d, "service_offering", vm.Serviceofferingname, vm.Serviceofferingid) setValueOrID(d, "service_offering", vm.Serviceofferingname, vm.Serviceofferingid)
setValueOrUUID(d, "template", vm.Templatename, vm.Templateid) setValueOrID(d, "template", vm.Templatename, vm.Templateid)
setValueOrUUID(d, "project", vm.Project, vm.Projectid) setValueOrID(d, "project", vm.Project, vm.Projectid)
setValueOrUUID(d, "zone", vm.Zonename, vm.Zoneid) setValueOrID(d, "zone", vm.Zonename, vm.Zoneid)
return nil return nil
} }
@ -278,8 +278,8 @@ func resourceCloudStackInstanceUpdate(d *schema.ResourceData, meta interface{})
if d.HasChange("service_offering") { if d.HasChange("service_offering") {
log.Printf("[DEBUG] Service offering changed for %s, starting update", name) log.Printf("[DEBUG] Service offering changed for %s, starting update", name)
// Retrieve the service_offering UUID // Retrieve the service_offering ID
serviceofferingid, e := retrieveUUID(cs, "service_offering", d.Get("service_offering").(string)) serviceofferingid, e := retrieveID(cs, "service_offering", d.Get("service_offering").(string))
if e != nil { if e != nil {
return e.Error() return e.Error()
} }
@ -335,7 +335,7 @@ func resourceCloudStackInstanceDelete(d *schema.ResourceData, meta interface{})
log.Printf("[INFO] Destroying instance: %s", d.Get("name").(string)) log.Printf("[INFO] Destroying instance: %s", d.Get("name").(string))
if _, err := cs.VirtualMachine.DestroyVirtualMachine(p); err != nil { if _, err := cs.VirtualMachine.DestroyVirtualMachine(p); err != nil {
// This is a very poor way to be told the UUID does no longer exist :( // This is a very poor way to be told the ID does no longer exist :(
if strings.Contains(err.Error(), fmt.Sprintf( if strings.Contains(err.Error(), fmt.Sprintf(
"Invalid parameter id value=%s due to incorrect long value format, "+ "Invalid parameter id value=%s due to incorrect long value format, "+
"or entity does not exist", d.Id())) { "or entity does not exist", d.Id())) {

View File

@ -53,8 +53,8 @@ func resourceCloudStackIPAddressCreate(d *schema.ResourceData, meta interface{})
p := cs.Address.NewAssociateIpAddressParams() p := cs.Address.NewAssociateIpAddressParams()
if network, ok := d.GetOk("network"); ok { if network, ok := d.GetOk("network"); ok {
// Retrieve the network UUID // Retrieve the network ID
networkid, e := retrieveUUID(cs, "network", network.(string)) networkid, e := retrieveID(cs, "network", network.(string))
if e != nil { if e != nil {
return e.Error() return e.Error()
} }
@ -64,8 +64,8 @@ func resourceCloudStackIPAddressCreate(d *schema.ResourceData, meta interface{})
} }
if vpc, ok := d.GetOk("vpc"); ok { if vpc, ok := d.GetOk("vpc"); ok {
// Retrieve the vpc UUID // Retrieve the vpc ID
vpcid, e := retrieveUUID(cs, "vpc", vpc.(string)) vpcid, e := retrieveID(cs, "vpc", vpc.(string))
if e != nil { if e != nil {
return e.Error() return e.Error()
} }
@ -76,8 +76,8 @@ func resourceCloudStackIPAddressCreate(d *schema.ResourceData, meta interface{})
// If there is a project supplied, we retrieve and set the project id // If there is a project supplied, we retrieve and set the project id
if project, ok := d.GetOk("project"); ok { if project, ok := d.GetOk("project"); ok {
// Retrieve the project UUID // Retrieve the project ID
projectid, e := retrieveUUID(cs, "project", project.(string)) projectid, e := retrieveID(cs, "project", project.(string))
if e != nil { if e != nil {
return e.Error() return e.Error()
} }
@ -122,7 +122,7 @@ func resourceCloudStackIPAddressRead(d *schema.ResourceData, meta interface{}) e
return err return err
} }
setValueOrUUID(d, "network", n.Name, f.Associatednetworkid) setValueOrID(d, "network", n.Name, f.Associatednetworkid)
} }
if _, ok := d.GetOk("vpc"); ok { if _, ok := d.GetOk("vpc"); ok {
@ -132,10 +132,10 @@ func resourceCloudStackIPAddressRead(d *schema.ResourceData, meta interface{}) e
return err return err
} }
setValueOrUUID(d, "vpc", v.Name, f.Vpcid) setValueOrID(d, "vpc", v.Name, f.Vpcid)
} }
setValueOrUUID(d, "project", f.Project, f.Projectid) setValueOrID(d, "project", f.Project, f.Projectid)
return nil return nil
} }
@ -148,7 +148,7 @@ func resourceCloudStackIPAddressDelete(d *schema.ResourceData, meta interface{})
// Disassociate the IP address // Disassociate the IP address
if _, err := cs.Address.DisassociateIpAddress(p); err != nil { if _, err := cs.Address.DisassociateIpAddress(p); err != nil {
// This is a very poor way to be told the UUID does no longer exist :( // This is a very poor way to be told the ID does no longer exist :(
if strings.Contains(err.Error(), fmt.Sprintf( if strings.Contains(err.Error(), fmt.Sprintf(
"Invalid parameter id value=%s due to incorrect long value format, "+ "Invalid parameter id value=%s due to incorrect long value format, "+
"or entity does not exist", d.Id())) { "or entity does not exist", d.Id())) {

View File

@ -89,9 +89,9 @@ func resourceCloudStackLoadBalancerRuleCreate(d *schema.ResourceData, meta inter
p.SetDescription(d.Get("name").(string)) p.SetDescription(d.Get("name").(string))
} }
// Retrieve the network and the UUID // Retrieve the network and the ID
if network, ok := d.GetOk("network"); ok { if network, ok := d.GetOk("network"); ok {
networkid, e := retrieveUUID(cs, "network", network.(string)) networkid, e := retrieveID(cs, "network", network.(string))
if e != nil { if e != nil {
return e.Error() return e.Error()
} }
@ -100,8 +100,8 @@ func resourceCloudStackLoadBalancerRuleCreate(d *schema.ResourceData, meta inter
p.SetNetworkid(networkid) p.SetNetworkid(networkid)
} }
// Retrieve the ipaddress UUID // Retrieve the ipaddress ID
ipaddressid, e := retrieveUUID(cs, "ipaddress", d.Get("ipaddress").(string)) ipaddressid, e := retrieveID(cs, "ipaddress", d.Get("ipaddress").(string))
if e != nil { if e != nil {
return e.Error() return e.Error()
} }
@ -113,7 +113,7 @@ func resourceCloudStackLoadBalancerRuleCreate(d *schema.ResourceData, meta inter
return err return err
} }
// Set the load balancer rule UUID and set partials // Set the load balancer rule ID and set partials
d.SetId(r.Id) d.SetId(r.Id)
d.SetPartial("name") d.SetPartial("name")
d.SetPartial("description") d.SetPartial("description")
@ -163,7 +163,7 @@ func resourceCloudStackLoadBalancerRuleRead(d *schema.ResourceData, meta interfa
d.Set("public_port", lb.Publicport) d.Set("public_port", lb.Publicport)
d.Set("private_port", lb.Privateport) d.Set("private_port", lb.Privateport)
setValueOrUUID(d, "ipaddress", lb.Publicip, lb.Publicipid) setValueOrID(d, "ipaddress", lb.Publicip, lb.Publicipid)
// Only set network if user specified it to avoid spurious diffs // Only set network if user specified it to avoid spurious diffs
if _, ok := d.GetOk("network"); ok { if _, ok := d.GetOk("network"); ok {
@ -171,7 +171,7 @@ func resourceCloudStackLoadBalancerRuleRead(d *schema.ResourceData, meta interfa
if err != nil { if err != nil {
return err return err
} }
setValueOrUUID(d, "network", network.Name, lb.Networkid) setValueOrID(d, "network", network.Name, lb.Networkid)
} }
return nil return nil
@ -229,7 +229,7 @@ func resourceCloudStackLoadBalancerRuleDelete(d *schema.ResourceData, meta inter
log.Printf("[INFO] Deleting load balancer rule: %s", d.Get("name").(string)) log.Printf("[INFO] Deleting load balancer rule: %s", d.Get("name").(string))
if _, err := cs.LoadBalancer.DeleteLoadBalancerRule(p); err != nil { if _, err := cs.LoadBalancer.DeleteLoadBalancerRule(p); err != nil {
// This is a very poor way to be told the UUID does no longer exist :( // This is a very poor way to be told the ID does no longer exist :(
if !strings.Contains(err.Error(), fmt.Sprintf( if !strings.Contains(err.Error(), fmt.Sprintf(
"Invalid parameter id value=%s due to incorrect long value format, "+ "Invalid parameter id value=%s due to incorrect long value format, "+
"or entity does not exist", d.Id())) { "or entity does not exist", d.Id())) {

View File

@ -223,12 +223,12 @@ func testAccCheckCloudStackLoadBalancerRuleDestroy(s *terraform.State) error {
return fmt.Errorf("No Loadbalancer rule ID is set") return fmt.Errorf("No Loadbalancer rule ID is set")
} }
for k, uuid := range rs.Primary.Attributes { for k, id := range rs.Primary.Attributes {
if !strings.Contains(k, "uuid") { if !strings.Contains(k, "uuid") {
continue continue
} }
_, _, err := cs.LoadBalancer.GetLoadBalancerRuleByID(uuid) _, _, err := cs.LoadBalancer.GetLoadBalancerRuleByID(id)
if err == nil { if err == nil {
return fmt.Errorf("Loadbalancer rule %s still exists", rs.Primary.ID) return fmt.Errorf("Loadbalancer rule %s still exists", rs.Primary.ID)
} }

View File

@ -72,14 +72,14 @@ func resourceCloudStackNetworkCreate(d *schema.ResourceData, meta interface{}) e
name := d.Get("name").(string) name := d.Get("name").(string)
// Retrieve the network_offering UUID // Retrieve the network_offering ID
networkofferingid, e := retrieveUUID(cs, "network_offering", d.Get("network_offering").(string)) networkofferingid, e := retrieveID(cs, "network_offering", d.Get("network_offering").(string))
if e != nil { if e != nil {
return e.Error() return e.Error()
} }
// Retrieve the zone UUID // Retrieve the zone ID
zoneid, e := retrieveUUID(cs, "zone", d.Get("zone").(string)) zoneid, e := retrieveID(cs, "zone", d.Get("zone").(string))
if e != nil { if e != nil {
return e.Error() return e.Error()
} }
@ -108,27 +108,27 @@ func resourceCloudStackNetworkCreate(d *schema.ResourceData, meta interface{}) e
// Check is this network needs to be created in a VPC // Check is this network needs to be created in a VPC
vpc := d.Get("vpc").(string) vpc := d.Get("vpc").(string)
if vpc != "" { if vpc != "" {
// Retrieve the vpc UUID // Retrieve the vpc ID
vpcid, e := retrieveUUID(cs, "vpc", vpc) vpcid, e := retrieveID(cs, "vpc", vpc)
if e != nil { if e != nil {
return e.Error() return e.Error()
} }
// Set the vpc UUID // Set the vpc ID
p.SetVpcid(vpcid) p.SetVpcid(vpcid)
// Since we're in a VPC, check if we want to assiciate an ACL list // Since we're in a VPC, check if we want to assiciate an ACL list
aclid := d.Get("aclid").(string) aclid := d.Get("aclid").(string)
if aclid != "" { if aclid != "" {
// Set the acl UUID // Set the acl ID
p.SetAclid(aclid) p.SetAclid(aclid)
} }
} }
// If there is a project supplied, we retrieve and set the project id // If there is a project supplied, we retrieve and set the project id
if project, ok := d.GetOk("project"); ok { if project, ok := d.GetOk("project"); ok {
// Retrieve the project UUID // Retrieve the project ID
projectid, e := retrieveUUID(cs, "project", project.(string)) projectid, e := retrieveID(cs, "project", project.(string))
if e != nil { if e != nil {
return e.Error() return e.Error()
} }
@ -167,9 +167,9 @@ func resourceCloudStackNetworkRead(d *schema.ResourceData, meta interface{}) err
d.Set("display_text", n.Displaytext) d.Set("display_text", n.Displaytext)
d.Set("cidr", n.Cidr) d.Set("cidr", n.Cidr)
setValueOrUUID(d, "network_offering", n.Networkofferingname, n.Networkofferingid) setValueOrID(d, "network_offering", n.Networkofferingname, n.Networkofferingid)
setValueOrUUID(d, "project", n.Project, n.Projectid) setValueOrID(d, "project", n.Project, n.Projectid)
setValueOrUUID(d, "zone", n.Zonename, n.Zoneid) setValueOrID(d, "zone", n.Zonename, n.Zoneid)
return nil return nil
} }
@ -200,8 +200,8 @@ func resourceCloudStackNetworkUpdate(d *schema.ResourceData, meta interface{}) e
// Check if the network offering is changed // Check if the network offering is changed
if d.HasChange("network_offering") { if d.HasChange("network_offering") {
// Retrieve the network_offering UUID // Retrieve the network_offering ID
networkofferingid, e := retrieveUUID(cs, "network_offering", d.Get("network_offering").(string)) networkofferingid, e := retrieveID(cs, "network_offering", d.Get("network_offering").(string))
if e != nil { if e != nil {
return e.Error() return e.Error()
} }
@ -228,7 +228,7 @@ func resourceCloudStackNetworkDelete(d *schema.ResourceData, meta interface{}) e
// Delete the network // Delete the network
_, err := cs.Network.DeleteNetwork(p) _, err := cs.Network.DeleteNetwork(p)
if err != nil { if err != nil {
// This is a very poor way to be told the UUID does no longer exist :( // This is a very poor way to be told the ID does no longer exist :(
if strings.Contains(err.Error(), fmt.Sprintf( if strings.Contains(err.Error(), fmt.Sprintf(
"Invalid parameter id value=%s due to incorrect long value format, "+ "Invalid parameter id value=%s due to incorrect long value format, "+
"or entity does not exist", d.Id())) { "or entity does not exist", d.Id())) {

View File

@ -43,8 +43,8 @@ func resourceCloudStackNetworkACLCreate(d *schema.ResourceData, meta interface{}
name := d.Get("name").(string) name := d.Get("name").(string)
// Retrieve the vpc UUID // Retrieve the vpc ID
vpcid, e := retrieveUUID(cs, "vpc", d.Get("vpc").(string)) vpcid, e := retrieveID(cs, "vpc", d.Get("vpc").(string))
if e != nil { if e != nil {
return e.Error() return e.Error()
} }
@ -95,7 +95,7 @@ func resourceCloudStackNetworkACLRead(d *schema.ResourceData, meta interface{})
return err return err
} }
setValueOrUUID(d, "vpc", v.Name, v.Id) setValueOrID(d, "vpc", v.Name, v.Id)
return nil return nil
} }
@ -109,7 +109,7 @@ func resourceCloudStackNetworkACLDelete(d *schema.ResourceData, meta interface{}
// Delete the network ACL list // Delete the network ACL list
_, err := cs.NetworkACL.DeleteNetworkACLList(p) _, err := cs.NetworkACL.DeleteNetworkACLList(p)
if err != nil { if err != nil {
// This is a very poor way to be told the UUID does no longer exist :( // This is a very poor way to be told the ID does no longer exist :(
if strings.Contains(err.Error(), fmt.Sprintf( if strings.Contains(err.Error(), fmt.Sprintf(
"Invalid parameter id value=%s due to incorrect long value format, "+ "Invalid parameter id value=%s due to incorrect long value format, "+
"or entity does not exist", d.Id())) { "or entity does not exist", d.Id())) {

View File

@ -247,7 +247,7 @@ func resourceCloudStackNetworkACLRuleRead(d *schema.ResourceData, meta interface
// Get the rule // Get the rule
r, count, err := cs.NetworkACL.GetNetworkACLByID(id.(string)) r, count, err := cs.NetworkACL.GetNetworkACLByID(id.(string))
// If the count == 0, there is no object found for this UUID // If the count == 0, there is no object found for this ID
if err != nil { if err != nil {
if count == 0 { if count == 0 {
delete(uuids, "icmp") delete(uuids, "icmp")
@ -275,7 +275,7 @@ func resourceCloudStackNetworkACLRuleRead(d *schema.ResourceData, meta interface
// Get the rule // Get the rule
r, count, err := cs.NetworkACL.GetNetworkACLByID(id.(string)) r, count, err := cs.NetworkACL.GetNetworkACLByID(id.(string))
// If the count == 0, there is no object found for this UUID // If the count == 0, there is no object found for this ID
if err != nil { if err != nil {
if count == 0 { if count == 0 {
delete(uuids, "all") delete(uuids, "all")
@ -469,7 +469,7 @@ func resourceCloudStackNetworkACLRuleDeleteRule(
// Delete the rule // Delete the rule
if _, err := cs.NetworkACL.DeleteNetworkACL(p); err != nil { if _, err := cs.NetworkACL.DeleteNetworkACL(p); err != nil {
// This is a very poor way to be told the UUID does no longer exist :( // This is a very poor way to be told the ID does no longer exist :(
if strings.Contains(err.Error(), fmt.Sprintf( if strings.Contains(err.Error(), fmt.Sprintf(
"Invalid parameter id value=%s due to incorrect long value format, "+ "Invalid parameter id value=%s due to incorrect long value format, "+
"or entity does not exist", id.(string))) { "or entity does not exist", id.(string))) {

View File

@ -122,13 +122,13 @@ func testAccCheckCloudStackNetworkACLRulesExist(n string) resource.TestCheckFunc
return fmt.Errorf("No network ACL rule ID is set") return fmt.Errorf("No network ACL rule ID is set")
} }
for k, uuid := range rs.Primary.Attributes { for k, id := range rs.Primary.Attributes {
if !strings.Contains(k, ".uuids.") || strings.HasSuffix(k, ".uuids.#") { if !strings.Contains(k, ".uuids.") || strings.HasSuffix(k, ".uuids.#") {
continue continue
} }
cs := testAccProvider.Meta().(*cloudstack.CloudStackClient) cs := testAccProvider.Meta().(*cloudstack.CloudStackClient)
_, count, err := cs.NetworkACL.GetNetworkACLByID(uuid) _, count, err := cs.NetworkACL.GetNetworkACLByID(id)
if err != nil { if err != nil {
return err return err
@ -155,12 +155,12 @@ func testAccCheckCloudStackNetworkACLRuleDestroy(s *terraform.State) error {
return fmt.Errorf("No network ACL rule ID is set") return fmt.Errorf("No network ACL rule ID is set")
} }
for k, uuid := range rs.Primary.Attributes { for k, id := range rs.Primary.Attributes {
if !strings.Contains(k, ".uuids.") || strings.HasSuffix(k, ".uuids.#") { if !strings.Contains(k, ".uuids.") || strings.HasSuffix(k, ".uuids.#") {
continue continue
} }
_, _, err := cs.NetworkACL.GetNetworkACLByID(uuid) _, _, err := cs.NetworkACL.GetNetworkACLByID(id)
if err == nil { if err == nil {
return fmt.Errorf("Network ACL rule %s still exists", rs.Primary.ID) return fmt.Errorf("Network ACL rule %s still exists", rs.Primary.ID)
} }

View File

@ -41,14 +41,14 @@ func resourceCloudStackNIC() *schema.Resource {
func resourceCloudStackNICCreate(d *schema.ResourceData, meta interface{}) error { func resourceCloudStackNICCreate(d *schema.ResourceData, meta interface{}) error {
cs := meta.(*cloudstack.CloudStackClient) cs := meta.(*cloudstack.CloudStackClient)
// Retrieve the network UUID // Retrieve the network ID
networkid, e := retrieveUUID(cs, "network", d.Get("network").(string)) networkid, e := retrieveID(cs, "network", d.Get("network").(string))
if e != nil { if e != nil {
return e.Error() return e.Error()
} }
// Retrieve the virtual_machine UUID // Retrieve the virtual_machine ID
virtualmachineid, e := retrieveUUID(cs, "virtual_machine", d.Get("virtual_machine").(string)) virtualmachineid, e := retrieveID(cs, "virtual_machine", d.Get("virtual_machine").(string))
if e != nil { if e != nil {
return e.Error() return e.Error()
} }
@ -103,8 +103,8 @@ func resourceCloudStackNICRead(d *schema.ResourceData, meta interface{}) error {
for _, n := range vm.Nic { for _, n := range vm.Nic {
if n.Id == d.Id() { if n.Id == d.Id() {
d.Set("ipaddress", n.Ipaddress) d.Set("ipaddress", n.Ipaddress)
setValueOrUUID(d, "network", n.Networkname, n.Networkid) setValueOrID(d, "network", n.Networkname, n.Networkid)
setValueOrUUID(d, "virtual_machine", vm.Name, vm.Id) setValueOrID(d, "virtual_machine", vm.Name, vm.Id)
found = true found = true
break break
} }
@ -121,8 +121,8 @@ func resourceCloudStackNICRead(d *schema.ResourceData, meta interface{}) error {
func resourceCloudStackNICDelete(d *schema.ResourceData, meta interface{}) error { func resourceCloudStackNICDelete(d *schema.ResourceData, meta interface{}) error {
cs := meta.(*cloudstack.CloudStackClient) cs := meta.(*cloudstack.CloudStackClient)
// Retrieve the virtual_machine UUID // Retrieve the virtual_machine ID
virtualmachineid, e := retrieveUUID(cs, "virtual_machine", d.Get("virtual_machine").(string)) virtualmachineid, e := retrieveID(cs, "virtual_machine", d.Get("virtual_machine").(string))
if e != nil { if e != nil {
return e.Error() return e.Error()
} }
@ -133,7 +133,7 @@ func resourceCloudStackNICDelete(d *schema.ResourceData, meta interface{}) error
// Remove the NIC // Remove the NIC
_, err := cs.VirtualMachine.RemoveNicFromVirtualMachine(p) _, err := cs.VirtualMachine.RemoveNicFromVirtualMachine(p)
if err != nil { if err != nil {
// This is a very poor way to be told the UUID does no longer exist :( // This is a very poor way to be told the ID does no longer exist :(
if strings.Contains(err.Error(), fmt.Sprintf( if strings.Contains(err.Error(), fmt.Sprintf(
"Invalid parameter id value=%s due to incorrect long value format, "+ "Invalid parameter id value=%s due to incorrect long value format, "+
"or entity does not exist", d.Id())) { "or entity does not exist", d.Id())) {

View File

@ -72,8 +72,8 @@ func resourceCloudStackPortForward() *schema.Resource {
func resourceCloudStackPortForwardCreate(d *schema.ResourceData, meta interface{}) error { func resourceCloudStackPortForwardCreate(d *schema.ResourceData, meta interface{}) error {
cs := meta.(*cloudstack.CloudStackClient) cs := meta.(*cloudstack.CloudStackClient)
// Retrieve the ipaddress UUID // Retrieve the ipaddress ID
ipaddressid, e := retrieveUUID(cs, "ipaddress", d.Get("ipaddress").(string)) ipaddressid, e := retrieveID(cs, "ipaddress", d.Get("ipaddress").(string))
if e != nil { if e != nil {
return e.Error() return e.Error()
} }
@ -115,8 +115,8 @@ func resourceCloudStackPortForwardCreateForward(
return err return err
} }
// Retrieve the virtual_machine UUID // Retrieve the virtual_machine ID
virtualmachineid, e := retrieveUUID(cs, "virtual_machine", forward["virtual_machine"].(string)) virtualmachineid, e := retrieveID(cs, "virtual_machine", forward["virtual_machine"].(string))
if e != nil { if e != nil {
return e.Error() return e.Error()
} }
@ -167,7 +167,7 @@ func resourceCloudStackPortForwardRead(d *schema.ResourceData, meta interface{})
// Get the forward // Get the forward
r, count, err := cs.Firewall.GetPortForwardingRuleByID(id.(string)) r, count, err := cs.Firewall.GetPortForwardingRuleByID(id.(string))
// If the count == 0, there is no object found for this UUID // If the count == 0, there is no object found for this ID
if err != nil { if err != nil {
if count == 0 { if count == 0 {
forward["uuid"] = "" forward["uuid"] = ""
@ -192,7 +192,7 @@ func resourceCloudStackPortForwardRead(d *schema.ResourceData, meta interface{})
forward["private_port"] = privPort forward["private_port"] = privPort
forward["public_port"] = pubPort forward["public_port"] = pubPort
if isUUID(forward["virtual_machine"].(string)) { if isID(forward["virtual_machine"].(string)) {
forward["virtual_machine"] = r.Virtualmachineid forward["virtual_machine"] = r.Virtualmachineid
} else { } else {
forward["virtual_machine"] = r.Virtualmachinename forward["virtual_machine"] = r.Virtualmachinename
@ -317,7 +317,7 @@ func resourceCloudStackPortForwardDeleteForward(
// Delete the forward // Delete the forward
if _, err := cs.Firewall.DeletePortForwardingRule(p); err != nil { if _, err := cs.Firewall.DeletePortForwardingRule(p); err != nil {
// This is a very poor way to be told the UUID does no longer exist :( // This is a very poor way to be told the ID does no longer exist :(
if !strings.Contains(err.Error(), fmt.Sprintf( if !strings.Contains(err.Error(), fmt.Sprintf(
"Invalid parameter id value=%s due to incorrect long value format, "+ "Invalid parameter id value=%s due to incorrect long value format, "+
"or entity does not exist", forward["uuid"].(string))) { "or entity does not exist", forward["uuid"].(string))) {
@ -325,6 +325,7 @@ func resourceCloudStackPortForwardDeleteForward(
} }
} }
// Empty the UUID of this rule
forward["uuid"] = "" forward["uuid"] = ""
return nil return nil

View File

@ -102,13 +102,13 @@ func testAccCheckCloudStackPortForwardsExist(n string) resource.TestCheckFunc {
return fmt.Errorf("No port forward ID is set") return fmt.Errorf("No port forward ID is set")
} }
for k, uuid := range rs.Primary.Attributes { for k, id := range rs.Primary.Attributes {
if !strings.Contains(k, "uuid") { if !strings.Contains(k, "uuid") {
continue continue
} }
cs := testAccProvider.Meta().(*cloudstack.CloudStackClient) cs := testAccProvider.Meta().(*cloudstack.CloudStackClient)
_, count, err := cs.Firewall.GetPortForwardingRuleByID(uuid) _, count, err := cs.Firewall.GetPortForwardingRuleByID(id)
if err != nil { if err != nil {
return err return err
@ -135,12 +135,12 @@ func testAccCheckCloudStackPortForwardDestroy(s *terraform.State) error {
return fmt.Errorf("No port forward ID is set") return fmt.Errorf("No port forward ID is set")
} }
for k, uuid := range rs.Primary.Attributes { for k, id := range rs.Primary.Attributes {
if !strings.Contains(k, "uuid") { if !strings.Contains(k, "uuid") {
continue continue
} }
_, _, err := cs.Firewall.GetPortForwardingRuleByID(uuid) _, _, err := cs.Firewall.GetPortForwardingRuleByID(id)
if err == nil { if err == nil {
return fmt.Errorf("Port forward %s still exists", rs.Primary.ID) return fmt.Errorf("Port forward %s still exists", rs.Primary.ID)
} }

View File

@ -44,8 +44,8 @@ func resourceCloudStackSecondaryIPAddressCreate(d *schema.ResourceData, meta int
nicid := d.Get("nicid").(string) nicid := d.Get("nicid").(string)
if nicid == "" { if nicid == "" {
// Retrieve the virtual_machine UUID // Retrieve the virtual_machine ID
virtualmachineid, e := retrieveUUID(cs, "virtual_machine", d.Get("virtual_machine").(string)) virtualmachineid, e := retrieveID(cs, "virtual_machine", d.Get("virtual_machine").(string))
if e != nil { if e != nil {
return e.Error() return e.Error()
} }
@ -84,8 +84,8 @@ func resourceCloudStackSecondaryIPAddressCreate(d *schema.ResourceData, meta int
func resourceCloudStackSecondaryIPAddressRead(d *schema.ResourceData, meta interface{}) error { func resourceCloudStackSecondaryIPAddressRead(d *schema.ResourceData, meta interface{}) error {
cs := meta.(*cloudstack.CloudStackClient) cs := meta.(*cloudstack.CloudStackClient)
// Retrieve the virtual_machine UUID // Retrieve the virtual_machine ID
virtualmachineid, e := retrieveUUID(cs, "virtual_machine", d.Get("virtual_machine").(string)) virtualmachineid, e := retrieveID(cs, "virtual_machine", d.Get("virtual_machine").(string))
if e != nil { if e != nil {
return e.Error() return e.Error()
} }
@ -146,7 +146,7 @@ func resourceCloudStackSecondaryIPAddressDelete(d *schema.ResourceData, meta int
log.Printf("[INFO] Removing secondary IP address: %s", d.Get("ipaddress").(string)) log.Printf("[INFO] Removing secondary IP address: %s", d.Get("ipaddress").(string))
if _, err := cs.Nic.RemoveIpFromNic(p); err != nil { if _, err := cs.Nic.RemoveIpFromNic(p); err != nil {
// This is a very poor way to be told the UUID does no longer exist :( // This is a very poor way to be told the ID does no longer exist :(
if strings.Contains(err.Error(), fmt.Sprintf( if strings.Contains(err.Error(), fmt.Sprintf(
"Invalid parameter id value=%s due to incorrect long value format, "+ "Invalid parameter id value=%s due to incorrect long value format, "+
"or entity does not exist", d.Id())) { "or entity does not exist", d.Id())) {

View File

@ -64,8 +64,8 @@ func testAccCheckCloudStackSecondaryIPAddressExists(
cs := testAccProvider.Meta().(*cloudstack.CloudStackClient) cs := testAccProvider.Meta().(*cloudstack.CloudStackClient)
// Retrieve the virtual_machine UUID // Retrieve the virtual_machine ID
virtualmachineid, e := retrieveUUID( virtualmachineid, e := retrieveID(
cs, "virtual_machine", rs.Primary.Attributes["virtual_machine"]) cs, "virtual_machine", rs.Primary.Attributes["virtual_machine"])
if e != nil { if e != nil {
return e.Error() return e.Error()
@ -136,8 +136,8 @@ func testAccCheckCloudStackSecondaryIPAddressDestroy(s *terraform.State) error {
return fmt.Errorf("No IP address ID is set") return fmt.Errorf("No IP address ID is set")
} }
// Retrieve the virtual_machine UUID // Retrieve the virtual_machine ID
virtualmachineid, e := retrieveUUID( virtualmachineid, e := retrieveID(
cs, "virtual_machine", rs.Primary.Attributes["virtual_machine"]) cs, "virtual_machine", rs.Primary.Attributes["virtual_machine"])
if e != nil { if e != nil {
return e.Error() return e.Error()

View File

@ -116,7 +116,7 @@ func resourceCloudStackSSHKeyPairDelete(d *schema.ResourceData, meta interface{}
// Remove the SSH Keypair // Remove the SSH Keypair
_, err := cs.SSH.DeleteSSHKeyPair(p) _, err := cs.SSH.DeleteSSHKeyPair(p)
if err != nil { if err != nil {
// This is a very poor way to be told the UUID does no longer exist :( // This is a very poor way to be told the ID does no longer exist :(
if strings.Contains(err.Error(), fmt.Sprintf( if strings.Contains(err.Error(), fmt.Sprintf(
"A key pair with name '%s' does not exist for account", d.Id())) { "A key pair with name '%s' does not exist for account", d.Id())) {
return nil return nil

View File

@ -124,14 +124,14 @@ func resourceCloudStackTemplateCreate(d *schema.ResourceData, meta interface{})
displaytext = name displaytext = name
} }
// Retrieve the os_type UUID // Retrieve the os_type ID
ostypeid, e := retrieveUUID(cs, "os_type", d.Get("os_type").(string)) ostypeid, e := retrieveID(cs, "os_type", d.Get("os_type").(string))
if e != nil { if e != nil {
return e.Error() return e.Error()
} }
// Retrieve the zone UUID // Retrieve the zone ID
zoneid, e := retrieveUUID(cs, "zone", d.Get("zone").(string)) zoneid, e := retrieveID(cs, "zone", d.Get("zone").(string))
if e != nil { if e != nil {
return e.Error() return e.Error()
} }
@ -169,8 +169,8 @@ func resourceCloudStackTemplateCreate(d *schema.ResourceData, meta interface{})
// If there is a project supplied, we retrieve and set the project id // If there is a project supplied, we retrieve and set the project id
if project, ok := d.GetOk("project"); ok { if project, ok := d.GetOk("project"); ok {
// Retrieve the project UUID // Retrieve the project ID
projectid, e := retrieveUUID(cs, "project", project.(string)) projectid, e := retrieveID(cs, "project", project.(string))
if e != nil { if e != nil {
return e.Error() return e.Error()
} }
@ -236,15 +236,9 @@ func resourceCloudStackTemplateRead(d *schema.ResourceData, meta interface{}) er
d.Set("password_enabled", t.Passwordenabled) d.Set("password_enabled", t.Passwordenabled)
d.Set("is_ready", t.Isready) d.Set("is_ready", t.Isready)
setValueOrUUID(d, "project", t.Project, t.Projectid) setValueOrID(d, "os_type", t.Ostypename, t.Ostypeid)
setValueOrID(d, "project", t.Project, t.Projectid)
if t.Zoneid == "" { setValueOrID(d, "zone", t.Zonename, t.Zoneid)
setValueOrUUID(d, "zone", UnlimitedResourceID, UnlimitedResourceID)
} else {
setValueOrUUID(d, "zone", t.Zonename, t.Zoneid)
}
setValueOrUUID(d, "os_type", t.Ostypename, t.Ostypeid)
return nil return nil
} }
@ -273,7 +267,7 @@ func resourceCloudStackTemplateUpdate(d *schema.ResourceData, meta interface{})
} }
if d.HasChange("os_type") { if d.HasChange("os_type") {
ostypeid, e := retrieveUUID(cs, "os_type", d.Get("os_type").(string)) ostypeid, e := retrieveID(cs, "os_type", d.Get("os_type").(string))
if e != nil { if e != nil {
return e.Error() return e.Error()
} }
@ -302,7 +296,7 @@ func resourceCloudStackTemplateDelete(d *schema.ResourceData, meta interface{})
log.Printf("[INFO] Deleting template: %s", d.Get("name").(string)) log.Printf("[INFO] Deleting template: %s", d.Get("name").(string))
_, err := cs.Template.DeleteTemplate(p) _, err := cs.Template.DeleteTemplate(p)
if err != nil { if err != nil {
// This is a very poor way to be told the UUID does no longer exist :( // This is a very poor way to be told the ID does no longer exist :(
if strings.Contains(err.Error(), fmt.Sprintf( if strings.Contains(err.Error(), fmt.Sprintf(
"Invalid parameter id value=%s due to incorrect long value format, "+ "Invalid parameter id value=%s due to incorrect long value format, "+
"or entity does not exist", d.Id())) { "or entity does not exist", d.Id())) {

View File

@ -66,14 +66,14 @@ func resourceCloudStackVPCCreate(d *schema.ResourceData, meta interface{}) error
name := d.Get("name").(string) name := d.Get("name").(string)
// Retrieve the vpc_offering UUID // Retrieve the vpc_offering ID
vpcofferingid, e := retrieveUUID(cs, "vpc_offering", d.Get("vpc_offering").(string)) vpcofferingid, e := retrieveID(cs, "vpc_offering", d.Get("vpc_offering").(string))
if e != nil { if e != nil {
return e.Error() return e.Error()
} }
// Retrieve the zone UUID // Retrieve the zone ID
zoneid, e := retrieveUUID(cs, "zone", d.Get("zone").(string)) zoneid, e := retrieveID(cs, "zone", d.Get("zone").(string))
if e != nil { if e != nil {
return e.Error() return e.Error()
} }
@ -101,8 +101,8 @@ func resourceCloudStackVPCCreate(d *schema.ResourceData, meta interface{}) error
// If there is a project supplied, we retrieve and set the project id // If there is a project supplied, we retrieve and set the project id
if project, ok := d.GetOk("project"); ok { if project, ok := d.GetOk("project"); ok {
// Retrieve the project UUID // Retrieve the project ID
projectid, e := retrieveUUID(cs, "project", project.(string)) projectid, e := retrieveID(cs, "project", project.(string))
if e != nil { if e != nil {
return e.Error() return e.Error()
} }
@ -148,9 +148,9 @@ func resourceCloudStackVPCRead(d *schema.ResourceData, meta interface{}) error {
return err return err
} }
setValueOrUUID(d, "vpc_offering", o.Name, v.Vpcofferingid) setValueOrID(d, "vpc_offering", o.Name, v.Vpcofferingid)
setValueOrUUID(d, "project", v.Project, v.Projectid) setValueOrID(d, "project", v.Project, v.Projectid)
setValueOrUUID(d, "zone", v.Zonename, v.Zoneid) setValueOrID(d, "zone", v.Zonename, v.Zoneid)
return nil return nil
} }
@ -191,7 +191,7 @@ func resourceCloudStackVPCDelete(d *schema.ResourceData, meta interface{}) error
// Delete the VPC // Delete the VPC
_, err := cs.VPC.DeleteVPC(p) _, err := cs.VPC.DeleteVPC(p)
if err != nil { if err != nil {
// This is a very poor way to be told the UUID does no longer exist :( // This is a very poor way to be told the ID does no longer exist :(
if strings.Contains(err.Error(), fmt.Sprintf( if strings.Contains(err.Error(), fmt.Sprintf(
"Invalid parameter id value=%s due to incorrect long value format, "+ "Invalid parameter id value=%s due to incorrect long value format, "+
"or entity does not exist", d.Id())) { "or entity does not exist", d.Id())) {

View File

@ -81,7 +81,7 @@ func resourceCloudStackVPNConnectionDelete(d *schema.ResourceData, meta interfac
// Delete the VPN Connection // Delete the VPN Connection
_, err := cs.VPN.DeleteVpnConnection(p) _, err := cs.VPN.DeleteVpnConnection(p)
if err != nil { if err != nil {
// This is a very poor way to be told the UUID does no longer exist :( // This is a very poor way to be told the ID does no longer exist :(
if strings.Contains(err.Error(), fmt.Sprintf( if strings.Contains(err.Error(), fmt.Sprintf(
"Invalid parameter id value=%s due to incorrect long value format, "+ "Invalid parameter id value=%s due to incorrect long value format, "+
"or entity does not exist", d.Id())) { "or entity does not exist", d.Id())) {

View File

@ -179,7 +179,7 @@ func resourceCloudStackVPNCustomerGatewayDelete(d *schema.ResourceData, meta int
// Delete the VPN Customer Gateway // Delete the VPN Customer Gateway
_, err := cs.VPN.DeleteVpnCustomerGateway(p) _, err := cs.VPN.DeleteVpnCustomerGateway(p)
if err != nil { if err != nil {
// This is a very poor way to be told the UUID does no longer exist :( // This is a very poor way to be told the ID does no longer exist :(
if strings.Contains(err.Error(), fmt.Sprintf( if strings.Contains(err.Error(), fmt.Sprintf(
"Invalid parameter id value=%s due to incorrect long value format, "+ "Invalid parameter id value=%s due to incorrect long value format, "+
"or entity does not exist", d.Id())) { "or entity does not exist", d.Id())) {

View File

@ -33,8 +33,8 @@ func resourceCloudStackVPNGateway() *schema.Resource {
func resourceCloudStackVPNGatewayCreate(d *schema.ResourceData, meta interface{}) error { func resourceCloudStackVPNGatewayCreate(d *schema.ResourceData, meta interface{}) error {
cs := meta.(*cloudstack.CloudStackClient) cs := meta.(*cloudstack.CloudStackClient)
// Retrieve the VPC UUID // Retrieve the VPC ID
vpcid, e := retrieveUUID(cs, "vpc", d.Get("vpc").(string)) vpcid, e := retrieveID(cs, "vpc", d.Get("vpc").(string))
if e != nil { if e != nil {
return e.Error() return e.Error()
} }
@ -69,7 +69,7 @@ func resourceCloudStackVPNGatewayRead(d *schema.ResourceData, meta interface{})
return err return err
} }
setValueOrUUID(d, "vpc", d.Get("vpc").(string), v.Vpcid) setValueOrID(d, "vpc", d.Get("vpc").(string), v.Vpcid)
d.Set("public_ip", v.Publicip) d.Set("public_ip", v.Publicip)
@ -85,7 +85,7 @@ func resourceCloudStackVPNGatewayDelete(d *schema.ResourceData, meta interface{}
// Delete the VPN Gateway // Delete the VPN Gateway
_, err := cs.VPN.DeleteVpnGateway(p) _, err := cs.VPN.DeleteVpnGateway(p)
if err != nil { if err != nil {
// This is a very poor way to be told the UUID does no longer exist :( // This is a very poor way to be told the ID does no longer exist :(
if strings.Contains(err.Error(), fmt.Sprintf( if strings.Contains(err.Error(), fmt.Sprintf(
"Invalid parameter id value=%s due to incorrect long value format, "+ "Invalid parameter id value=%s due to incorrect long value format, "+
"or entity does not exist", d.Id())) { "or entity does not exist", d.Id())) {

View File

@ -20,46 +20,51 @@ type retrieveError struct {
} }
func (e *retrieveError) Error() error { func (e *retrieveError) Error() error {
return fmt.Errorf("Error retrieving UUID of %s %s: %s", e.name, e.value, e.err) return fmt.Errorf("Error retrieving ID of %s %s: %s", e.name, e.value, e.err)
} }
func setValueOrUUID(d *schema.ResourceData, key string, value string, uuid string) { func setValueOrID(d *schema.ResourceData, key string, value string, id string) {
if isUUID(d.Get(key).(string)) { if isID(d.Get(key).(string)) {
d.Set(key, uuid) // If the given id is an empty string, check if the configured value matches
// the UnlimitedResourceID in which case we set id to UnlimitedResourceID
if id == "" && d.Get(key).(string) == UnlimitedResourceID {
id = UnlimitedResourceID
}
d.Set(key, id)
} else { } else {
d.Set(key, value) d.Set(key, value)
} }
} }
func retrieveUUID(cs *cloudstack.CloudStackClient, name, value string) (uuid string, e *retrieveError) { func retrieveID(cs *cloudstack.CloudStackClient, name, value string) (id string, e *retrieveError) {
// If the supplied value isn't a UUID, try to retrieve the UUID ourselves // If the supplied value isn't a ID, try to retrieve the ID ourselves
if isUUID(value) { if isID(value) {
return value, nil return value, nil
} }
log.Printf("[DEBUG] Retrieving UUID of %s: %s", name, value) log.Printf("[DEBUG] Retrieving ID of %s: %s", name, value)
var err error var err error
switch name { switch name {
case "disk_offering": case "disk_offering":
uuid, err = cs.DiskOffering.GetDiskOfferingID(value) id, err = cs.DiskOffering.GetDiskOfferingID(value)
case "virtual_machine": case "virtual_machine":
uuid, err = cs.VirtualMachine.GetVirtualMachineID(value) id, err = cs.VirtualMachine.GetVirtualMachineID(value)
case "service_offering": case "service_offering":
uuid, err = cs.ServiceOffering.GetServiceOfferingID(value) id, err = cs.ServiceOffering.GetServiceOfferingID(value)
case "network_offering": case "network_offering":
uuid, err = cs.NetworkOffering.GetNetworkOfferingID(value) id, err = cs.NetworkOffering.GetNetworkOfferingID(value)
case "project":
id, err = cs.Project.GetProjectID(value)
case "vpc_offering": case "vpc_offering":
uuid, err = cs.VPC.GetVPCOfferingID(value) id, err = cs.VPC.GetVPCOfferingID(value)
case "vpc": case "vpc":
uuid, err = cs.VPC.GetVPCID(value) id, err = cs.VPC.GetVPCID(value)
case "network": case "network":
uuid, err = cs.Network.GetNetworkID(value) id, err = cs.Network.GetNetworkID(value)
case "zone": case "zone":
if value == UnlimitedResourceID { id, err = cs.Zone.GetZoneID(value)
return value, nil
}
uuid, err = cs.Zone.GetZoneID(value)
case "ipaddress": case "ipaddress":
p := cs.Address.NewListPublicIpAddressesParams() p := cs.Address.NewListPublicIpAddressesParams()
p.SetIpaddress(value) p.SetIpaddress(value)
@ -69,10 +74,10 @@ func retrieveUUID(cs *cloudstack.CloudStackClient, name, value string) (uuid str
break break
} }
if l.Count == 1 { if l.Count == 1 {
uuid = l.PublicIpAddresses[0].Id id = l.PublicIpAddresses[0].Id
break break
} }
err = fmt.Errorf("Could not find UUID of IP address: %s", value) err = fmt.Errorf("Could not find ID of IP address: %s", value)
case "os_type": case "os_type":
p := cs.GuestOS.NewListOsTypesParams() p := cs.GuestOS.NewListOsTypesParams()
p.SetDescription(value) p.SetDescription(value)
@ -82,43 +87,42 @@ func retrieveUUID(cs *cloudstack.CloudStackClient, name, value string) (uuid str
break break
} }
if l.Count == 1 { if l.Count == 1 {
uuid = l.OsTypes[0].Id id = l.OsTypes[0].Id
break break
} }
err = fmt.Errorf("Could not find UUID of OS Type: %s", value) err = fmt.Errorf("Could not find ID of OS Type: %s", value)
case "project":
uuid, err = cs.Project.GetProjectID(value)
default: default:
return uuid, &retrieveError{name: name, value: value, return id, &retrieveError{name: name, value: value,
err: fmt.Errorf("Unknown request: %s", name)} err: fmt.Errorf("Unknown request: %s", name)}
} }
if err != nil { if err != nil {
return uuid, &retrieveError{name: name, value: value, err: err} return id, &retrieveError{name: name, value: value, err: err}
} }
return uuid, nil return id, nil
} }
func retrieveTemplateUUID(cs *cloudstack.CloudStackClient, zoneid, value string) (uuid string, e *retrieveError) { func retrieveTemplateID(cs *cloudstack.CloudStackClient, zoneid, value string) (id string, e *retrieveError) {
// If the supplied value isn't a UUID, try to retrieve the UUID ourselves // If the supplied value isn't a ID, try to retrieve the ID ourselves
if isUUID(value) { if isID(value) {
return value, nil return value, nil
} }
log.Printf("[DEBUG] Retrieving UUID of template: %s", value) log.Printf("[DEBUG] Retrieving ID of template: %s", value)
uuid, err := cs.Template.GetTemplateID(value, "executable", zoneid) id, err := cs.Template.GetTemplateID(value, "executable", zoneid)
if err != nil { if err != nil {
return uuid, &retrieveError{name: "template", value: value, err: err} return id, &retrieveError{name: "template", value: value, err: err}
} }
return uuid, nil return id, nil
} }
func isUUID(s string) bool { // ID can be either a UUID or a UnlimitedResourceID
re := regexp.MustCompile(`^[0-9a-f]{8}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{12}$`) func isID(id string) bool {
return re.MatchString(s) re := regexp.MustCompile(`^[0-9a-f]{8}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{12}|-1$`)
return re.MatchString(id)
} }
// RetryFunc is the function retried n times // RetryFunc is the function retried n times