Import support for Storage Volumes
This commit is contained in:
parent
41595582dc
commit
6d859479dd
|
@ -0,0 +1,141 @@
|
||||||
|
package opc
|
||||||
|
|
||||||
|
import (
|
||||||
|
"testing"
|
||||||
|
|
||||||
|
"fmt"
|
||||||
|
"github.com/hashicorp/terraform/helper/acctest"
|
||||||
|
"github.com/hashicorp/terraform/helper/resource"
|
||||||
|
)
|
||||||
|
|
||||||
|
func TestAccOPCStorageVolume_importBasic(t *testing.T) {
|
||||||
|
resourceName := "opc_compute_storage_volume.test"
|
||||||
|
rInt := acctest.RandInt()
|
||||||
|
config := fmt.Sprintf(testAccStorageVolumeBasic, rInt)
|
||||||
|
|
||||||
|
resource.Test(t, resource.TestCase{
|
||||||
|
PreCheck: func() { testAccPreCheck(t) },
|
||||||
|
Providers: testAccProviders,
|
||||||
|
CheckDestroy: opcResourceCheck(resourceName, testAccCheckStorageVolumeDestroyed),
|
||||||
|
Steps: []resource.TestStep{
|
||||||
|
{
|
||||||
|
Config: config,
|
||||||
|
},
|
||||||
|
{
|
||||||
|
ResourceName: resourceName,
|
||||||
|
ImportState: true,
|
||||||
|
ImportStateVerify: true,
|
||||||
|
},
|
||||||
|
},
|
||||||
|
})
|
||||||
|
}
|
||||||
|
|
||||||
|
func TestAccOPCStorageVolume_importComplete(t *testing.T) {
|
||||||
|
resourceName := "opc_compute_storage_volume.test"
|
||||||
|
rInt := acctest.RandInt()
|
||||||
|
config := fmt.Sprintf(testAccStorageVolumeComplete, rInt)
|
||||||
|
|
||||||
|
resource.Test(t, resource.TestCase{
|
||||||
|
PreCheck: func() { testAccPreCheck(t) },
|
||||||
|
Providers: testAccProviders,
|
||||||
|
CheckDestroy: opcResourceCheck(resourceName, testAccCheckStorageVolumeDestroyed),
|
||||||
|
Steps: []resource.TestStep{
|
||||||
|
{
|
||||||
|
Config: config,
|
||||||
|
},
|
||||||
|
{
|
||||||
|
ResourceName: resourceName,
|
||||||
|
ImportState: true,
|
||||||
|
ImportStateVerify: true,
|
||||||
|
},
|
||||||
|
},
|
||||||
|
})
|
||||||
|
}
|
||||||
|
|
||||||
|
func TestAccOPCStorageVolume_importMaxSize(t *testing.T) {
|
||||||
|
resourceName := "opc_compute_storage_volume.test"
|
||||||
|
rInt := acctest.RandInt()
|
||||||
|
config := fmt.Sprintf(testAccStorageVolumeBasicMaxSize, rInt)
|
||||||
|
|
||||||
|
resource.Test(t, resource.TestCase{
|
||||||
|
PreCheck: func() { testAccPreCheck(t) },
|
||||||
|
Providers: testAccProviders,
|
||||||
|
CheckDestroy: opcResourceCheck(resourceName, testAccCheckStorageVolumeDestroyed),
|
||||||
|
Steps: []resource.TestStep{
|
||||||
|
{
|
||||||
|
Config: config,
|
||||||
|
},
|
||||||
|
{
|
||||||
|
ResourceName: resourceName,
|
||||||
|
ImportState: true,
|
||||||
|
ImportStateVerify: true,
|
||||||
|
},
|
||||||
|
},
|
||||||
|
})
|
||||||
|
}
|
||||||
|
|
||||||
|
func TestAccOPCStorageVolume_importBootable(t *testing.T) {
|
||||||
|
resourceName := "opc_compute_storage_volume.test"
|
||||||
|
rInt := acctest.RandInt()
|
||||||
|
config := fmt.Sprintf(testAccStorageVolumeBootable, rInt, rInt)
|
||||||
|
|
||||||
|
resource.Test(t, resource.TestCase{
|
||||||
|
PreCheck: func() { testAccPreCheck(t) },
|
||||||
|
Providers: testAccProviders,
|
||||||
|
CheckDestroy: opcResourceCheck(resourceName, testAccCheckStorageVolumeDestroyed),
|
||||||
|
Steps: []resource.TestStep{
|
||||||
|
{
|
||||||
|
Config: config,
|
||||||
|
},
|
||||||
|
{
|
||||||
|
ResourceName: resourceName,
|
||||||
|
ImportState: true,
|
||||||
|
ImportStateVerify: true,
|
||||||
|
},
|
||||||
|
},
|
||||||
|
})
|
||||||
|
}
|
||||||
|
|
||||||
|
func TestAccOPCStorageVolume_importImageListEntry(t *testing.T) {
|
||||||
|
resourceName := "opc_compute_storage_volume.test"
|
||||||
|
rInt := acctest.RandInt()
|
||||||
|
config := fmt.Sprintf(testAccStorageVolumeBootable, rInt, rInt)
|
||||||
|
|
||||||
|
resource.Test(t, resource.TestCase{
|
||||||
|
PreCheck: func() { testAccPreCheck(t) },
|
||||||
|
Providers: testAccProviders,
|
||||||
|
CheckDestroy: opcResourceCheck(resourceName, testAccCheckStorageVolumeDestroyed),
|
||||||
|
Steps: []resource.TestStep{
|
||||||
|
{
|
||||||
|
Config: config,
|
||||||
|
},
|
||||||
|
{
|
||||||
|
ResourceName: resourceName,
|
||||||
|
ImportState: true,
|
||||||
|
ImportStateVerify: true,
|
||||||
|
},
|
||||||
|
},
|
||||||
|
})
|
||||||
|
}
|
||||||
|
|
||||||
|
func TestAccOPCStorageVolume_importFromSnapshot(t *testing.T) {
|
||||||
|
resourceName := "opc_compute_storage_volume.test"
|
||||||
|
rInt := acctest.RandInt()
|
||||||
|
config := testAccStorageVolumeFromSnapshot(rInt)
|
||||||
|
|
||||||
|
resource.Test(t, resource.TestCase{
|
||||||
|
PreCheck: func() { testAccPreCheck(t) },
|
||||||
|
Providers: testAccProviders,
|
||||||
|
CheckDestroy: opcResourceCheck(resourceName, testAccCheckStorageVolumeDestroyed),
|
||||||
|
Steps: []resource.TestStep{
|
||||||
|
{
|
||||||
|
Config: config,
|
||||||
|
},
|
||||||
|
{
|
||||||
|
ResourceName: resourceName,
|
||||||
|
ImportState: true,
|
||||||
|
ImportStateVerify: true,
|
||||||
|
},
|
||||||
|
},
|
||||||
|
})
|
||||||
|
}
|
|
@ -15,6 +15,9 @@ func resourceOPCStorageVolume() *schema.Resource {
|
||||||
Read: resourceOPCStorageVolumeRead,
|
Read: resourceOPCStorageVolumeRead,
|
||||||
Update: resourceOPCStorageVolumeUpdate,
|
Update: resourceOPCStorageVolumeUpdate,
|
||||||
Delete: resourceOPCStorageVolumeDelete,
|
Delete: resourceOPCStorageVolumeDelete,
|
||||||
|
Importer: &schema.ResourceImporter{
|
||||||
|
State: schema.ImportStatePassthrough,
|
||||||
|
},
|
||||||
|
|
||||||
Schema: map[string]*schema.Schema{
|
Schema: map[string]*schema.Schema{
|
||||||
"name": {
|
"name": {
|
||||||
|
@ -232,7 +235,7 @@ func resourceOPCStorageVolumeRead(d *schema.ResourceData, meta interface{}) erro
|
||||||
|
|
||||||
d.Set("name", result.Name)
|
d.Set("name", result.Name)
|
||||||
d.Set("description", result.Description)
|
d.Set("description", result.Description)
|
||||||
d.Set("storage", result.Properties[0])
|
d.Set("storage_type", result.Properties[0])
|
||||||
size, err := strconv.Atoi(result.Size)
|
size, err := strconv.Atoi(result.Size)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
|
|
|
@ -160,6 +160,8 @@ func TestAccOPCStorageVolume_FromSnapshot(t *testing.T) {
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// TODO: test Premium storage
|
||||||
|
|
||||||
func testAccCheckStorageVolumeExists(state *OPCResourceState) error {
|
func testAccCheckStorageVolumeExists(state *OPCResourceState) error {
|
||||||
sv := state.Client.StorageVolumes()
|
sv := state.Client.StorageVolumes()
|
||||||
volumeName := state.Attributes["name"]
|
volumeName := state.Attributes["name"]
|
||||||
|
@ -270,9 +272,9 @@ resource "opc_compute_storage_volume" "test" {
|
||||||
|
|
||||||
const testAccStorageVolumeBasicMaxSize = `
|
const testAccStorageVolumeBasicMaxSize = `
|
||||||
resource "opc_compute_storage_volume" "test" {
|
resource "opc_compute_storage_volume" "test" {
|
||||||
name = "test-acc-stor-vol-%d"
|
name = "test-acc-stor-vol-%d"
|
||||||
description = "Provider Acceptance Tests Storage Volume Max Size"
|
description = "Provider Acceptance Tests Storage Volume Max Size"
|
||||||
size = 2048
|
size = 2048
|
||||||
}
|
}
|
||||||
`
|
`
|
||||||
|
|
||||||
|
@ -280,23 +282,23 @@ func testAccStorageVolumeFromSnapshot(rInt int) string {
|
||||||
return fmt.Sprintf(`
|
return fmt.Sprintf(`
|
||||||
// Initial Storage Volume to create snapshot with
|
// Initial Storage Volume to create snapshot with
|
||||||
resource "opc_compute_storage_volume" "foo" {
|
resource "opc_compute_storage_volume" "foo" {
|
||||||
name = "test-acc-stor-vol-%d"
|
name = "test-acc-stor-vol-%d"
|
||||||
description = "Acc Test intermediary storage volume for snapshot"
|
description = "Acc Test intermediary storage volume for snapshot"
|
||||||
size = 5
|
size = 5
|
||||||
}
|
}
|
||||||
|
|
||||||
resource "opc_compute_storage_volume_snapshot" "foo" {
|
resource "opc_compute_storage_volume_snapshot" "foo" {
|
||||||
description = "testing-acc"
|
description = "testing-acc"
|
||||||
name = "test-acc-stor-snapshot-%d"
|
name = "test-acc-stor-snapshot-%d"
|
||||||
collocated = true
|
collocated = true
|
||||||
volume_name = "${opc_compute_storage_volume.foo.name}"
|
volume_name = "${opc_compute_storage_volume.foo.name}"
|
||||||
}
|
}
|
||||||
|
|
||||||
// Create storage volume from snapshot
|
// Create storage volume from snapshot
|
||||||
resource "opc_compute_storage_volume" "test" {
|
resource "opc_compute_storage_volume" "test" {
|
||||||
name = "test-acc-stor-vol-final-%d"
|
name = "test-acc-stor-vol-final-%d"
|
||||||
description = "storage volume from snapshot"
|
description = "storage volume from snapshot"
|
||||||
size = 5
|
size = 5
|
||||||
snapshot_id = "${opc_compute_storage_volume_snapshot.foo.snapshot_id}"
|
snapshot_id = "${opc_compute_storage_volume_snapshot.foo.snapshot_id}"
|
||||||
}`, rInt, rInt, rInt)
|
}`, rInt, rInt, rInt)
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue