mirror of
https://github.com/opentofu/opentofu.git
synced 2025-02-25 18:45:20 -06:00
provider/openstack: Support Import of OpenStack Block Storage Volumes (#7347)
This commit is contained in:
parent
69f3fb803a
commit
8b80d05103
@ -0,0 +1,29 @@
|
|||||||
|
package openstack
|
||||||
|
|
||||||
|
import (
|
||||||
|
"testing"
|
||||||
|
|
||||||
|
"github.com/hashicorp/terraform/helper/resource"
|
||||||
|
)
|
||||||
|
|
||||||
|
func TestAccOpenStackBlockStorageV1Volume_importBasic(t *testing.T) {
|
||||||
|
resourceName := "openstack_blockstorage_volume_v1.volume_1"
|
||||||
|
|
||||||
|
resource.Test(t, resource.TestCase{
|
||||||
|
PreCheck: func() { testAccPreCheck(t) },
|
||||||
|
Providers: testAccProviders,
|
||||||
|
CheckDestroy: testAccCheckBlockStorageV1VolumeDestroy,
|
||||||
|
Steps: []resource.TestStep{
|
||||||
|
resource.TestStep{
|
||||||
|
Config: testAccBlockStorageV1Volume_basic,
|
||||||
|
},
|
||||||
|
|
||||||
|
resource.TestStep{
|
||||||
|
ResourceName: resourceName,
|
||||||
|
ImportState: true,
|
||||||
|
ImportStateVerify: true,
|
||||||
|
ImportStateVerifyIgnore: []string{"region"},
|
||||||
|
},
|
||||||
|
},
|
||||||
|
})
|
||||||
|
}
|
@ -0,0 +1,29 @@
|
|||||||
|
package openstack
|
||||||
|
|
||||||
|
import (
|
||||||
|
"testing"
|
||||||
|
|
||||||
|
"github.com/hashicorp/terraform/helper/resource"
|
||||||
|
)
|
||||||
|
|
||||||
|
func TestAccOpenStackBlockStorageV2Volume_importBasic(t *testing.T) {
|
||||||
|
resourceName := "openstack_blockstorage_volume_v2.volume_1"
|
||||||
|
|
||||||
|
resource.Test(t, resource.TestCase{
|
||||||
|
PreCheck: func() { testAccPreCheck(t) },
|
||||||
|
Providers: testAccProviders,
|
||||||
|
CheckDestroy: testAccCheckBlockStorageV2VolumeDestroy,
|
||||||
|
Steps: []resource.TestStep{
|
||||||
|
resource.TestStep{
|
||||||
|
Config: testAccBlockStorageV2Volume_basic,
|
||||||
|
},
|
||||||
|
|
||||||
|
resource.TestStep{
|
||||||
|
ResourceName: resourceName,
|
||||||
|
ImportState: true,
|
||||||
|
ImportStateVerify: true,
|
||||||
|
ImportStateVerifyIgnore: []string{"region"},
|
||||||
|
},
|
||||||
|
},
|
||||||
|
})
|
||||||
|
}
|
@ -20,6 +20,9 @@ func resourceBlockStorageVolumeV1() *schema.Resource {
|
|||||||
Read: resourceBlockStorageVolumeV1Read,
|
Read: resourceBlockStorageVolumeV1Read,
|
||||||
Update: resourceBlockStorageVolumeV1Update,
|
Update: resourceBlockStorageVolumeV1Update,
|
||||||
Delete: resourceBlockStorageVolumeV1Delete,
|
Delete: resourceBlockStorageVolumeV1Delete,
|
||||||
|
Importer: &schema.ResourceImporter{
|
||||||
|
State: schema.ImportStatePassthrough,
|
||||||
|
},
|
||||||
|
|
||||||
Schema: map[string]*schema.Schema{
|
Schema: map[string]*schema.Schema{
|
||||||
"region": &schema.Schema{
|
"region": &schema.Schema{
|
||||||
@ -177,17 +180,15 @@ func resourceBlockStorageVolumeV1Read(d *schema.ResourceData, meta interface{})
|
|||||||
d.Set("volume_type", v.VolumeType)
|
d.Set("volume_type", v.VolumeType)
|
||||||
d.Set("metadata", v.Metadata)
|
d.Set("metadata", v.Metadata)
|
||||||
|
|
||||||
if len(v.Attachments) > 0 {
|
attachments := make([]map[string]interface{}, len(v.Attachments))
|
||||||
attachments := make([]map[string]interface{}, len(v.Attachments))
|
for i, attachment := range v.Attachments {
|
||||||
for i, attachment := range v.Attachments {
|
attachments[i] = make(map[string]interface{})
|
||||||
attachments[i] = make(map[string]interface{})
|
attachments[i]["id"] = attachment["id"]
|
||||||
attachments[i]["id"] = attachment["id"]
|
attachments[i]["instance_id"] = attachment["server_id"]
|
||||||
attachments[i]["instance_id"] = attachment["server_id"]
|
attachments[i]["device"] = attachment["device"]
|
||||||
attachments[i]["device"] = attachment["device"]
|
log.Printf("[DEBUG] attachment: %v", attachment)
|
||||||
log.Printf("[DEBUG] attachment: %v", attachment)
|
|
||||||
}
|
|
||||||
d.Set("attachment", attachments)
|
|
||||||
}
|
}
|
||||||
|
d.Set("attachment", attachments)
|
||||||
|
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
@ -156,24 +156,20 @@ func testAccCheckBlockStorageV1VolumeMetadata(
|
|||||||
|
|
||||||
var testAccBlockStorageV1Volume_basic = fmt.Sprintf(`
|
var testAccBlockStorageV1Volume_basic = fmt.Sprintf(`
|
||||||
resource "openstack_blockstorage_volume_v1" "volume_1" {
|
resource "openstack_blockstorage_volume_v1" "volume_1" {
|
||||||
region = "%s"
|
|
||||||
name = "tf-test-volume"
|
name = "tf-test-volume"
|
||||||
description = "first test volume"
|
description = "first test volume"
|
||||||
metadata{
|
metadata{
|
||||||
foo = "bar"
|
foo = "bar"
|
||||||
}
|
}
|
||||||
size = 1
|
size = 1
|
||||||
}`,
|
}`)
|
||||||
OS_REGION_NAME)
|
|
||||||
|
|
||||||
var testAccBlockStorageV1Volume_update = fmt.Sprintf(`
|
var testAccBlockStorageV1Volume_update = fmt.Sprintf(`
|
||||||
resource "openstack_blockstorage_volume_v1" "volume_1" {
|
resource "openstack_blockstorage_volume_v1" "volume_1" {
|
||||||
region = "%s"
|
|
||||||
name = "tf-test-volume-updated"
|
name = "tf-test-volume-updated"
|
||||||
description = "first test volume"
|
description = "first test volume"
|
||||||
metadata{
|
metadata{
|
||||||
foo = "bar"
|
foo = "bar"
|
||||||
}
|
}
|
||||||
size = 1
|
size = 1
|
||||||
}`,
|
}`)
|
||||||
OS_REGION_NAME)
|
|
||||||
|
@ -20,6 +20,9 @@ func resourceBlockStorageVolumeV2() *schema.Resource {
|
|||||||
Read: resourceBlockStorageVolumeV2Read,
|
Read: resourceBlockStorageVolumeV2Read,
|
||||||
Update: resourceBlockStorageVolumeV2Update,
|
Update: resourceBlockStorageVolumeV2Update,
|
||||||
Delete: resourceBlockStorageVolumeV2Delete,
|
Delete: resourceBlockStorageVolumeV2Delete,
|
||||||
|
Importer: &schema.ResourceImporter{
|
||||||
|
State: schema.ImportStatePassthrough,
|
||||||
|
},
|
||||||
|
|
||||||
Schema: map[string]*schema.Schema{
|
Schema: map[string]*schema.Schema{
|
||||||
"region": &schema.Schema{
|
"region": &schema.Schema{
|
||||||
@ -189,17 +192,15 @@ func resourceBlockStorageVolumeV2Read(d *schema.ResourceData, meta interface{})
|
|||||||
d.Set("volume_type", v.VolumeType)
|
d.Set("volume_type", v.VolumeType)
|
||||||
d.Set("metadata", v.Metadata)
|
d.Set("metadata", v.Metadata)
|
||||||
|
|
||||||
if len(v.Attachments) > 0 {
|
attachments := make([]map[string]interface{}, len(v.Attachments))
|
||||||
attachments := make([]map[string]interface{}, len(v.Attachments))
|
for i, attachment := range v.Attachments {
|
||||||
for i, attachment := range v.Attachments {
|
attachments[i] = make(map[string]interface{})
|
||||||
attachments[i] = make(map[string]interface{})
|
attachments[i]["id"] = attachment["id"]
|
||||||
attachments[i]["id"] = attachment["id"]
|
attachments[i]["instance_id"] = attachment["server_id"]
|
||||||
attachments[i]["instance_id"] = attachment["server_id"]
|
attachments[i]["device"] = attachment["device"]
|
||||||
attachments[i]["device"] = attachment["device"]
|
log.Printf("[DEBUG] attachment: %v", attachment)
|
||||||
log.Printf("[DEBUG] attachment: %v", attachment)
|
|
||||||
}
|
|
||||||
d.Set("attachment", attachments)
|
|
||||||
}
|
}
|
||||||
|
d.Set("attachment", attachments)
|
||||||
|
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
@ -15,26 +15,6 @@ import (
|
|||||||
func TestAccBlockStorageV2Volume_basic(t *testing.T) {
|
func TestAccBlockStorageV2Volume_basic(t *testing.T) {
|
||||||
var volume volumes.Volume
|
var volume volumes.Volume
|
||||||
|
|
||||||
var testAccBlockStorageV2Volume_basic = fmt.Sprintf(`
|
|
||||||
resource "openstack_blockstorage_volume_v2" "volume_1" {
|
|
||||||
name = "volume_1"
|
|
||||||
description = "first test volume"
|
|
||||||
metadata {
|
|
||||||
foo = "bar"
|
|
||||||
}
|
|
||||||
size = 1
|
|
||||||
}`)
|
|
||||||
|
|
||||||
var testAccBlockStorageV2Volume_update = fmt.Sprintf(`
|
|
||||||
resource "openstack_blockstorage_volume_v2" "volume_1" {
|
|
||||||
name = "volume_1-updated"
|
|
||||||
description = "first test volume"
|
|
||||||
metadata {
|
|
||||||
foo = "bar"
|
|
||||||
}
|
|
||||||
size = 1
|
|
||||||
}`)
|
|
||||||
|
|
||||||
resource.Test(t, resource.TestCase{
|
resource.Test(t, resource.TestCase{
|
||||||
PreCheck: func() { testAccPreCheck(t) },
|
PreCheck: func() { testAccPreCheck(t) },
|
||||||
Providers: testAccProviders,
|
Providers: testAccProviders,
|
||||||
@ -186,3 +166,23 @@ func testAccCheckBlockStorageV2VolumeMetadata(
|
|||||||
return fmt.Errorf("Metadata not found: %s", k)
|
return fmt.Errorf("Metadata not found: %s", k)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
var testAccBlockStorageV2Volume_basic = fmt.Sprintf(`
|
||||||
|
resource "openstack_blockstorage_volume_v2" "volume_1" {
|
||||||
|
name = "volume_1"
|
||||||
|
description = "first test volume"
|
||||||
|
metadata {
|
||||||
|
foo = "bar"
|
||||||
|
}
|
||||||
|
size = 1
|
||||||
|
}`)
|
||||||
|
|
||||||
|
var testAccBlockStorageV2Volume_update = fmt.Sprintf(`
|
||||||
|
resource "openstack_blockstorage_volume_v2" "volume_1" {
|
||||||
|
name = "volume_1-updated"
|
||||||
|
description = "first test volume"
|
||||||
|
metadata {
|
||||||
|
foo = "bar"
|
||||||
|
}
|
||||||
|
size = 1
|
||||||
|
}`)
|
||||||
|
Loading…
Reference in New Issue
Block a user