Merge pull request #6921 from jtopjian/openstack-blockdevice-forcenew

provider/openstack: Enforce ForceNew on Instance Block Device
This commit is contained in:
Joe Topjian 2016-06-02 20:30:46 -06:00
commit 8691f2477d
3 changed files with 71 additions and 6 deletions

View File

@ -193,37 +193,43 @@ func resourceComputeInstanceV2() *schema.Resource {
"block_device": &schema.Schema{ "block_device": &schema.Schema{
Type: schema.TypeList, Type: schema.TypeList,
Optional: true, Optional: true,
ForceNew: true,
Elem: &schema.Resource{ Elem: &schema.Resource{
Schema: map[string]*schema.Schema{ Schema: map[string]*schema.Schema{
"source_type": &schema.Schema{ "source_type": &schema.Schema{
Type: schema.TypeString, Type: schema.TypeString,
Required: true, Required: true,
ForceNew: true,
}, },
"uuid": &schema.Schema{ "uuid": &schema.Schema{
Type: schema.TypeString, Type: schema.TypeString,
Optional: true, Optional: true,
ForceNew: true,
}, },
"volume_size": &schema.Schema{ "volume_size": &schema.Schema{
Type: schema.TypeInt, Type: schema.TypeInt,
Optional: true, Optional: true,
ForceNew: true,
}, },
"destination_type": &schema.Schema{ "destination_type": &schema.Schema{
Type: schema.TypeString, Type: schema.TypeString,
Optional: true, Optional: true,
ForceNew: true,
}, },
"boot_index": &schema.Schema{ "boot_index": &schema.Schema{
Type: schema.TypeInt, Type: schema.TypeInt,
Optional: true, Optional: true,
ForceNew: true,
}, },
"delete_on_termination": &schema.Schema{ "delete_on_termination": &schema.Schema{
Type: schema.TypeBool, Type: schema.TypeBool,
Optional: true, Optional: true,
Default: false, Default: false,
ForceNew: true,
}, },
"guest_format": &schema.Schema{ "guest_format": &schema.Schema{
Type: schema.TypeString, Type: schema.TypeString,
Optional: true, Optional: true,
ForceNew: true,
}, },
}, },
}, },

View File

@ -426,6 +426,61 @@ func TestAccComputeV2Instance_bootFromVolumeVolume(t *testing.T) {
}) })
} }
func TestAccComputeV2Instance_bootFromVolumeForceNew(t *testing.T) {
var instance1_1 servers.Server
var instance1_2 servers.Server
var testAccComputeV2Instance_bootFromVolumeForceNew_1 = fmt.Sprintf(`
resource "openstack_compute_instance_v2" "instance_1" {
name = "instance_1"
security_groups = ["default"]
block_device {
uuid = "%s"
source_type = "image"
volume_size = 5
boot_index = 0
destination_type = "volume"
delete_on_termination = true
}
}`,
os.Getenv("OS_IMAGE_ID"))
var testAccComputeV2Instance_bootFromVolumeForceNew_2 = fmt.Sprintf(`
resource "openstack_compute_instance_v2" "instance_1" {
name = "instance_1"
security_groups = ["default"]
block_device {
uuid = "%s"
source_type = "image"
volume_size = 4
boot_index = 0
destination_type = "volume"
delete_on_termination = true
}
}`,
os.Getenv("OS_IMAGE_ID"))
resource.Test(t, resource.TestCase{
PreCheck: func() { testAccPreCheck(t) },
Providers: testAccProviders,
CheckDestroy: testAccCheckComputeV2InstanceDestroy,
Steps: []resource.TestStep{
resource.TestStep{
Config: testAccComputeV2Instance_bootFromVolumeForceNew_1,
Check: resource.ComposeTestCheckFunc(
testAccCheckComputeV2InstanceExists(t, "openstack_compute_instance_v2.instance_1", &instance1_1),
),
},
resource.TestStep{
Config: testAccComputeV2Instance_bootFromVolumeForceNew_2,
Check: resource.ComposeTestCheckFunc(
testAccCheckComputeV2InstanceExists(t, "openstack_compute_instance_v2.instance_1", &instance1_2),
testAccCheckComputeV2InstanceInstanceIDsDoNotMatch(&instance1_1, &instance1_2),
),
},
},
})
}
// TODO: verify the personality really exists on the instance. // TODO: verify the personality really exists on the instance.
func TestAccComputeV2Instance_personality(t *testing.T) { func TestAccComputeV2Instance_personality(t *testing.T) {
var instance servers.Server var instance servers.Server

View File

@ -290,22 +290,26 @@ The `network` block supports:
The `block_device` block supports: The `block_device` block supports:
* `uuid` - (Required unless `source_type` is set to `"blank"` ) The UUID of the image, volume, or snapshot. * `uuid` - (Required unless `source_type` is set to `"blank"` ) The UUID of
the image, volume, or snapshot. Changing this creates a new server.
* `source_type` - (Required) The source type of the device. Must be one of * `source_type` - (Required) The source type of the device. Must be one of
"blank", "image", "volume", or "snapshot". "blank", "image", "volume", or "snapshot". Changing this creates a new
server.
* `volume_size` - The size of the volume to create (in gigabytes). Required * `volume_size` - The size of the volume to create (in gigabytes). Required
in the following combinations: source=image and destination=volume, in the following combinations: source=image and destination=volume,
source=blank and destination=local. source=blank and destination=local. Changing this creates a new server.
* `boot_index` - (Optional) The boot index of the volume. It defaults to 0. * `boot_index` - (Optional) The boot index of the volume. It defaults to 0.
Changing this creates a new server.
* `destination_type` - (Optional) The type that gets created. Possible values * `destination_type` - (Optional) The type that gets created. Possible values
are "volume" and "local". are "volume" and "local". Changing this creates a new server.
* `delete_on_termination` - (Optional) Delete the volume / block device upon * `delete_on_termination` - (Optional) Delete the volume / block device upon
termination of the instance. Defaults to false. termination of the instance. Defaults to false. Changing this creates a
new server.
The `volume` block supports: The `volume` block supports: