Import support for Storage Volumes

This commit is contained in:
tombuildsstuff 2017-04-07 10:36:04 +01:00
parent 41595582dc
commit 6d859479dd
3 changed files with 155 additions and 9 deletions

View File

@ -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,
},
},
})
}

View File

@ -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

View File

@ -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"]