provider/openstack: Set Availability Zone in Instances (#12610)
* provider/openstack: Set Availability Zone in Instances This commit configures the openstack_compute_instance_v2 resource to set the Availability Zone of the instance resource. * vendor: Updating Gophercloud for OpenStack
This commit is contained in:
parent
cbfb29cd8f
commit
f4e74650f0
|
@ -10,6 +10,7 @@ import (
|
|||
"time"
|
||||
|
||||
"github.com/gophercloud/gophercloud"
|
||||
"github.com/gophercloud/gophercloud/openstack/compute/v2/extensions/availabilityzones"
|
||||
"github.com/gophercloud/gophercloud/openstack/compute/v2/extensions/bootfromvolume"
|
||||
"github.com/gophercloud/gophercloud/openstack/compute/v2/extensions/floatingips"
|
||||
"github.com/gophercloud/gophercloud/openstack/compute/v2/extensions/keypairs"
|
||||
|
@ -103,6 +104,7 @@ func resourceComputeInstanceV2() *schema.Resource {
|
|||
Type: schema.TypeString,
|
||||
Optional: true,
|
||||
ForceNew: true,
|
||||
Computed: true,
|
||||
},
|
||||
"network": &schema.Schema{
|
||||
Type: schema.TypeList,
|
||||
|
@ -571,6 +573,21 @@ func resourceComputeInstanceV2Read(d *schema.ResourceData, meta interface{}) err
|
|||
return err
|
||||
}
|
||||
|
||||
// Build a custom struct for the availability zone extension
|
||||
var serverWithAZ struct {
|
||||
servers.Server
|
||||
availabilityzones.ServerExt
|
||||
}
|
||||
|
||||
// Do another Get so the above work is not disturbed.
|
||||
err = servers.Get(computeClient, d.Id()).ExtractInto(&serverWithAZ)
|
||||
if err != nil {
|
||||
return CheckDeleted(d, err, "server")
|
||||
}
|
||||
|
||||
// Set the availability zone
|
||||
d.Set("availability_zone", serverWithAZ.AvailabilityZone)
|
||||
|
||||
return nil
|
||||
}
|
||||
|
||||
|
|
|
@ -29,6 +29,8 @@ func TestAccComputeV2Instance_basic(t *testing.T) {
|
|||
Check: resource.ComposeTestCheckFunc(
|
||||
testAccCheckComputeV2InstanceExists("openstack_compute_instance_v2.instance_1", &instance),
|
||||
testAccCheckComputeV2InstanceMetadata(&instance, "foo", "bar"),
|
||||
resource.TestCheckResourceAttr(
|
||||
"openstack_compute_instance_v2.instance_1", "availability_zone", "nova"),
|
||||
),
|
||||
},
|
||||
},
|
||||
|
|
12
vendor/github.com/gophercloud/gophercloud/openstack/compute/v2/extensions/availabilityzones/results.go
generated
vendored
Normal file
12
vendor/github.com/gophercloud/gophercloud/openstack/compute/v2/extensions/availabilityzones/results.go
generated
vendored
Normal file
|
@ -0,0 +1,12 @@
|
|||
package availabilityzones
|
||||
|
||||
// ServerExt is an extension to the base Server object
|
||||
type ServerExt struct {
|
||||
// AvailabilityZone is the availabilty zone the server is in.
|
||||
AvailabilityZone string `json:"OS-EXT-AZ:availability_zone"`
|
||||
}
|
||||
|
||||
// UnmarshalJSON to override default
|
||||
func (r *ServerExt) UnmarshalJSON(b []byte) error {
|
||||
return nil
|
||||
}
|
|
@ -1530,6 +1530,12 @@
|
|||
"revision": "0f64da0e36de86a0ca1a8f2fc1b0570a0d3f7504",
|
||||
"revisionTime": "2017-03-10T01:59:53Z"
|
||||
},
|
||||
{
|
||||
"checksumSHA1": "y49Ur726Juznj85+23ZgqMvehgg=",
|
||||
"path": "github.com/gophercloud/gophercloud/openstack/compute/v2/extensions/availabilityzones",
|
||||
"revision": "0f64da0e36de86a0ca1a8f2fc1b0570a0d3f7504",
|
||||
"revisionTime": "2017-03-10T01:59:53Z"
|
||||
},
|
||||
{
|
||||
"checksumSHA1": "w2wHF5eEBE89ZYlkS9GAJsSIq9U=",
|
||||
"path": "github.com/gophercloud/gophercloud/openstack/compute/v2/extensions/bootfromvolume",
|
||||
|
|
Loading…
Reference in New Issue