Fixes #1: sets the rights values based on isUUID

This commit is contained in:
Avi Nanhkoesingh 2015-04-29 11:21:37 +02:00 committed by Sander van Harmelen
parent 61509fd96a
commit 1411d4010f
18 changed files with 71 additions and 33 deletions

View File

@ -28,6 +28,28 @@ func TestProvider_impl(t *testing.T) {
var _ terraform.ResourceProvider = Provider()
}
func testSetValueOnResourceData(t *testing.T) {
d := schema.ResourceData{}
d.Set("id", "name")
setValueOrUUID(&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) {
d := schema.ResourceData{}
d.Set("id", "54711781-274e-41b2-83c0-17194d0108f7")
setValueOrUUID(&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'")
}
}
func testAccPreCheck(t *testing.T) {
if v := os.Getenv("CLOUDSTACK_API_URL"); v == "" {
t.Fatal("CLOUDSTACK_API_URL must be set for acceptance tests")

View File

@ -139,10 +139,11 @@ func resourceCloudStackDiskRead(d *schema.ResourceData, meta interface{}) error
}
d.Set("name", v.Name)
d.Set("attach", v.Attached != "") // If attached this will contain a timestamp when attached
d.Set("disk_offering", v.Diskofferingname)
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("zone", v.Zonename)
setValueOrUUID(d, "disk_offering", v.Diskofferingname, v.Diskofferingid)
setValueOrUUID(d, "zone", v.Zonename, v.Zoneid)
if v.Attached != "" {
// Get the virtual machine details

View File

@ -184,12 +184,13 @@ func resourceCloudStackInstanceRead(d *schema.ResourceData, meta interface{}) er
// Update the config
d.Set("name", vm.Name)
d.Set("display_name", vm.Displayname)
d.Set("service_offering", vm.Serviceofferingname)
d.Set("network", vm.Nic[0].Networkname)
d.Set("ipaddress", vm.Nic[0].Ipaddress)
d.Set("template", vm.Templatename)
d.Set("zone", vm.Zonename)
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)
return nil
}

View File

@ -149,8 +149,9 @@ func resourceCloudStackNetworkRead(d *schema.ResourceData, meta interface{}) err
d.Set("name", n.Name)
d.Set("display_text", n.Displaytext)
d.Set("cidr", n.Cidr)
d.Set("network_offering", n.Networkofferingname)
d.Set("zone", n.Zonename)
setValueOrUUID(d, "network_offering", n.Networkofferingname, n.Networkofferingid)
setValueOrUUID(d, "zone", n.Zonename, n.Zoneid)
return nil
}

View File

@ -95,7 +95,7 @@ func resourceCloudStackNetworkACLRead(d *schema.ResourceData, meta interface{})
return err
}
d.Set("vpc", v.Name)
setValueOrUUID(d, "vpc", v.Name, v.Id)
return nil
}

View File

@ -102,9 +102,9 @@ func resourceCloudStackNICRead(d *schema.ResourceData, meta interface{}) error {
found := false
for _, n := range vm.Nic {
if n.Id == d.Id() {
d.Set("network", n.Networkname)
d.Set("ipaddress", n.Ipaddress)
d.Set("virtual_machine", vm.Name)
setValueOrUUID(d, "network", n.Networkname, n.Networkid)
setValueOrUUID(d, "virtual_machine", vm.Name, vm.Id)
found = true
break
}

View File

@ -205,8 +205,6 @@ func resourceCloudStackTemplateRead(d *schema.ResourceData, meta interface{}) er
d.Set("display_text", t.Displaytext)
d.Set("format", t.Format)
d.Set("hypervisor", t.Hypervisor)
d.Set("os_type", t.Ostypename)
d.Set("zone", t.Zonename)
d.Set("is_dynamically_scalable", t.Isdynamicallyscalable)
d.Set("is_extractable", t.Isextractable)
d.Set("is_featured", t.Isfeatured)
@ -214,6 +212,9 @@ func resourceCloudStackTemplateRead(d *schema.ResourceData, meta interface{}) er
d.Set("password_enabled", t.Passwordenabled)
d.Set("is_ready", t.Isready)
setValueOrUUID(d, "os_type", t.Ostypename, t.Ostypeid)
setValueOrUUID(d, "zone", t.Zonename, t.Zoneid)
return nil
}

View File

@ -105,7 +105,8 @@ func resourceCloudStackVPCRead(d *schema.ResourceData, meta interface{}) error {
d.Set("name", v.Name)
d.Set("display_text", v.Displaytext)
d.Set("cidr", v.Cidr)
d.Set("zone", v.Zonename)
setValueOrUUID(d, "zone", v.Zonename, v.Zoneid)
// Get the VPC offering details
o, _, err := cs.VPC.GetVPCOfferingByID(v.Vpcofferingid)
@ -113,7 +114,7 @@ func resourceCloudStackVPCRead(d *schema.ResourceData, meta interface{}) error {
return err
}
d.Set("vpc_offering", o.Name)
setValueOrUUID(d, "vpc_offering", o.Name, v.Vpcofferingid)
return nil
}

View File

@ -69,6 +69,8 @@ func resourceCloudStackVPNGatewayRead(d *schema.ResourceData, meta interface{})
return err
}
setValueOrUUID(d, "vpc", d.Get("vpc").(string), v.Vpcid)
d.Set("public_ip", v.Publicip)
return nil

View File

@ -5,6 +5,7 @@ import (
"log"
"regexp"
"github.com/hashicorp/terraform/helper/schema"
"github.com/xanzy/go-cloudstack/cloudstack"
)
@ -18,6 +19,14 @@ func (e *retrieveError) Error() error {
return fmt.Errorf("Error retrieving UUID 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)
} 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) {

View File

@ -36,8 +36,8 @@ The following arguments are supported:
* `device` - (Optional) The device to map the disk volume to within the guest OS.
* `disk_offering` - (Required) The name of the disk offering to use for this
disk volume.
* `disk_offering` - (Required) The name or ID of the disk offering to use for
this disk volume.
* `size` - (Optional) The size of the disk volume in gigabytes.
@ -47,7 +47,7 @@ The following arguments are supported:
* `virtual_machine` - (Optional) The name of the virtual machine to which you
want to attach the disk volume.
* `zone` - (Required) The name of the zone where this disk volume will be available.
* `zone` - (Required) The name or ID of the zone where this disk volume will be available.
Changing this forces a new resource to be created.
## Attributes Reference

View File

@ -32,15 +32,15 @@ The following arguments are supported:
* `display_name` - (Optional) The display name of the instance.
* `service_offering` - (Required) The service offering used for this instance.
* `service_offering` - (Required) The name or ID of the service offering used for this instance.
* `network` - (Optional) The name of the network to connect this instance to.
* `network` - (Optional) The name or ID of the network to connect this instance to.
Changing this forces a new resource to be created.
* `ipaddress` - (Optional) The IP address to assign to this instance. Changing
this forces a new resource to be created.
* `template` - (Required) The name of the template used for this instance.
* `template` - (Required) The name or ID of the template used for this instance.
Changing this forces a new resource to be created.
* `zone` - (Required) The name of the zone where this instance will be created.

View File

@ -34,8 +34,8 @@ The following arguments are supported:
* `cidr` - (Required) The CIDR block for the network. Changing this forces a new
resource to be created.
* `network_offering` - (Required) The name of the network offering to use for
this network.
* `network_offering` - (Required) The name or ID of the network offering to use
for this network.
* `vpc` - (Optional) The name of the VPC to create this network for. Changing
this forces a new resource to be created.
@ -43,7 +43,7 @@ The following arguments are supported:
* `aclid` - (Optional) The ID of a network ACL that should be attached to the
network. Changing this forces a new resource to be created.
* `zone` - (Required) The name of the zone where this disk volume will be
* `zone` - (Required) The name or ID of the zone where this disk volume will be
available. Changing this forces a new resource to be created.
## Attributes Reference

View File

@ -27,8 +27,8 @@ The following arguments are supported:
to be created.
* `description` - (Optional) The description of the ACL. Changing this forces a
new resource to be created.
* `vpc` - (Required) The name of the VPC to create this ACL for. Changing this
forces a new resource to be created.
* `vpc` - (Required) The name or ID of the VPC to create this ACL for. Changing
this forces a new resource to be created.
## Attributes Reference

View File

@ -26,14 +26,14 @@ resource "cloudstack_nic" "test" {
The following arguments are supported:
* `network` - (Required) The name of the network to plug the NIC into. Changing
* `network` - (Required) The name or ID of the network to plug the NIC into. Changing
this forces a new resource to be created.
* `ipaddress` - (Optional) The IP address to assign to the NIC. Changing this
forces a new resource to be created.
* `virtual_machine` - (Required) The name of the virtual machine to which to
attach the NIC. Changing this forces a new resource to be created.
* `virtual_machine` - (Required) The name or ID of the virtual machine to which
to attach the NIC. Changing this forces a new resource to be created.
## Attributes Reference

View File

@ -43,7 +43,7 @@ The following arguments are supported:
* `url` - (Required) The URL of where the template is hosted. Changing this
forces a new resource to be created.
* `zone` - (Required) The name of the zone where this template will be created.
* `zone` - (Required) The name or ID of the zone where this template will be created.
Changing this forces a new resource to be created.
* `is_dynamically_scalable` - (Optional) Set to indicate if the template contains

View File

@ -34,10 +34,10 @@ The following arguments are supported:
* `cidr` - (Required) The CIDR block for the VPC. Changing this forces a new
resource to be created.
* `vpc_offering` - (Required) The name of the VPC offering to use for this VPC.
* `vpc_offering` - (Required) The name or ID of the VPC offering to use for this VPC.
Changing this forces a new resource to be created.
* `zone` - (Required) The name of the zone where this disk volume will be
* `zone` - (Required) The name or ID of the zone where this disk volume will be
available. Changing this forces a new resource to be created.
## Attributes Reference

View File

@ -24,7 +24,7 @@ resource "cloudstack_vpn_gateway" "default" {
The following arguments are supported:
* `vpc` - (Required) The name of the VPC for which to create the VPN Gateway.
* `vpc` - (Required) The name or ID of the VPC for which to create the VPN Gateway.
Changing this forces a new resource to be created.
## Attributes Reference