From aa950be63bf5120fa1200824e0332fe0fde52b5b Mon Sep 17 00:00:00 2001 From: Hany Fahim Date: Thu, 24 Sep 2015 16:16:12 -0400 Subject: [PATCH] Use constant for global resources --- .../providers/cloudstack/resource_cloudstack_template.go | 6 +++--- builtin/providers/cloudstack/resources.go | 4 +++- 2 files changed, 6 insertions(+), 4 deletions(-) diff --git a/builtin/providers/cloudstack/resource_cloudstack_template.go b/builtin/providers/cloudstack/resource_cloudstack_template.go index 139a1ef52..6762e3467 100644 --- a/builtin/providers/cloudstack/resource_cloudstack_template.go +++ b/builtin/providers/cloudstack/resource_cloudstack_template.go @@ -219,12 +219,12 @@ func resourceCloudStackTemplateRead(d *schema.ResourceData, meta interface{}) er d.Set("password_enabled", t.Passwordenabled) d.Set("is_ready", t.Isready) - if t.Zoneid == "" { - d.Set("zone", "-1") + if t.Zoneid == IS_GLOBAL_RESOURCE { + setValueOrUUID(d, "zone", t.Zonename, IS_GLOBAL_RESOURCE) } else { setValueOrUUID(d, "zone", t.Zonename, t.Zoneid) } - + setValueOrUUID(d, "os_type", t.Ostypename, t.Ostypeid) return nil diff --git a/builtin/providers/cloudstack/resources.go b/builtin/providers/cloudstack/resources.go index 6e259ba5f..954bfd36c 100644 --- a/builtin/providers/cloudstack/resources.go +++ b/builtin/providers/cloudstack/resources.go @@ -10,6 +10,8 @@ import ( "github.com/xanzy/go-cloudstack/cloudstack" ) +const IS_GLOBAL_RESOURCE = "-1" + type retrieveError struct { name string value string @@ -53,7 +55,7 @@ func retrieveUUID(cs *cloudstack.CloudStackClient, name, value string) (uuid str case "network": uuid, err = cs.Network.GetNetworkID(value) case "zone": - if value == "-1" { + if value == IS_GLOBAL_RESOURCE { return value, nil } uuid, err = cs.Zone.GetZoneID(value)