diff --git a/builtin/providers/cloudstack/provider_test.go b/builtin/providers/cloudstack/provider_test.go index 878ab1882..d48bec984 100644 --- a/builtin/providers/cloudstack/provider_test.go +++ b/builtin/providers/cloudstack/provider_test.go @@ -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") diff --git a/builtin/providers/cloudstack/resource_cloudstack_disk.go b/builtin/providers/cloudstack/resource_cloudstack_disk.go index 382cd2876..c4d84f520 100644 --- a/builtin/providers/cloudstack/resource_cloudstack_disk.go +++ b/builtin/providers/cloudstack/resource_cloudstack_disk.go @@ -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 diff --git a/builtin/providers/cloudstack/resource_cloudstack_instance.go b/builtin/providers/cloudstack/resource_cloudstack_instance.go index b88e4a255..c07678f3e 100644 --- a/builtin/providers/cloudstack/resource_cloudstack_instance.go +++ b/builtin/providers/cloudstack/resource_cloudstack_instance.go @@ -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 } diff --git a/builtin/providers/cloudstack/resource_cloudstack_network.go b/builtin/providers/cloudstack/resource_cloudstack_network.go index 4eb03f666..a23547896 100644 --- a/builtin/providers/cloudstack/resource_cloudstack_network.go +++ b/builtin/providers/cloudstack/resource_cloudstack_network.go @@ -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 } diff --git a/builtin/providers/cloudstack/resource_cloudstack_network_acl.go b/builtin/providers/cloudstack/resource_cloudstack_network_acl.go index 3aea0d17e..7f073bbf8 100644 --- a/builtin/providers/cloudstack/resource_cloudstack_network_acl.go +++ b/builtin/providers/cloudstack/resource_cloudstack_network_acl.go @@ -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 } diff --git a/builtin/providers/cloudstack/resource_cloudstack_nic.go b/builtin/providers/cloudstack/resource_cloudstack_nic.go index 99f2d3000..2eb89c80b 100644 --- a/builtin/providers/cloudstack/resource_cloudstack_nic.go +++ b/builtin/providers/cloudstack/resource_cloudstack_nic.go @@ -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 } diff --git a/builtin/providers/cloudstack/resource_cloudstack_template.go b/builtin/providers/cloudstack/resource_cloudstack_template.go index 4469f2d3f..608a129a8 100644 --- a/builtin/providers/cloudstack/resource_cloudstack_template.go +++ b/builtin/providers/cloudstack/resource_cloudstack_template.go @@ -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 } diff --git a/builtin/providers/cloudstack/resource_cloudstack_vpc.go b/builtin/providers/cloudstack/resource_cloudstack_vpc.go index 5b884d031..cb829495b 100644 --- a/builtin/providers/cloudstack/resource_cloudstack_vpc.go +++ b/builtin/providers/cloudstack/resource_cloudstack_vpc.go @@ -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 } diff --git a/builtin/providers/cloudstack/resource_cloudstack_vpn_gateway.go b/builtin/providers/cloudstack/resource_cloudstack_vpn_gateway.go index 063c31777..704511ca8 100644 --- a/builtin/providers/cloudstack/resource_cloudstack_vpn_gateway.go +++ b/builtin/providers/cloudstack/resource_cloudstack_vpn_gateway.go @@ -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 diff --git a/builtin/providers/cloudstack/resources.go b/builtin/providers/cloudstack/resources.go index 37f5cb965..85fa0bd5a 100644 --- a/builtin/providers/cloudstack/resources.go +++ b/builtin/providers/cloudstack/resources.go @@ -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) { diff --git a/website/source/docs/providers/cloudstack/r/disk.html.markdown b/website/source/docs/providers/cloudstack/r/disk.html.markdown index af87ba220..53ae73656 100644 --- a/website/source/docs/providers/cloudstack/r/disk.html.markdown +++ b/website/source/docs/providers/cloudstack/r/disk.html.markdown @@ -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 diff --git a/website/source/docs/providers/cloudstack/r/instance.html.markdown b/website/source/docs/providers/cloudstack/r/instance.html.markdown index af9efd423..e09cd6c6e 100644 --- a/website/source/docs/providers/cloudstack/r/instance.html.markdown +++ b/website/source/docs/providers/cloudstack/r/instance.html.markdown @@ -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. diff --git a/website/source/docs/providers/cloudstack/r/network.html.markdown b/website/source/docs/providers/cloudstack/r/network.html.markdown index 98e07f178..9819a8ce3 100644 --- a/website/source/docs/providers/cloudstack/r/network.html.markdown +++ b/website/source/docs/providers/cloudstack/r/network.html.markdown @@ -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 diff --git a/website/source/docs/providers/cloudstack/r/network_acl.html.markdown b/website/source/docs/providers/cloudstack/r/network_acl.html.markdown index 487d0fe90..0001cbffb 100644 --- a/website/source/docs/providers/cloudstack/r/network_acl.html.markdown +++ b/website/source/docs/providers/cloudstack/r/network_acl.html.markdown @@ -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 diff --git a/website/source/docs/providers/cloudstack/r/nic.html.markdown b/website/source/docs/providers/cloudstack/r/nic.html.markdown index 8633034f9..09bfb0bd4 100644 --- a/website/source/docs/providers/cloudstack/r/nic.html.markdown +++ b/website/source/docs/providers/cloudstack/r/nic.html.markdown @@ -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 diff --git a/website/source/docs/providers/cloudstack/r/template.html.markdown b/website/source/docs/providers/cloudstack/r/template.html.markdown index 1757193af..b31c24db0 100644 --- a/website/source/docs/providers/cloudstack/r/template.html.markdown +++ b/website/source/docs/providers/cloudstack/r/template.html.markdown @@ -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 diff --git a/website/source/docs/providers/cloudstack/r/vpc.html.markdown b/website/source/docs/providers/cloudstack/r/vpc.html.markdown index 141bc9203..1e40c6466 100644 --- a/website/source/docs/providers/cloudstack/r/vpc.html.markdown +++ b/website/source/docs/providers/cloudstack/r/vpc.html.markdown @@ -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 diff --git a/website/source/docs/providers/cloudstack/r/vpn_gateway.html.markdown b/website/source/docs/providers/cloudstack/r/vpn_gateway.html.markdown index 10aabd796..5bf9cf389 100644 --- a/website/source/docs/providers/cloudstack/r/vpn_gateway.html.markdown +++ b/website/source/docs/providers/cloudstack/r/vpn_gateway.html.markdown @@ -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