provider/openstack: Convert block_device from TypeSet to TypeList

This change better reflects how block devices are passed to the Nova API
and allows for future enablement of block_device features. It also resolves
an interpolation bug.
This commit is contained in:
Joe Topjian 2015-12-12 18:51:21 +00:00
parent 0a73c2e629
commit 4716451617
2 changed files with 47 additions and 19 deletions

View File

@ -176,12 +176,7 @@ func resourceComputeInstanceV2() *schema.Resource {
ForceNew: true,
},
"block_device": &schema.Schema{
// TODO: This is a set because we don't support singleton
// sub-resources today. We'll enforce that the set only ever has
// length zero or one below. When TF gains support for
// sub-resources this can be converted.
// As referenced in resource_aws_instance.go
Type: schema.TypeSet,
Type: schema.TypeList,
Optional: true,
ForceNew: true,
Elem: &schema.Resource{
@ -213,10 +208,6 @@ func resourceComputeInstanceV2() *schema.Resource {
},
},
},
Set: func(v interface{}) int {
// there can only be one bootable block device; no need to hash anything
return 0
},
},
"volume": &schema.Schema{
Type: schema.TypeSet,
@ -352,9 +343,8 @@ func resourceComputeInstanceV2Create(d *schema.ResourceData, meta interface{}) e
}
}
if v, ok := d.GetOk("block_device"); ok {
vL := v.(*schema.Set).List()
for _, v := range vL {
if vL, ok := d.GetOk("block_device"); ok {
for _, v := range vL.([]interface{}) {
blockDeviceRaw := v.(map[string]interface{})
blockDevice := resourceInstanceBlockDeviceV2(d, blockDeviceRaw)
createOpts = &bootfromvolume.CreateOptsExt{
@ -1239,9 +1229,8 @@ func checkVolumeConfig(d *schema.ResourceData) error {
}
}
if v, ok := d.GetOk("block_device"); ok {
vL := v.(*schema.Set).List()
if len(vL) > 1 {
if vL, ok := d.GetOk("block_device"); ok {
if len(vL.([]interface{})) > 1 {
return fmt.Errorf("Can only specify one block device to boot from.")
}
}

View File

@ -253,9 +253,9 @@ func TestAccComputeV2Instance_multi_secgroups(t *testing.T) {
})
}
func TestAccComputeV2Instance_bootFromVolume(t *testing.T) {
func TestAccComputeV2Instance_bootFromVolumeImage(t *testing.T) {
var instance servers.Server
var testAccComputeV2Instance_bootFromVolume = fmt.Sprintf(`
var testAccComputeV2Instance_bootFromVolumeImage = fmt.Sprintf(`
resource "openstack_compute_instance_v2" "foo" {
name = "terraform-test"
security_groups = ["default"]
@ -276,7 +276,46 @@ func TestAccComputeV2Instance_bootFromVolume(t *testing.T) {
CheckDestroy: testAccCheckComputeV2InstanceDestroy,
Steps: []resource.TestStep{
resource.TestStep{
Config: testAccComputeV2Instance_bootFromVolume,
Config: testAccComputeV2Instance_bootFromVolumeImage,
Check: resource.ComposeTestCheckFunc(
testAccCheckComputeV2InstanceExists(t, "openstack_compute_instance_v2.foo", &instance),
testAccCheckComputeV2InstanceBootVolumeAttachment(&instance),
),
},
},
})
}
func TestAccComputeV2Instance_bootFromVolumeVolume(t *testing.T) {
var instance servers.Server
var testAccComputeV2Instance_bootFromVolumeVolume = fmt.Sprintf(`
resource "openstack_blockstorage_volume_v1" "foo" {
name = "terraform-test"
size = 5
image_id = "%s"
}
resource "openstack_compute_instance_v2" "foo" {
name = "terraform-test"
security_groups = ["default"]
block_device {
uuid = "${openstack_blockstorage_volume_v1.foo.id}"
source_type = "volume"
volume_size = 5
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_bootFromVolumeVolume,
Check: resource.ComposeTestCheckFunc(
testAccCheckComputeV2InstanceExists(t, "openstack_compute_instance_v2.foo", &instance),
testAccCheckComputeV2InstanceBootVolumeAttachment(&instance),