From fe0a7a5ec5a005c9715e57b43f9964d1f7c3d76f Mon Sep 17 00:00:00 2001 From: Joe Topjian Date: Sat, 11 Apr 2015 04:11:34 +0000 Subject: [PATCH] Allow Blank Region When OS_REGION_NAME is not set, fall back to a blank string. This will cause gophercloud to use the cloud's only region in single-region clouds. --- builtin/providers/openstack/provider.go | 7 +++++++ builtin/providers/openstack/provider_test.go | 5 ++--- .../openstack/resource_openstack_blockstorage_volume_v1.go | 2 +- .../openstack/resource_openstack_compute_floatingip_v2.go | 2 +- .../openstack/resource_openstack_compute_instance_v2.go | 2 +- .../openstack/resource_openstack_compute_keypair_v2.go | 2 +- .../openstack/resource_openstack_compute_secgroup_v2.go | 2 +- .../openstack/resource_openstack_fw_firewall_v1.go | 2 +- .../providers/openstack/resource_openstack_fw_policy_v1.go | 2 +- .../providers/openstack/resource_openstack_fw_rule_v1.go | 2 +- .../openstack/resource_openstack_lb_monitor_v1.go | 2 +- .../providers/openstack/resource_openstack_lb_pool_v1.go | 4 ++-- .../providers/openstack/resource_openstack_lb_vip_v1.go | 2 +- .../resource_openstack_networking_floatingip_v2.go | 2 +- .../openstack/resource_openstack_networking_network_v2.go | 2 +- .../resource_openstack_networking_router_interface_v2.go | 2 +- .../openstack/resource_openstack_networking_router_v2.go | 2 +- .../openstack/resource_openstack_networking_subnet_v2.go | 2 +- .../resource_openstack_objectstorage_container_v1.go | 2 +- 19 files changed, 27 insertions(+), 21 deletions(-) diff --git a/builtin/providers/openstack/provider.go b/builtin/providers/openstack/provider.go index a43242333..d71f5a8f0 100644 --- a/builtin/providers/openstack/provider.go +++ b/builtin/providers/openstack/provider.go @@ -111,3 +111,10 @@ func envDefaultFunc(k string) schema.SchemaDefaultFunc { return nil, nil } } + +func envDefaultFuncAllowMissing(k string) schema.SchemaDefaultFunc { + return func() (interface{}, error) { + v := os.Getenv(k) + return v, nil + } +} diff --git a/builtin/providers/openstack/provider_test.go b/builtin/providers/openstack/provider_test.go index 7e4b6d99f..686bf0533 100644 --- a/builtin/providers/openstack/provider_test.go +++ b/builtin/providers/openstack/provider_test.go @@ -40,10 +40,9 @@ func testAccPreCheck(t *testing.T) { } v = os.Getenv("OS_REGION_NAME") - if v == "" { - t.Fatal("OS_REGION_NAME must be set for acceptance tests") + if v != "" { + OS_REGION_NAME = v } - OS_REGION_NAME = v v1 := os.Getenv("OS_IMAGE_ID") v2 := os.Getenv("OS_IMAGE_NAME") diff --git a/builtin/providers/openstack/resource_openstack_blockstorage_volume_v1.go b/builtin/providers/openstack/resource_openstack_blockstorage_volume_v1.go index dc2638590..c83bc538e 100644 --- a/builtin/providers/openstack/resource_openstack_blockstorage_volume_v1.go +++ b/builtin/providers/openstack/resource_openstack_blockstorage_volume_v1.go @@ -26,7 +26,7 @@ func resourceBlockStorageVolumeV1() *schema.Resource { Type: schema.TypeString, Required: true, ForceNew: true, - DefaultFunc: envDefaultFunc("OS_REGION_NAME"), + DefaultFunc: envDefaultFuncAllowMissing("OS_REGION_NAME"), }, "size": &schema.Schema{ Type: schema.TypeInt, diff --git a/builtin/providers/openstack/resource_openstack_compute_floatingip_v2.go b/builtin/providers/openstack/resource_openstack_compute_floatingip_v2.go index bb2facc4e..323ec7608 100644 --- a/builtin/providers/openstack/resource_openstack_compute_floatingip_v2.go +++ b/builtin/providers/openstack/resource_openstack_compute_floatingip_v2.go @@ -20,7 +20,7 @@ func resourceComputeFloatingIPV2() *schema.Resource { Type: schema.TypeString, Required: true, ForceNew: true, - DefaultFunc: envDefaultFunc("OS_REGION_NAME"), + DefaultFunc: envDefaultFuncAllowMissing("OS_REGION_NAME"), }, "pool": &schema.Schema{ diff --git a/builtin/providers/openstack/resource_openstack_compute_instance_v2.go b/builtin/providers/openstack/resource_openstack_compute_instance_v2.go index a6cf8a597..02dafe5ae 100644 --- a/builtin/providers/openstack/resource_openstack_compute_instance_v2.go +++ b/builtin/providers/openstack/resource_openstack_compute_instance_v2.go @@ -36,7 +36,7 @@ func resourceComputeInstanceV2() *schema.Resource { Type: schema.TypeString, Required: true, ForceNew: true, - DefaultFunc: envDefaultFunc("OS_REGION_NAME"), + DefaultFunc: envDefaultFuncAllowMissing("OS_REGION_NAME"), }, "name": &schema.Schema{ Type: schema.TypeString, diff --git a/builtin/providers/openstack/resource_openstack_compute_keypair_v2.go b/builtin/providers/openstack/resource_openstack_compute_keypair_v2.go index db6bed5b2..bc9a28b38 100644 --- a/builtin/providers/openstack/resource_openstack_compute_keypair_v2.go +++ b/builtin/providers/openstack/resource_openstack_compute_keypair_v2.go @@ -19,7 +19,7 @@ func resourceComputeKeypairV2() *schema.Resource { Type: schema.TypeString, Required: true, ForceNew: true, - DefaultFunc: envDefaultFunc("OS_REGION_NAME"), + DefaultFunc: envDefaultFuncAllowMissing("OS_REGION_NAME"), }, "name": &schema.Schema{ Type: schema.TypeString, diff --git a/builtin/providers/openstack/resource_openstack_compute_secgroup_v2.go b/builtin/providers/openstack/resource_openstack_compute_secgroup_v2.go index ca646d77d..e6d8be8ea 100644 --- a/builtin/providers/openstack/resource_openstack_compute_secgroup_v2.go +++ b/builtin/providers/openstack/resource_openstack_compute_secgroup_v2.go @@ -23,7 +23,7 @@ func resourceComputeSecGroupV2() *schema.Resource { Type: schema.TypeString, Required: true, ForceNew: true, - DefaultFunc: envDefaultFunc("OS_REGION_NAME"), + DefaultFunc: envDefaultFuncAllowMissing("OS_REGION_NAME"), }, "name": &schema.Schema{ Type: schema.TypeString, diff --git a/builtin/providers/openstack/resource_openstack_fw_firewall_v1.go b/builtin/providers/openstack/resource_openstack_fw_firewall_v1.go index 8505ac3b3..e845babdc 100644 --- a/builtin/providers/openstack/resource_openstack_fw_firewall_v1.go +++ b/builtin/providers/openstack/resource_openstack_fw_firewall_v1.go @@ -23,7 +23,7 @@ func resourceFWFirewallV1() *schema.Resource { Type: schema.TypeString, Required: true, ForceNew: true, - DefaultFunc: envDefaultFunc("OS_REGION_NAME"), + DefaultFunc: envDefaultFuncAllowMissing("OS_REGION_NAME"), }, "name": &schema.Schema{ Type: schema.TypeString, diff --git a/builtin/providers/openstack/resource_openstack_fw_policy_v1.go b/builtin/providers/openstack/resource_openstack_fw_policy_v1.go index 0560bfcef..a1c13853c 100644 --- a/builtin/providers/openstack/resource_openstack_fw_policy_v1.go +++ b/builtin/providers/openstack/resource_openstack_fw_policy_v1.go @@ -23,7 +23,7 @@ func resourceFWPolicyV1() *schema.Resource { Type: schema.TypeString, Required: true, ForceNew: true, - DefaultFunc: envDefaultFunc("OS_REGION_NAME"), + DefaultFunc: envDefaultFuncAllowMissing("OS_REGION_NAME"), }, "name": &schema.Schema{ Type: schema.TypeString, diff --git a/builtin/providers/openstack/resource_openstack_fw_rule_v1.go b/builtin/providers/openstack/resource_openstack_fw_rule_v1.go index f0f5affcc..47728ab3f 100644 --- a/builtin/providers/openstack/resource_openstack_fw_rule_v1.go +++ b/builtin/providers/openstack/resource_openstack_fw_rule_v1.go @@ -21,7 +21,7 @@ func resourceFWRuleV1() *schema.Resource { Type: schema.TypeString, Required: true, ForceNew: true, - DefaultFunc: envDefaultFunc("OS_REGION_NAME"), + DefaultFunc: envDefaultFuncAllowMissing("OS_REGION_NAME"), }, "name": &schema.Schema{ Type: schema.TypeString, diff --git a/builtin/providers/openstack/resource_openstack_lb_monitor_v1.go b/builtin/providers/openstack/resource_openstack_lb_monitor_v1.go index cdfd54ccc..35dcc9f60 100644 --- a/builtin/providers/openstack/resource_openstack_lb_monitor_v1.go +++ b/builtin/providers/openstack/resource_openstack_lb_monitor_v1.go @@ -21,7 +21,7 @@ func resourceLBMonitorV1() *schema.Resource { Type: schema.TypeString, Required: true, ForceNew: true, - DefaultFunc: envDefaultFunc("OS_REGION_NAME"), + DefaultFunc: envDefaultFuncAllowMissing("OS_REGION_NAME"), }, "tenant_id": &schema.Schema{ Type: schema.TypeString, diff --git a/builtin/providers/openstack/resource_openstack_lb_pool_v1.go b/builtin/providers/openstack/resource_openstack_lb_pool_v1.go index 6b69f2fac..a41747a1f 100644 --- a/builtin/providers/openstack/resource_openstack_lb_pool_v1.go +++ b/builtin/providers/openstack/resource_openstack_lb_pool_v1.go @@ -24,7 +24,7 @@ func resourceLBPoolV1() *schema.Resource { Type: schema.TypeString, Required: true, ForceNew: true, - DefaultFunc: envDefaultFunc("OS_REGION_NAME"), + DefaultFunc: envDefaultFuncAllowMissing("OS_REGION_NAME"), }, "name": &schema.Schema{ Type: schema.TypeString, @@ -61,7 +61,7 @@ func resourceLBPoolV1() *schema.Resource { Type: schema.TypeString, Required: true, ForceNew: true, - DefaultFunc: envDefaultFunc("OS_REGION_NAME"), + DefaultFunc: envDefaultFuncAllowMissing("OS_REGION_NAME"), }, "tenant_id": &schema.Schema{ Type: schema.TypeString, diff --git a/builtin/providers/openstack/resource_openstack_lb_vip_v1.go b/builtin/providers/openstack/resource_openstack_lb_vip_v1.go index bd2ae135e..e2e2a26e4 100644 --- a/builtin/providers/openstack/resource_openstack_lb_vip_v1.go +++ b/builtin/providers/openstack/resource_openstack_lb_vip_v1.go @@ -22,7 +22,7 @@ func resourceLBVipV1() *schema.Resource { Type: schema.TypeString, Required: true, ForceNew: true, - DefaultFunc: envDefaultFunc("OS_REGION_NAME"), + DefaultFunc: envDefaultFuncAllowMissing("OS_REGION_NAME"), }, "name": &schema.Schema{ Type: schema.TypeString, diff --git a/builtin/providers/openstack/resource_openstack_networking_floatingip_v2.go b/builtin/providers/openstack/resource_openstack_networking_floatingip_v2.go index fd8b3fc65..1b81c6a96 100644 --- a/builtin/providers/openstack/resource_openstack_networking_floatingip_v2.go +++ b/builtin/providers/openstack/resource_openstack_networking_floatingip_v2.go @@ -21,7 +21,7 @@ func resourceNetworkingFloatingIPV2() *schema.Resource { Type: schema.TypeString, Required: true, ForceNew: true, - DefaultFunc: envDefaultFunc("OS_REGION_NAME"), + DefaultFunc: envDefaultFuncAllowMissing("OS_REGION_NAME"), }, "address": &schema.Schema{ Type: schema.TypeString, diff --git a/builtin/providers/openstack/resource_openstack_networking_network_v2.go b/builtin/providers/openstack/resource_openstack_networking_network_v2.go index 2ac4ab94e..0977f3ad4 100644 --- a/builtin/providers/openstack/resource_openstack_networking_network_v2.go +++ b/builtin/providers/openstack/resource_openstack_networking_network_v2.go @@ -21,7 +21,7 @@ func resourceNetworkingNetworkV2() *schema.Resource { Type: schema.TypeString, Required: true, ForceNew: true, - DefaultFunc: envDefaultFunc("OS_REGION_NAME"), + DefaultFunc: envDefaultFuncAllowMissing("OS_REGION_NAME"), }, "name": &schema.Schema{ Type: schema.TypeString, diff --git a/builtin/providers/openstack/resource_openstack_networking_router_interface_v2.go b/builtin/providers/openstack/resource_openstack_networking_router_interface_v2.go index e67ff6f58..1e60c30ef 100644 --- a/builtin/providers/openstack/resource_openstack_networking_router_interface_v2.go +++ b/builtin/providers/openstack/resource_openstack_networking_router_interface_v2.go @@ -21,7 +21,7 @@ func resourceNetworkingRouterInterfaceV2() *schema.Resource { Type: schema.TypeString, Required: true, ForceNew: true, - DefaultFunc: envDefaultFunc("OS_REGION_NAME"), + DefaultFunc: envDefaultFuncAllowMissing("OS_REGION_NAME"), }, "router_id": &schema.Schema{ Type: schema.TypeString, diff --git a/builtin/providers/openstack/resource_openstack_networking_router_v2.go b/builtin/providers/openstack/resource_openstack_networking_router_v2.go index 3b6df4816..39ecc6ee2 100644 --- a/builtin/providers/openstack/resource_openstack_networking_router_v2.go +++ b/builtin/providers/openstack/resource_openstack_networking_router_v2.go @@ -22,7 +22,7 @@ func resourceNetworkingRouterV2() *schema.Resource { Type: schema.TypeString, Required: true, ForceNew: true, - DefaultFunc: envDefaultFunc("OS_REGION_NAME"), + DefaultFunc: envDefaultFuncAllowMissing("OS_REGION_NAME"), }, "name": &schema.Schema{ Type: schema.TypeString, diff --git a/builtin/providers/openstack/resource_openstack_networking_subnet_v2.go b/builtin/providers/openstack/resource_openstack_networking_subnet_v2.go index 2f898bb4c..573e4d7ee 100644 --- a/builtin/providers/openstack/resource_openstack_networking_subnet_v2.go +++ b/builtin/providers/openstack/resource_openstack_networking_subnet_v2.go @@ -22,7 +22,7 @@ func resourceNetworkingSubnetV2() *schema.Resource { Type: schema.TypeString, Required: true, ForceNew: true, - DefaultFunc: envDefaultFunc("OS_REGION_NAME"), + DefaultFunc: envDefaultFuncAllowMissing("OS_REGION_NAME"), }, "network_id": &schema.Schema{ Type: schema.TypeString, diff --git a/builtin/providers/openstack/resource_openstack_objectstorage_container_v1.go b/builtin/providers/openstack/resource_openstack_objectstorage_container_v1.go index 31666a356..b476a4080 100644 --- a/builtin/providers/openstack/resource_openstack_objectstorage_container_v1.go +++ b/builtin/providers/openstack/resource_openstack_objectstorage_container_v1.go @@ -20,7 +20,7 @@ func resourceObjectStorageContainerV1() *schema.Resource { Type: schema.TypeString, Required: true, ForceNew: true, - DefaultFunc: envDefaultFunc("OS_REGION_NAME"), + DefaultFunc: envDefaultFuncAllowMissing("OS_REGION_NAME"), }, "name": &schema.Schema{ Type: schema.TypeString,