From ead1fed89774e94b6c4152430bef59d7d27c34b4 Mon Sep 17 00:00:00 2001 From: Joe Topjian Date: Sat, 28 May 2016 22:40:36 +0000 Subject: [PATCH] provider/openstack: Enforce ForceNew on Instance Block Device This commit causes openstack_compute_instance_v2 resources to be destroyed and recreated upon changes to any block_device argument. --- .../resource_openstack_compute_instance_v2.go | 8 ++- ...urce_openstack_compute_instance_v2_test.go | 55 +++++++++++++++++++ .../r/compute_instance_v2.html.markdown | 14 +++-- 3 files changed, 71 insertions(+), 6 deletions(-) diff --git a/builtin/providers/openstack/resource_openstack_compute_instance_v2.go b/builtin/providers/openstack/resource_openstack_compute_instance_v2.go index 5fb2be254..57d346dc6 100644 --- a/builtin/providers/openstack/resource_openstack_compute_instance_v2.go +++ b/builtin/providers/openstack/resource_openstack_compute_instance_v2.go @@ -193,37 +193,43 @@ func resourceComputeInstanceV2() *schema.Resource { "block_device": &schema.Schema{ Type: schema.TypeList, Optional: true, - ForceNew: true, Elem: &schema.Resource{ Schema: map[string]*schema.Schema{ "source_type": &schema.Schema{ Type: schema.TypeString, Required: true, + ForceNew: true, }, "uuid": &schema.Schema{ Type: schema.TypeString, Optional: true, + ForceNew: true, }, "volume_size": &schema.Schema{ Type: schema.TypeInt, Optional: true, + ForceNew: true, }, "destination_type": &schema.Schema{ Type: schema.TypeString, Optional: true, + ForceNew: true, }, "boot_index": &schema.Schema{ Type: schema.TypeInt, Optional: true, + ForceNew: true, }, "delete_on_termination": &schema.Schema{ Type: schema.TypeBool, Optional: true, Default: false, + ForceNew: true, }, "guest_format": &schema.Schema{ Type: schema.TypeString, Optional: true, + ForceNew: true, }, }, }, diff --git a/builtin/providers/openstack/resource_openstack_compute_instance_v2_test.go b/builtin/providers/openstack/resource_openstack_compute_instance_v2_test.go index 0ba4817e5..fd08536a7 100644 --- a/builtin/providers/openstack/resource_openstack_compute_instance_v2_test.go +++ b/builtin/providers/openstack/resource_openstack_compute_instance_v2_test.go @@ -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. func TestAccComputeV2Instance_personality(t *testing.T) { var instance servers.Server diff --git a/website/source/docs/providers/openstack/r/compute_instance_v2.html.markdown b/website/source/docs/providers/openstack/r/compute_instance_v2.html.markdown index 9a25b75c8..af7783122 100644 --- a/website/source/docs/providers/openstack/r/compute_instance_v2.html.markdown +++ b/website/source/docs/providers/openstack/r/compute_instance_v2.html.markdown @@ -290,22 +290,26 @@ The `network` 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 - "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 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. + Changing this creates a new server. * `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 - termination of the instance. Defaults to false. + termination of the instance. Defaults to false. Changing this creates a + new server. The `volume` block supports: