Small refactor of the UUID/UnlimitedResourceID logic
This makes things a little more generic and robust.
This commit is contained in:
parent
6fb61e3d98
commit
350b8e2df2
|
@ -32,18 +32,18 @@ func testSetValueOnResourceData(t *testing.T) {
|
|||
d := schema.ResourceData{}
|
||||
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" {
|
||||
t.Fatal("err: 'id' does not match 'name'")
|
||||
}
|
||||
}
|
||||
|
||||
func testSetUUIDOnResourceData(t *testing.T) {
|
||||
func testSetIDOnResourceData(t *testing.T) {
|
||||
d := schema.ResourceData{}
|
||||
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" {
|
||||
t.Fatal("err: 'id' doest not match '54711781-274e-41b2-83c0-17194d0108f7'")
|
||||
|
|
|
@ -80,12 +80,12 @@ func resourceCloudStackDiskCreate(d *schema.ResourceData, meta interface{}) erro
|
|||
// Create a new parameter struct
|
||||
p := cs.Volume.NewCreateVolumeParams(name)
|
||||
|
||||
// Retrieve the disk_offering UUID
|
||||
diskofferingid, e := retrieveUUID(cs, "disk_offering", d.Get("disk_offering").(string))
|
||||
// Retrieve the disk_offering ID
|
||||
diskofferingid, e := retrieveID(cs, "disk_offering", d.Get("disk_offering").(string))
|
||||
if e != nil {
|
||||
return e.Error()
|
||||
}
|
||||
// Set the disk_offering UUID
|
||||
// Set the disk_offering ID
|
||||
p.SetDiskofferingid(diskofferingid)
|
||||
|
||||
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 project, ok := d.GetOk("project"); ok {
|
||||
// Retrieve the project UUID
|
||||
projectid, e := retrieveUUID(cs, "project", project.(string))
|
||||
// Retrieve the project ID
|
||||
projectid, e := retrieveID(cs, "project", project.(string))
|
||||
if e != nil {
|
||||
return e.Error()
|
||||
}
|
||||
|
@ -104,8 +104,8 @@ func resourceCloudStackDiskCreate(d *schema.ResourceData, meta interface{}) erro
|
|||
p.SetProjectid(projectid)
|
||||
}
|
||||
|
||||
// Retrieve the zone UUID
|
||||
zoneid, e := retrieveUUID(cs, "zone", d.Get("zone").(string))
|
||||
// Retrieve the zone ID
|
||||
zoneid, e := retrieveID(cs, "zone", d.Get("zone").(string))
|
||||
if e != nil {
|
||||
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)
|
||||
}
|
||||
|
||||
// Set the volume UUID and partials
|
||||
// Set the volume ID and partials
|
||||
d.SetId(r.Id)
|
||||
d.SetPartial("name")
|
||||
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("size", int(v.Size/(1024*1024*1024))) // Needed to get GB's again
|
||||
|
||||
setValueOrUUID(d, "disk_offering", v.Diskofferingname, v.Diskofferingid)
|
||||
setValueOrUUID(d, "project", v.Project, v.Projectid)
|
||||
setValueOrUUID(d, "zone", v.Zonename, v.Zoneid)
|
||||
setValueOrID(d, "disk_offering", v.Diskofferingname, v.Diskofferingid)
|
||||
setValueOrID(d, "project", v.Project, v.Projectid)
|
||||
setValueOrID(d, "zone", v.Zonename, v.Zoneid)
|
||||
|
||||
if v.Attached != "" {
|
||||
// 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))
|
||||
setValueOrUUID(d, "virtual_machine", v.Vmname, v.Virtualmachineid)
|
||||
setValueOrID(d, "virtual_machine", v.Vmname, v.Virtualmachineid)
|
||||
}
|
||||
|
||||
return nil
|
||||
|
@ -205,13 +205,13 @@ func resourceCloudStackDiskUpdate(d *schema.ResourceData, meta interface{}) erro
|
|||
// Create a new parameter struct
|
||||
p := cs.Volume.NewResizeVolumeParams(d.Id())
|
||||
|
||||
// Retrieve the disk_offering UUID
|
||||
diskofferingid, e := retrieveUUID(cs, "disk_offering", d.Get("disk_offering").(string))
|
||||
// Retrieve the disk_offering ID
|
||||
diskofferingid, e := retrieveID(cs, "disk_offering", d.Get("disk_offering").(string))
|
||||
if e != nil {
|
||||
return e.Error()
|
||||
}
|
||||
|
||||
// Set the disk_offering UUID
|
||||
// Set the disk_offering ID
|
||||
p.SetDiskofferingid(diskofferingid)
|
||||
|
||||
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)
|
||||
}
|
||||
|
||||
// Update the volume UUID and set partials
|
||||
// Update the volume ID and set partials
|
||||
d.SetId(r.Id)
|
||||
d.SetPartial("disk_offering")
|
||||
d.SetPartial("size")
|
||||
|
@ -278,7 +278,7 @@ func resourceCloudStackDiskDelete(d *schema.ResourceData, meta interface{}) erro
|
|||
|
||||
// Delete the voluem
|
||||
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(
|
||||
"Invalid parameter id value=%s due to incorrect long value format, "+
|
||||
"or entity does not exist", d.Id())) {
|
||||
|
@ -299,8 +299,8 @@ func resourceCloudStackDiskAttach(d *schema.ResourceData, meta interface{}) erro
|
|||
return err
|
||||
}
|
||||
|
||||
// Retrieve the virtual_machine UUID
|
||||
virtualmachineid, e := retrieveUUID(cs, "virtual_machine", d.Get("virtual_machine").(string))
|
||||
// Retrieve the virtual_machine ID
|
||||
virtualmachineid, e := retrieveID(cs, "virtual_machine", d.Get("virtual_machine").(string))
|
||||
if e != nil {
|
||||
return e.Error()
|
||||
}
|
||||
|
@ -341,13 +341,13 @@ func resourceCloudStackDiskDetach(d *schema.ResourceData, meta interface{}) erro
|
|||
// Create a new parameter struct
|
||||
p := cs.Volume.NewDetachVolumeParams()
|
||||
|
||||
// Set the volume UUID
|
||||
// Set the volume ID
|
||||
p.SetId(d.Id())
|
||||
|
||||
// Detach the currently attached volume
|
||||
if _, err := cs.Volume.DetachVolume(p); err != nil {
|
||||
// Retrieve the virtual_machine UUID
|
||||
virtualmachineid, e := retrieveUUID(cs, "virtual_machine", d.Get("virtual_machine").(string))
|
||||
// Retrieve the virtual_machine ID
|
||||
virtualmachineid, e := retrieveID(cs, "virtual_machine", d.Get("virtual_machine").(string))
|
||||
if e != nil {
|
||||
return e.Error()
|
||||
}
|
||||
|
|
|
@ -89,8 +89,8 @@ func resourceCloudStackEgressFirewallCreate(d *schema.ResourceData, meta interfa
|
|||
return err
|
||||
}
|
||||
|
||||
// Retrieve the network UUID
|
||||
networkid, e := retrieveUUID(cs, "network", d.Get("network").(string))
|
||||
// Retrieve the network ID
|
||||
networkid, e := retrieveID(cs, "network", d.Get("network").(string))
|
||||
if e != nil {
|
||||
return e.Error()
|
||||
}
|
||||
|
@ -222,7 +222,7 @@ func resourceCloudStackEgressFirewallRead(d *schema.ResourceData, meta interface
|
|||
|
||||
// Get the rule
|
||||
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 count == 0 {
|
||||
delete(uuids, "icmp")
|
||||
|
@ -415,7 +415,7 @@ func resourceCloudStackEgressFirewallDeleteRule(
|
|||
// Delete the rule
|
||||
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(
|
||||
"Invalid parameter id value=%s due to incorrect long value format, "+
|
||||
"or entity does not exist", id.(string))) {
|
||||
|
|
|
@ -123,13 +123,13 @@ func testAccCheckCloudStackEgressFirewallRulesExist(n string) resource.TestCheck
|
|||
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.#") {
|
||||
continue
|
||||
}
|
||||
|
||||
cs := testAccProvider.Meta().(*cloudstack.CloudStackClient)
|
||||
_, count, err := cs.Firewall.GetEgressFirewallRuleByID(uuid)
|
||||
_, count, err := cs.Firewall.GetEgressFirewallRuleByID(id)
|
||||
|
||||
if err != nil {
|
||||
return err
|
||||
|
@ -156,12 +156,12 @@ func testAccCheckCloudStackEgressFirewallDestroy(s *terraform.State) error {
|
|||
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.#") {
|
||||
continue
|
||||
}
|
||||
|
||||
_, _, err := cs.Firewall.GetEgressFirewallRuleByID(uuid)
|
||||
_, _, err := cs.Firewall.GetEgressFirewallRuleByID(id)
|
||||
if err == nil {
|
||||
return fmt.Errorf("Egress rule %s still exists", rs.Primary.ID)
|
||||
}
|
||||
|
|
|
@ -89,8 +89,8 @@ func resourceCloudStackFirewallCreate(d *schema.ResourceData, meta interface{})
|
|||
return err
|
||||
}
|
||||
|
||||
// Retrieve the ipaddress UUID
|
||||
ipaddressid, e := retrieveUUID(cs, "ipaddress", d.Get("ipaddress").(string))
|
||||
// Retrieve the ipaddress ID
|
||||
ipaddressid, e := retrieveID(cs, "ipaddress", d.Get("ipaddress").(string))
|
||||
if e != nil {
|
||||
return e.Error()
|
||||
}
|
||||
|
@ -222,7 +222,7 @@ func resourceCloudStackFirewallRead(d *schema.ResourceData, meta interface{}) er
|
|||
|
||||
// Get the rule
|
||||
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 count == 0 {
|
||||
delete(uuids, "icmp")
|
||||
|
@ -415,7 +415,7 @@ func resourceCloudStackFirewallDeleteRule(
|
|||
// Delete the rule
|
||||
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(
|
||||
"Invalid parameter id value=%s due to incorrect long value format, "+
|
||||
"or entity does not exist", id.(string))) {
|
||||
|
|
|
@ -110,13 +110,13 @@ func testAccCheckCloudStackFirewallRulesExist(n string) resource.TestCheckFunc {
|
|||
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.#") {
|
||||
continue
|
||||
}
|
||||
|
||||
cs := testAccProvider.Meta().(*cloudstack.CloudStackClient)
|
||||
_, count, err := cs.Firewall.GetFirewallRuleByID(uuid)
|
||||
_, count, err := cs.Firewall.GetFirewallRuleByID(id)
|
||||
|
||||
if err != nil {
|
||||
return err
|
||||
|
@ -143,12 +143,12 @@ func testAccCheckCloudStackFirewallDestroy(s *terraform.State) error {
|
|||
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.#") {
|
||||
continue
|
||||
}
|
||||
|
||||
_, _, err := cs.Firewall.GetFirewallRuleByID(uuid)
|
||||
_, _, err := cs.Firewall.GetFirewallRuleByID(id)
|
||||
if err == nil {
|
||||
return fmt.Errorf("Firewall rule %s still exists", rs.Primary.ID)
|
||||
}
|
||||
|
|
|
@ -100,14 +100,14 @@ func resourceCloudStackInstance() *schema.Resource {
|
|||
func resourceCloudStackInstanceCreate(d *schema.ResourceData, meta interface{}) error {
|
||||
cs := meta.(*cloudstack.CloudStackClient)
|
||||
|
||||
// Retrieve the service_offering UUID
|
||||
serviceofferingid, e := retrieveUUID(cs, "service_offering", d.Get("service_offering").(string))
|
||||
// Retrieve the service_offering ID
|
||||
serviceofferingid, e := retrieveID(cs, "service_offering", d.Get("service_offering").(string))
|
||||
if e != nil {
|
||||
return e.Error()
|
||||
}
|
||||
|
||||
// Retrieve the zone UUID
|
||||
zoneid, e := retrieveUUID(cs, "zone", d.Get("zone").(string))
|
||||
// Retrieve the zone ID
|
||||
zoneid, e := retrieveID(cs, "zone", d.Get("zone").(string))
|
||||
if e != nil {
|
||||
return e.Error()
|
||||
}
|
||||
|
@ -118,8 +118,8 @@ func resourceCloudStackInstanceCreate(d *schema.ResourceData, meta interface{})
|
|||
return err
|
||||
}
|
||||
|
||||
// Retrieve the template UUID
|
||||
templateid, e := retrieveTemplateUUID(cs, zone.Id, d.Get("template").(string))
|
||||
// Retrieve the template ID
|
||||
templateid, e := retrieveTemplateID(cs, zone.Id, d.Get("template").(string))
|
||||
if e != nil {
|
||||
return e.Error()
|
||||
}
|
||||
|
@ -139,8 +139,8 @@ func resourceCloudStackInstanceCreate(d *schema.ResourceData, meta interface{})
|
|||
}
|
||||
|
||||
if zone.Networktype == "Advanced" {
|
||||
// Retrieve the network UUID
|
||||
networkid, e := retrieveUUID(cs, "network", d.Get("network").(string))
|
||||
// Retrieve the network ID
|
||||
networkid, e := retrieveID(cs, "network", d.Get("network").(string))
|
||||
if e != nil {
|
||||
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 project, ok := d.GetOk("project"); ok {
|
||||
// Retrieve the project UUID
|
||||
projectid, e := retrieveUUID(cs, "project", project.(string))
|
||||
// Retrieve the project ID
|
||||
projectid, e := retrieveID(cs, "project", project.(string))
|
||||
if e != nil {
|
||||
return e.Error()
|
||||
}
|
||||
|
@ -229,11 +229,11 @@ func resourceCloudStackInstanceRead(d *schema.ResourceData, meta interface{}) er
|
|||
d.Set("ipaddress", vm.Nic[0].Ipaddress)
|
||||
//NB cloudstack sometimes sends back the wrong keypair name, so dont update it
|
||||
|
||||
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)
|
||||
setValueOrUUID(d, "zone", vm.Zonename, vm.Zoneid)
|
||||
setValueOrID(d, "network", vm.Nic[0].Networkname, vm.Nic[0].Networkid)
|
||||
setValueOrID(d, "service_offering", vm.Serviceofferingname, vm.Serviceofferingid)
|
||||
setValueOrID(d, "template", vm.Templatename, vm.Templateid)
|
||||
setValueOrID(d, "project", vm.Project, vm.Projectid)
|
||||
setValueOrID(d, "zone", vm.Zonename, vm.Zoneid)
|
||||
|
||||
return nil
|
||||
}
|
||||
|
@ -278,8 +278,8 @@ func resourceCloudStackInstanceUpdate(d *schema.ResourceData, meta interface{})
|
|||
if d.HasChange("service_offering") {
|
||||
log.Printf("[DEBUG] Service offering changed for %s, starting update", name)
|
||||
|
||||
// Retrieve the service_offering UUID
|
||||
serviceofferingid, e := retrieveUUID(cs, "service_offering", d.Get("service_offering").(string))
|
||||
// Retrieve the service_offering ID
|
||||
serviceofferingid, e := retrieveID(cs, "service_offering", d.Get("service_offering").(string))
|
||||
if e != nil {
|
||||
return e.Error()
|
||||
}
|
||||
|
@ -335,7 +335,7 @@ func resourceCloudStackInstanceDelete(d *schema.ResourceData, meta interface{})
|
|||
|
||||
log.Printf("[INFO] Destroying instance: %s", d.Get("name").(string))
|
||||
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(
|
||||
"Invalid parameter id value=%s due to incorrect long value format, "+
|
||||
"or entity does not exist", d.Id())) {
|
||||
|
|
|
@ -53,8 +53,8 @@ func resourceCloudStackIPAddressCreate(d *schema.ResourceData, meta interface{})
|
|||
p := cs.Address.NewAssociateIpAddressParams()
|
||||
|
||||
if network, ok := d.GetOk("network"); ok {
|
||||
// Retrieve the network UUID
|
||||
networkid, e := retrieveUUID(cs, "network", network.(string))
|
||||
// Retrieve the network ID
|
||||
networkid, e := retrieveID(cs, "network", network.(string))
|
||||
if e != nil {
|
||||
return e.Error()
|
||||
}
|
||||
|
@ -64,8 +64,8 @@ func resourceCloudStackIPAddressCreate(d *schema.ResourceData, meta interface{})
|
|||
}
|
||||
|
||||
if vpc, ok := d.GetOk("vpc"); ok {
|
||||
// Retrieve the vpc UUID
|
||||
vpcid, e := retrieveUUID(cs, "vpc", vpc.(string))
|
||||
// Retrieve the vpc ID
|
||||
vpcid, e := retrieveID(cs, "vpc", vpc.(string))
|
||||
if e != nil {
|
||||
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 project, ok := d.GetOk("project"); ok {
|
||||
// Retrieve the project UUID
|
||||
projectid, e := retrieveUUID(cs, "project", project.(string))
|
||||
// Retrieve the project ID
|
||||
projectid, e := retrieveID(cs, "project", project.(string))
|
||||
if e != nil {
|
||||
return e.Error()
|
||||
}
|
||||
|
@ -122,7 +122,7 @@ func resourceCloudStackIPAddressRead(d *schema.ResourceData, meta interface{}) e
|
|||
return err
|
||||
}
|
||||
|
||||
setValueOrUUID(d, "network", n.Name, f.Associatednetworkid)
|
||||
setValueOrID(d, "network", n.Name, f.Associatednetworkid)
|
||||
}
|
||||
|
||||
if _, ok := d.GetOk("vpc"); ok {
|
||||
|
@ -132,10 +132,10 @@ func resourceCloudStackIPAddressRead(d *schema.ResourceData, meta interface{}) e
|
|||
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
|
||||
}
|
||||
|
@ -148,7 +148,7 @@ func resourceCloudStackIPAddressDelete(d *schema.ResourceData, meta interface{})
|
|||
|
||||
// Disassociate the IP address
|
||||
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(
|
||||
"Invalid parameter id value=%s due to incorrect long value format, "+
|
||||
"or entity does not exist", d.Id())) {
|
||||
|
|
|
@ -89,9 +89,9 @@ func resourceCloudStackLoadBalancerRuleCreate(d *schema.ResourceData, meta inter
|
|||
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 {
|
||||
networkid, e := retrieveUUID(cs, "network", network.(string))
|
||||
networkid, e := retrieveID(cs, "network", network.(string))
|
||||
if e != nil {
|
||||
return e.Error()
|
||||
}
|
||||
|
@ -100,8 +100,8 @@ func resourceCloudStackLoadBalancerRuleCreate(d *schema.ResourceData, meta inter
|
|||
p.SetNetworkid(networkid)
|
||||
}
|
||||
|
||||
// Retrieve the ipaddress UUID
|
||||
ipaddressid, e := retrieveUUID(cs, "ipaddress", d.Get("ipaddress").(string))
|
||||
// Retrieve the ipaddress ID
|
||||
ipaddressid, e := retrieveID(cs, "ipaddress", d.Get("ipaddress").(string))
|
||||
if e != nil {
|
||||
return e.Error()
|
||||
}
|
||||
|
@ -113,7 +113,7 @@ func resourceCloudStackLoadBalancerRuleCreate(d *schema.ResourceData, meta inter
|
|||
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.SetPartial("name")
|
||||
d.SetPartial("description")
|
||||
|
@ -163,7 +163,7 @@ func resourceCloudStackLoadBalancerRuleRead(d *schema.ResourceData, meta interfa
|
|||
d.Set("public_port", lb.Publicport)
|
||||
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
|
||||
if _, ok := d.GetOk("network"); ok {
|
||||
|
@ -171,7 +171,7 @@ func resourceCloudStackLoadBalancerRuleRead(d *schema.ResourceData, meta interfa
|
|||
if err != nil {
|
||||
return err
|
||||
}
|
||||
setValueOrUUID(d, "network", network.Name, lb.Networkid)
|
||||
setValueOrID(d, "network", network.Name, lb.Networkid)
|
||||
}
|
||||
|
||||
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))
|
||||
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(
|
||||
"Invalid parameter id value=%s due to incorrect long value format, "+
|
||||
"or entity does not exist", d.Id())) {
|
||||
|
|
|
@ -223,12 +223,12 @@ func testAccCheckCloudStackLoadBalancerRuleDestroy(s *terraform.State) error {
|
|||
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") {
|
||||
continue
|
||||
}
|
||||
|
||||
_, _, err := cs.LoadBalancer.GetLoadBalancerRuleByID(uuid)
|
||||
_, _, err := cs.LoadBalancer.GetLoadBalancerRuleByID(id)
|
||||
if err == nil {
|
||||
return fmt.Errorf("Loadbalancer rule %s still exists", rs.Primary.ID)
|
||||
}
|
||||
|
|
|
@ -72,14 +72,14 @@ func resourceCloudStackNetworkCreate(d *schema.ResourceData, meta interface{}) e
|
|||
|
||||
name := d.Get("name").(string)
|
||||
|
||||
// Retrieve the network_offering UUID
|
||||
networkofferingid, e := retrieveUUID(cs, "network_offering", d.Get("network_offering").(string))
|
||||
// Retrieve the network_offering ID
|
||||
networkofferingid, e := retrieveID(cs, "network_offering", d.Get("network_offering").(string))
|
||||
if e != nil {
|
||||
return e.Error()
|
||||
}
|
||||
|
||||
// Retrieve the zone UUID
|
||||
zoneid, e := retrieveUUID(cs, "zone", d.Get("zone").(string))
|
||||
// Retrieve the zone ID
|
||||
zoneid, e := retrieveID(cs, "zone", d.Get("zone").(string))
|
||||
if e != nil {
|
||||
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
|
||||
vpc := d.Get("vpc").(string)
|
||||
if vpc != "" {
|
||||
// Retrieve the vpc UUID
|
||||
vpcid, e := retrieveUUID(cs, "vpc", vpc)
|
||||
// Retrieve the vpc ID
|
||||
vpcid, e := retrieveID(cs, "vpc", vpc)
|
||||
if e != nil {
|
||||
return e.Error()
|
||||
}
|
||||
|
||||
// Set the vpc UUID
|
||||
// Set the vpc ID
|
||||
p.SetVpcid(vpcid)
|
||||
|
||||
// Since we're in a VPC, check if we want to assiciate an ACL list
|
||||
aclid := d.Get("aclid").(string)
|
||||
if aclid != "" {
|
||||
// Set the acl UUID
|
||||
// Set the acl ID
|
||||
p.SetAclid(aclid)
|
||||
}
|
||||
}
|
||||
|
||||
// If there is a project supplied, we retrieve and set the project id
|
||||
if project, ok := d.GetOk("project"); ok {
|
||||
// Retrieve the project UUID
|
||||
projectid, e := retrieveUUID(cs, "project", project.(string))
|
||||
// Retrieve the project ID
|
||||
projectid, e := retrieveID(cs, "project", project.(string))
|
||||
if e != nil {
|
||||
return e.Error()
|
||||
}
|
||||
|
@ -167,9 +167,9 @@ func resourceCloudStackNetworkRead(d *schema.ResourceData, meta interface{}) err
|
|||
d.Set("display_text", n.Displaytext)
|
||||
d.Set("cidr", n.Cidr)
|
||||
|
||||
setValueOrUUID(d, "network_offering", n.Networkofferingname, n.Networkofferingid)
|
||||
setValueOrUUID(d, "project", n.Project, n.Projectid)
|
||||
setValueOrUUID(d, "zone", n.Zonename, n.Zoneid)
|
||||
setValueOrID(d, "network_offering", n.Networkofferingname, n.Networkofferingid)
|
||||
setValueOrID(d, "project", n.Project, n.Projectid)
|
||||
setValueOrID(d, "zone", n.Zonename, n.Zoneid)
|
||||
|
||||
return nil
|
||||
}
|
||||
|
@ -200,8 +200,8 @@ func resourceCloudStackNetworkUpdate(d *schema.ResourceData, meta interface{}) e
|
|||
|
||||
// Check if the network offering is changed
|
||||
if d.HasChange("network_offering") {
|
||||
// Retrieve the network_offering UUID
|
||||
networkofferingid, e := retrieveUUID(cs, "network_offering", d.Get("network_offering").(string))
|
||||
// Retrieve the network_offering ID
|
||||
networkofferingid, e := retrieveID(cs, "network_offering", d.Get("network_offering").(string))
|
||||
if e != nil {
|
||||
return e.Error()
|
||||
}
|
||||
|
@ -228,7 +228,7 @@ func resourceCloudStackNetworkDelete(d *schema.ResourceData, meta interface{}) e
|
|||
// Delete the network
|
||||
_, err := cs.Network.DeleteNetwork(p)
|
||||
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(
|
||||
"Invalid parameter id value=%s due to incorrect long value format, "+
|
||||
"or entity does not exist", d.Id())) {
|
||||
|
|
|
@ -43,8 +43,8 @@ func resourceCloudStackNetworkACLCreate(d *schema.ResourceData, meta interface{}
|
|||
|
||||
name := d.Get("name").(string)
|
||||
|
||||
// Retrieve the vpc UUID
|
||||
vpcid, e := retrieveUUID(cs, "vpc", d.Get("vpc").(string))
|
||||
// Retrieve the vpc ID
|
||||
vpcid, e := retrieveID(cs, "vpc", d.Get("vpc").(string))
|
||||
if e != nil {
|
||||
return e.Error()
|
||||
}
|
||||
|
@ -95,7 +95,7 @@ func resourceCloudStackNetworkACLRead(d *schema.ResourceData, meta interface{})
|
|||
return err
|
||||
}
|
||||
|
||||
setValueOrUUID(d, "vpc", v.Name, v.Id)
|
||||
setValueOrID(d, "vpc", v.Name, v.Id)
|
||||
|
||||
return nil
|
||||
}
|
||||
|
@ -109,7 +109,7 @@ func resourceCloudStackNetworkACLDelete(d *schema.ResourceData, meta interface{}
|
|||
// Delete the network ACL list
|
||||
_, err := cs.NetworkACL.DeleteNetworkACLList(p)
|
||||
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(
|
||||
"Invalid parameter id value=%s due to incorrect long value format, "+
|
||||
"or entity does not exist", d.Id())) {
|
||||
|
|
|
@ -247,7 +247,7 @@ func resourceCloudStackNetworkACLRuleRead(d *schema.ResourceData, meta interface
|
|||
|
||||
// Get the rule
|
||||
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 count == 0 {
|
||||
delete(uuids, "icmp")
|
||||
|
@ -275,7 +275,7 @@ func resourceCloudStackNetworkACLRuleRead(d *schema.ResourceData, meta interface
|
|||
|
||||
// Get the rule
|
||||
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 count == 0 {
|
||||
delete(uuids, "all")
|
||||
|
@ -469,7 +469,7 @@ func resourceCloudStackNetworkACLRuleDeleteRule(
|
|||
// Delete the rule
|
||||
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(
|
||||
"Invalid parameter id value=%s due to incorrect long value format, "+
|
||||
"or entity does not exist", id.(string))) {
|
||||
|
|
|
@ -122,13 +122,13 @@ func testAccCheckCloudStackNetworkACLRulesExist(n string) resource.TestCheckFunc
|
|||
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.#") {
|
||||
continue
|
||||
}
|
||||
|
||||
cs := testAccProvider.Meta().(*cloudstack.CloudStackClient)
|
||||
_, count, err := cs.NetworkACL.GetNetworkACLByID(uuid)
|
||||
_, count, err := cs.NetworkACL.GetNetworkACLByID(id)
|
||||
|
||||
if err != nil {
|
||||
return err
|
||||
|
@ -155,12 +155,12 @@ func testAccCheckCloudStackNetworkACLRuleDestroy(s *terraform.State) error {
|
|||
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.#") {
|
||||
continue
|
||||
}
|
||||
|
||||
_, _, err := cs.NetworkACL.GetNetworkACLByID(uuid)
|
||||
_, _, err := cs.NetworkACL.GetNetworkACLByID(id)
|
||||
if err == nil {
|
||||
return fmt.Errorf("Network ACL rule %s still exists", rs.Primary.ID)
|
||||
}
|
||||
|
|
|
@ -41,14 +41,14 @@ func resourceCloudStackNIC() *schema.Resource {
|
|||
func resourceCloudStackNICCreate(d *schema.ResourceData, meta interface{}) error {
|
||||
cs := meta.(*cloudstack.CloudStackClient)
|
||||
|
||||
// Retrieve the network UUID
|
||||
networkid, e := retrieveUUID(cs, "network", d.Get("network").(string))
|
||||
// Retrieve the network ID
|
||||
networkid, e := retrieveID(cs, "network", d.Get("network").(string))
|
||||
if e != nil {
|
||||
return e.Error()
|
||||
}
|
||||
|
||||
// Retrieve the virtual_machine UUID
|
||||
virtualmachineid, e := retrieveUUID(cs, "virtual_machine", d.Get("virtual_machine").(string))
|
||||
// Retrieve the virtual_machine ID
|
||||
virtualmachineid, e := retrieveID(cs, "virtual_machine", d.Get("virtual_machine").(string))
|
||||
if e != nil {
|
||||
return e.Error()
|
||||
}
|
||||
|
@ -103,8 +103,8 @@ func resourceCloudStackNICRead(d *schema.ResourceData, meta interface{}) error {
|
|||
for _, n := range vm.Nic {
|
||||
if n.Id == d.Id() {
|
||||
d.Set("ipaddress", n.Ipaddress)
|
||||
setValueOrUUID(d, "network", n.Networkname, n.Networkid)
|
||||
setValueOrUUID(d, "virtual_machine", vm.Name, vm.Id)
|
||||
setValueOrID(d, "network", n.Networkname, n.Networkid)
|
||||
setValueOrID(d, "virtual_machine", vm.Name, vm.Id)
|
||||
found = true
|
||||
break
|
||||
}
|
||||
|
@ -121,8 +121,8 @@ func resourceCloudStackNICRead(d *schema.ResourceData, meta interface{}) error {
|
|||
func resourceCloudStackNICDelete(d *schema.ResourceData, meta interface{}) error {
|
||||
cs := meta.(*cloudstack.CloudStackClient)
|
||||
|
||||
// Retrieve the virtual_machine UUID
|
||||
virtualmachineid, e := retrieveUUID(cs, "virtual_machine", d.Get("virtual_machine").(string))
|
||||
// Retrieve the virtual_machine ID
|
||||
virtualmachineid, e := retrieveID(cs, "virtual_machine", d.Get("virtual_machine").(string))
|
||||
if e != nil {
|
||||
return e.Error()
|
||||
}
|
||||
|
@ -133,7 +133,7 @@ func resourceCloudStackNICDelete(d *schema.ResourceData, meta interface{}) error
|
|||
// Remove the NIC
|
||||
_, err := cs.VirtualMachine.RemoveNicFromVirtualMachine(p)
|
||||
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(
|
||||
"Invalid parameter id value=%s due to incorrect long value format, "+
|
||||
"or entity does not exist", d.Id())) {
|
||||
|
|
|
@ -72,8 +72,8 @@ func resourceCloudStackPortForward() *schema.Resource {
|
|||
func resourceCloudStackPortForwardCreate(d *schema.ResourceData, meta interface{}) error {
|
||||
cs := meta.(*cloudstack.CloudStackClient)
|
||||
|
||||
// Retrieve the ipaddress UUID
|
||||
ipaddressid, e := retrieveUUID(cs, "ipaddress", d.Get("ipaddress").(string))
|
||||
// Retrieve the ipaddress ID
|
||||
ipaddressid, e := retrieveID(cs, "ipaddress", d.Get("ipaddress").(string))
|
||||
if e != nil {
|
||||
return e.Error()
|
||||
}
|
||||
|
@ -115,8 +115,8 @@ func resourceCloudStackPortForwardCreateForward(
|
|||
return err
|
||||
}
|
||||
|
||||
// Retrieve the virtual_machine UUID
|
||||
virtualmachineid, e := retrieveUUID(cs, "virtual_machine", forward["virtual_machine"].(string))
|
||||
// Retrieve the virtual_machine ID
|
||||
virtualmachineid, e := retrieveID(cs, "virtual_machine", forward["virtual_machine"].(string))
|
||||
if e != nil {
|
||||
return e.Error()
|
||||
}
|
||||
|
@ -167,7 +167,7 @@ func resourceCloudStackPortForwardRead(d *schema.ResourceData, meta interface{})
|
|||
|
||||
// Get the forward
|
||||
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 count == 0 {
|
||||
forward["uuid"] = ""
|
||||
|
@ -192,7 +192,7 @@ func resourceCloudStackPortForwardRead(d *schema.ResourceData, meta interface{})
|
|||
forward["private_port"] = privPort
|
||||
forward["public_port"] = pubPort
|
||||
|
||||
if isUUID(forward["virtual_machine"].(string)) {
|
||||
if isID(forward["virtual_machine"].(string)) {
|
||||
forward["virtual_machine"] = r.Virtualmachineid
|
||||
} else {
|
||||
forward["virtual_machine"] = r.Virtualmachinename
|
||||
|
@ -317,7 +317,7 @@ func resourceCloudStackPortForwardDeleteForward(
|
|||
|
||||
// Delete the forward
|
||||
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(
|
||||
"Invalid parameter id value=%s due to incorrect long value format, "+
|
||||
"or entity does not exist", forward["uuid"].(string))) {
|
||||
|
@ -325,6 +325,7 @@ func resourceCloudStackPortForwardDeleteForward(
|
|||
}
|
||||
}
|
||||
|
||||
// Empty the UUID of this rule
|
||||
forward["uuid"] = ""
|
||||
|
||||
return nil
|
||||
|
|
|
@ -102,13 +102,13 @@ func testAccCheckCloudStackPortForwardsExist(n string) resource.TestCheckFunc {
|
|||
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") {
|
||||
continue
|
||||
}
|
||||
|
||||
cs := testAccProvider.Meta().(*cloudstack.CloudStackClient)
|
||||
_, count, err := cs.Firewall.GetPortForwardingRuleByID(uuid)
|
||||
_, count, err := cs.Firewall.GetPortForwardingRuleByID(id)
|
||||
|
||||
if err != nil {
|
||||
return err
|
||||
|
@ -135,12 +135,12 @@ func testAccCheckCloudStackPortForwardDestroy(s *terraform.State) error {
|
|||
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") {
|
||||
continue
|
||||
}
|
||||
|
||||
_, _, err := cs.Firewall.GetPortForwardingRuleByID(uuid)
|
||||
_, _, err := cs.Firewall.GetPortForwardingRuleByID(id)
|
||||
if err == nil {
|
||||
return fmt.Errorf("Port forward %s still exists", rs.Primary.ID)
|
||||
}
|
||||
|
|
|
@ -44,8 +44,8 @@ func resourceCloudStackSecondaryIPAddressCreate(d *schema.ResourceData, meta int
|
|||
|
||||
nicid := d.Get("nicid").(string)
|
||||
if nicid == "" {
|
||||
// Retrieve the virtual_machine UUID
|
||||
virtualmachineid, e := retrieveUUID(cs, "virtual_machine", d.Get("virtual_machine").(string))
|
||||
// Retrieve the virtual_machine ID
|
||||
virtualmachineid, e := retrieveID(cs, "virtual_machine", d.Get("virtual_machine").(string))
|
||||
if e != nil {
|
||||
return e.Error()
|
||||
}
|
||||
|
@ -84,8 +84,8 @@ func resourceCloudStackSecondaryIPAddressCreate(d *schema.ResourceData, meta int
|
|||
func resourceCloudStackSecondaryIPAddressRead(d *schema.ResourceData, meta interface{}) error {
|
||||
cs := meta.(*cloudstack.CloudStackClient)
|
||||
|
||||
// Retrieve the virtual_machine UUID
|
||||
virtualmachineid, e := retrieveUUID(cs, "virtual_machine", d.Get("virtual_machine").(string))
|
||||
// Retrieve the virtual_machine ID
|
||||
virtualmachineid, e := retrieveID(cs, "virtual_machine", d.Get("virtual_machine").(string))
|
||||
if e != nil {
|
||||
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))
|
||||
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(
|
||||
"Invalid parameter id value=%s due to incorrect long value format, "+
|
||||
"or entity does not exist", d.Id())) {
|
||||
|
|
|
@ -64,8 +64,8 @@ func testAccCheckCloudStackSecondaryIPAddressExists(
|
|||
|
||||
cs := testAccProvider.Meta().(*cloudstack.CloudStackClient)
|
||||
|
||||
// Retrieve the virtual_machine UUID
|
||||
virtualmachineid, e := retrieveUUID(
|
||||
// Retrieve the virtual_machine ID
|
||||
virtualmachineid, e := retrieveID(
|
||||
cs, "virtual_machine", rs.Primary.Attributes["virtual_machine"])
|
||||
if e != nil {
|
||||
return e.Error()
|
||||
|
@ -136,8 +136,8 @@ func testAccCheckCloudStackSecondaryIPAddressDestroy(s *terraform.State) error {
|
|||
return fmt.Errorf("No IP address ID is set")
|
||||
}
|
||||
|
||||
// Retrieve the virtual_machine UUID
|
||||
virtualmachineid, e := retrieveUUID(
|
||||
// Retrieve the virtual_machine ID
|
||||
virtualmachineid, e := retrieveID(
|
||||
cs, "virtual_machine", rs.Primary.Attributes["virtual_machine"])
|
||||
if e != nil {
|
||||
return e.Error()
|
||||
|
|
|
@ -116,7 +116,7 @@ func resourceCloudStackSSHKeyPairDelete(d *schema.ResourceData, meta interface{}
|
|||
// Remove the SSH Keypair
|
||||
_, err := cs.SSH.DeleteSSHKeyPair(p)
|
||||
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(
|
||||
"A key pair with name '%s' does not exist for account", d.Id())) {
|
||||
return nil
|
||||
|
|
|
@ -124,14 +124,14 @@ func resourceCloudStackTemplateCreate(d *schema.ResourceData, meta interface{})
|
|||
displaytext = name
|
||||
}
|
||||
|
||||
// Retrieve the os_type UUID
|
||||
ostypeid, e := retrieveUUID(cs, "os_type", d.Get("os_type").(string))
|
||||
// Retrieve the os_type ID
|
||||
ostypeid, e := retrieveID(cs, "os_type", d.Get("os_type").(string))
|
||||
if e != nil {
|
||||
return e.Error()
|
||||
}
|
||||
|
||||
// Retrieve the zone UUID
|
||||
zoneid, e := retrieveUUID(cs, "zone", d.Get("zone").(string))
|
||||
// Retrieve the zone ID
|
||||
zoneid, e := retrieveID(cs, "zone", d.Get("zone").(string))
|
||||
if e != nil {
|
||||
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 project, ok := d.GetOk("project"); ok {
|
||||
// Retrieve the project UUID
|
||||
projectid, e := retrieveUUID(cs, "project", project.(string))
|
||||
// Retrieve the project ID
|
||||
projectid, e := retrieveID(cs, "project", project.(string))
|
||||
if e != nil {
|
||||
return e.Error()
|
||||
}
|
||||
|
@ -236,15 +236,9 @@ func resourceCloudStackTemplateRead(d *schema.ResourceData, meta interface{}) er
|
|||
d.Set("password_enabled", t.Passwordenabled)
|
||||
d.Set("is_ready", t.Isready)
|
||||
|
||||
setValueOrUUID(d, "project", t.Project, t.Projectid)
|
||||
|
||||
if t.Zoneid == "" {
|
||||
setValueOrUUID(d, "zone", UnlimitedResourceID, UnlimitedResourceID)
|
||||
} else {
|
||||
setValueOrUUID(d, "zone", t.Zonename, t.Zoneid)
|
||||
}
|
||||
|
||||
setValueOrUUID(d, "os_type", t.Ostypename, t.Ostypeid)
|
||||
setValueOrID(d, "os_type", t.Ostypename, t.Ostypeid)
|
||||
setValueOrID(d, "project", t.Project, t.Projectid)
|
||||
setValueOrID(d, "zone", t.Zonename, t.Zoneid)
|
||||
|
||||
return nil
|
||||
}
|
||||
|
@ -273,7 +267,7 @@ func resourceCloudStackTemplateUpdate(d *schema.ResourceData, meta interface{})
|
|||
}
|
||||
|
||||
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 {
|
||||
return e.Error()
|
||||
}
|
||||
|
@ -302,7 +296,7 @@ func resourceCloudStackTemplateDelete(d *schema.ResourceData, meta interface{})
|
|||
log.Printf("[INFO] Deleting template: %s", d.Get("name").(string))
|
||||
_, err := cs.Template.DeleteTemplate(p)
|
||||
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(
|
||||
"Invalid parameter id value=%s due to incorrect long value format, "+
|
||||
"or entity does not exist", d.Id())) {
|
||||
|
|
|
@ -66,14 +66,14 @@ func resourceCloudStackVPCCreate(d *schema.ResourceData, meta interface{}) error
|
|||
|
||||
name := d.Get("name").(string)
|
||||
|
||||
// Retrieve the vpc_offering UUID
|
||||
vpcofferingid, e := retrieveUUID(cs, "vpc_offering", d.Get("vpc_offering").(string))
|
||||
// Retrieve the vpc_offering ID
|
||||
vpcofferingid, e := retrieveID(cs, "vpc_offering", d.Get("vpc_offering").(string))
|
||||
if e != nil {
|
||||
return e.Error()
|
||||
}
|
||||
|
||||
// Retrieve the zone UUID
|
||||
zoneid, e := retrieveUUID(cs, "zone", d.Get("zone").(string))
|
||||
// Retrieve the zone ID
|
||||
zoneid, e := retrieveID(cs, "zone", d.Get("zone").(string))
|
||||
if e != nil {
|
||||
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 project, ok := d.GetOk("project"); ok {
|
||||
// Retrieve the project UUID
|
||||
projectid, e := retrieveUUID(cs, "project", project.(string))
|
||||
// Retrieve the project ID
|
||||
projectid, e := retrieveID(cs, "project", project.(string))
|
||||
if e != nil {
|
||||
return e.Error()
|
||||
}
|
||||
|
@ -148,9 +148,9 @@ func resourceCloudStackVPCRead(d *schema.ResourceData, meta interface{}) error {
|
|||
return err
|
||||
}
|
||||
|
||||
setValueOrUUID(d, "vpc_offering", o.Name, v.Vpcofferingid)
|
||||
setValueOrUUID(d, "project", v.Project, v.Projectid)
|
||||
setValueOrUUID(d, "zone", v.Zonename, v.Zoneid)
|
||||
setValueOrID(d, "vpc_offering", o.Name, v.Vpcofferingid)
|
||||
setValueOrID(d, "project", v.Project, v.Projectid)
|
||||
setValueOrID(d, "zone", v.Zonename, v.Zoneid)
|
||||
|
||||
return nil
|
||||
}
|
||||
|
@ -191,7 +191,7 @@ func resourceCloudStackVPCDelete(d *schema.ResourceData, meta interface{}) error
|
|||
// Delete the VPC
|
||||
_, err := cs.VPC.DeleteVPC(p)
|
||||
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(
|
||||
"Invalid parameter id value=%s due to incorrect long value format, "+
|
||||
"or entity does not exist", d.Id())) {
|
||||
|
|
|
@ -81,7 +81,7 @@ func resourceCloudStackVPNConnectionDelete(d *schema.ResourceData, meta interfac
|
|||
// Delete the VPN Connection
|
||||
_, err := cs.VPN.DeleteVpnConnection(p)
|
||||
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(
|
||||
"Invalid parameter id value=%s due to incorrect long value format, "+
|
||||
"or entity does not exist", d.Id())) {
|
||||
|
|
|
@ -179,7 +179,7 @@ func resourceCloudStackVPNCustomerGatewayDelete(d *schema.ResourceData, meta int
|
|||
// Delete the VPN Customer Gateway
|
||||
_, err := cs.VPN.DeleteVpnCustomerGateway(p)
|
||||
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(
|
||||
"Invalid parameter id value=%s due to incorrect long value format, "+
|
||||
"or entity does not exist", d.Id())) {
|
||||
|
|
|
@ -33,8 +33,8 @@ func resourceCloudStackVPNGateway() *schema.Resource {
|
|||
func resourceCloudStackVPNGatewayCreate(d *schema.ResourceData, meta interface{}) error {
|
||||
cs := meta.(*cloudstack.CloudStackClient)
|
||||
|
||||
// Retrieve the VPC UUID
|
||||
vpcid, e := retrieveUUID(cs, "vpc", d.Get("vpc").(string))
|
||||
// Retrieve the VPC ID
|
||||
vpcid, e := retrieveID(cs, "vpc", d.Get("vpc").(string))
|
||||
if e != nil {
|
||||
return e.Error()
|
||||
}
|
||||
|
@ -69,7 +69,7 @@ func resourceCloudStackVPNGatewayRead(d *schema.ResourceData, meta interface{})
|
|||
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)
|
||||
|
||||
|
@ -85,7 +85,7 @@ func resourceCloudStackVPNGatewayDelete(d *schema.ResourceData, meta interface{}
|
|||
// Delete the VPN Gateway
|
||||
_, err := cs.VPN.DeleteVpnGateway(p)
|
||||
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(
|
||||
"Invalid parameter id value=%s due to incorrect long value format, "+
|
||||
"or entity does not exist", d.Id())) {
|
||||
|
|
|
@ -20,46 +20,51 @@ type retrieveError struct {
|
|||
}
|
||||
|
||||
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) {
|
||||
if isUUID(d.Get(key).(string)) {
|
||||
d.Set(key, uuid)
|
||||
func setValueOrID(d *schema.ResourceData, key string, value string, id string) {
|
||||
if isID(d.Get(key).(string)) {
|
||||
// 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 {
|
||||
d.Set(key, value)
|
||||
}
|
||||
}
|
||||
|
||||
func retrieveUUID(cs *cloudstack.CloudStackClient, name, value string) (uuid string, e *retrieveError) {
|
||||
// If the supplied value isn't a UUID, try to retrieve the UUID ourselves
|
||||
if isUUID(value) {
|
||||
func retrieveID(cs *cloudstack.CloudStackClient, name, value string) (id string, e *retrieveError) {
|
||||
// If the supplied value isn't a ID, try to retrieve the ID ourselves
|
||||
if isID(value) {
|
||||
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
|
||||
switch name {
|
||||
case "disk_offering":
|
||||
uuid, err = cs.DiskOffering.GetDiskOfferingID(value)
|
||||
id, err = cs.DiskOffering.GetDiskOfferingID(value)
|
||||
case "virtual_machine":
|
||||
uuid, err = cs.VirtualMachine.GetVirtualMachineID(value)
|
||||
id, err = cs.VirtualMachine.GetVirtualMachineID(value)
|
||||
case "service_offering":
|
||||
uuid, err = cs.ServiceOffering.GetServiceOfferingID(value)
|
||||
id, err = cs.ServiceOffering.GetServiceOfferingID(value)
|
||||
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":
|
||||
uuid, err = cs.VPC.GetVPCOfferingID(value)
|
||||
id, err = cs.VPC.GetVPCOfferingID(value)
|
||||
case "vpc":
|
||||
uuid, err = cs.VPC.GetVPCID(value)
|
||||
id, err = cs.VPC.GetVPCID(value)
|
||||
case "network":
|
||||
uuid, err = cs.Network.GetNetworkID(value)
|
||||
id, err = cs.Network.GetNetworkID(value)
|
||||
case "zone":
|
||||
if value == UnlimitedResourceID {
|
||||
return value, nil
|
||||
}
|
||||
uuid, err = cs.Zone.GetZoneID(value)
|
||||
id, err = cs.Zone.GetZoneID(value)
|
||||
case "ipaddress":
|
||||
p := cs.Address.NewListPublicIpAddressesParams()
|
||||
p.SetIpaddress(value)
|
||||
|
@ -69,10 +74,10 @@ func retrieveUUID(cs *cloudstack.CloudStackClient, name, value string) (uuid str
|
|||
break
|
||||
}
|
||||
if l.Count == 1 {
|
||||
uuid = l.PublicIpAddresses[0].Id
|
||||
id = l.PublicIpAddresses[0].Id
|
||||
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":
|
||||
p := cs.GuestOS.NewListOsTypesParams()
|
||||
p.SetDescription(value)
|
||||
|
@ -82,43 +87,42 @@ func retrieveUUID(cs *cloudstack.CloudStackClient, name, value string) (uuid str
|
|||
break
|
||||
}
|
||||
if l.Count == 1 {
|
||||
uuid = l.OsTypes[0].Id
|
||||
id = l.OsTypes[0].Id
|
||||
break
|
||||
}
|
||||
err = fmt.Errorf("Could not find UUID of OS Type: %s", value)
|
||||
case "project":
|
||||
uuid, err = cs.Project.GetProjectID(value)
|
||||
err = fmt.Errorf("Could not find ID of OS Type: %s", value)
|
||||
default:
|
||||
return uuid, &retrieveError{name: name, value: value,
|
||||
return id, &retrieveError{name: name, value: value,
|
||||
err: fmt.Errorf("Unknown request: %s", name)}
|
||||
}
|
||||
|
||||
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) {
|
||||
// If the supplied value isn't a UUID, try to retrieve the UUID ourselves
|
||||
if isUUID(value) {
|
||||
func retrieveTemplateID(cs *cloudstack.CloudStackClient, zoneid, value string) (id string, e *retrieveError) {
|
||||
// If the supplied value isn't a ID, try to retrieve the ID ourselves
|
||||
if isID(value) {
|
||||
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 {
|
||||
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 {
|
||||
re := regexp.MustCompile(`^[0-9a-f]{8}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{12}$`)
|
||||
return re.MatchString(s)
|
||||
// ID can be either a UUID or a UnlimitedResourceID
|
||||
func isID(id string) bool {
|
||||
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
|
||||
|
|
Loading…
Reference in New Issue