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,
|
||||
Update: resourceOPCStorageVolumeUpdate,
|
||||
Delete: resourceOPCStorageVolumeDelete,
|
||||
Importer: &schema.ResourceImporter{
|
||||
State: schema.ImportStatePassthrough,
|
||||
},
|
||||
|
||||
Schema: map[string]*schema.Schema{
|
||||
"name": {
|
||||
|
@ -232,7 +235,7 @@ func resourceOPCStorageVolumeRead(d *schema.ResourceData, meta interface{}) erro
|
|||
|
||||
d.Set("name", result.Name)
|
||||
d.Set("description", result.Description)
|
||||
d.Set("storage", result.Properties[0])
|
||||
d.Set("storage_type", result.Properties[0])
|
||||
size, err := strconv.Atoi(result.Size)
|
||||
if err != nil {
|
||||
return err
|
||||
|
|
|
@ -160,6 +160,8 @@ func TestAccOPCStorageVolume_FromSnapshot(t *testing.T) {
|
|||
})
|
||||
}
|
||||
|
||||
// TODO: test Premium storage
|
||||
|
||||
func testAccCheckStorageVolumeExists(state *OPCResourceState) error {
|
||||
sv := state.Client.StorageVolumes()
|
||||
volumeName := state.Attributes["name"]
|
||||
|
|
Loading…
Reference in New Issue