Merge branch 'f-oracle-compute' into f-oracle-website
This commit is contained in:
commit
4129afd884
|
@ -0,0 +1,163 @@
|
|||
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_importLowLatency(t *testing.T) {
|
||||
resourceName := "opc_compute_storage_volume.test"
|
||||
rInt := acctest.RandInt()
|
||||
config := testAccStorageVolumeLowLatency(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": {
|
||||
|
@ -63,15 +66,15 @@ func resourceOPCStorageVolume() *schema.Resource {
|
|||
},
|
||||
|
||||
"bootable": {
|
||||
Type: schema.TypeList,
|
||||
Type: schema.TypeBool,
|
||||
Optional: true,
|
||||
Default: false,
|
||||
ForceNew: true,
|
||||
MaxItems: 1,
|
||||
Elem: &schema.Resource{
|
||||
Schema: map[string]*schema.Schema{
|
||||
},
|
||||
|
||||
"image_list": {
|
||||
Type: schema.TypeString,
|
||||
Required: true,
|
||||
Optional: true,
|
||||
ForceNew: true,
|
||||
},
|
||||
|
||||
|
@ -81,9 +84,6 @@ func resourceOPCStorageVolume() *schema.Resource {
|
|||
ForceNew: true,
|
||||
Default: -1,
|
||||
},
|
||||
},
|
||||
},
|
||||
},
|
||||
|
||||
"tags": tagsOptionalSchema(),
|
||||
|
||||
|
@ -139,25 +139,37 @@ func resourceOPCStorageVolumeCreate(d *schema.ResourceData, meta interface{}) er
|
|||
description := d.Get("description").(string)
|
||||
size := d.Get("size").(int)
|
||||
storageType := d.Get("storage_type").(string)
|
||||
bootable := d.Get("bootable").(bool)
|
||||
imageList := d.Get("image_list").(string)
|
||||
imageListEntry := d.Get("image_list_entry").(int)
|
||||
|
||||
if bootable == true {
|
||||
if imageList == "" {
|
||||
return fmt.Errorf("Error: A Bootable Volume must have an Image List!")
|
||||
}
|
||||
|
||||
if imageListEntry == -1 {
|
||||
return fmt.Errorf("Error: A Bootable Volume must have an Image List Entry!")
|
||||
}
|
||||
}
|
||||
|
||||
input := compute.CreateStorageVolumeInput{
|
||||
Name: name,
|
||||
Description: description,
|
||||
Size: strconv.Itoa(size),
|
||||
Properties: []string{storageType},
|
||||
Bootable: bootable,
|
||||
ImageList: imageList,
|
||||
ImageListEntry: imageListEntry,
|
||||
Tags: getStringList(d, "tags"),
|
||||
}
|
||||
|
||||
expandOPCStorageVolumeOptionalFields(d, &input)
|
||||
|
||||
if v, ok := d.GetOk("snapshot"); ok {
|
||||
input.Snapshot = v.(string)
|
||||
}
|
||||
|
||||
if v, ok := d.GetOk("snapshot_account"); ok {
|
||||
input.SnapshotAccount = v.(string)
|
||||
}
|
||||
|
||||
if v, ok := d.GetOk("snapshot_id"); ok {
|
||||
input.SnapshotID = v.(string)
|
||||
}
|
||||
|
@ -178,12 +190,16 @@ func resourceOPCStorageVolumeUpdate(d *schema.ResourceData, meta interface{}) er
|
|||
description := d.Get("description").(string)
|
||||
size := d.Get("size").(int)
|
||||
storageType := d.Get("storage_type").(string)
|
||||
imageList := d.Get("image_list").(string)
|
||||
imageListEntry := d.Get("image_list_entry").(int)
|
||||
|
||||
input := compute.UpdateStorageVolumeInput{
|
||||
Name: name,
|
||||
Description: description,
|
||||
Size: strconv.Itoa(size),
|
||||
Properties: []string{storageType},
|
||||
ImageList: imageList,
|
||||
ImageListEntry: imageListEntry,
|
||||
Tags: getStringList(d, "tags"),
|
||||
}
|
||||
_, err := client.UpdateStorageVolume(&input)
|
||||
|
@ -219,22 +235,24 @@ 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("snapshot", result.Snapshot)
|
||||
d.Set("snapshot_id", result.SnapshotID)
|
||||
d.Set("snapshot_account", result.SnapshotAccount)
|
||||
d.Set("storage_type", result.Properties[0])
|
||||
size, err := strconv.Atoi(result.Size)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
d.Set("size", size)
|
||||
d.Set("bootable", result.Bootable)
|
||||
d.Set("image_list", result.ImageList)
|
||||
d.Set("image_list_entry", result.ImageListEntry)
|
||||
|
||||
d.Set("snapshot", result.Snapshot)
|
||||
d.Set("snapshot_id", result.SnapshotID)
|
||||
d.Set("snapshot_account", result.SnapshotAccount)
|
||||
|
||||
if err := setStringList(d, "tags", result.Tags); err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
flattenOPCStorageVolumeOptionalFields(d, result)
|
||||
|
||||
flattenOPCStorageVolumeComputedFields(d, result)
|
||||
|
||||
return nil
|
||||
|
@ -255,24 +273,6 @@ func resourceOPCStorageVolumeDelete(d *schema.ResourceData, meta interface{}) er
|
|||
return nil
|
||||
}
|
||||
|
||||
func expandOPCStorageVolumeOptionalFields(d *schema.ResourceData, input *compute.CreateStorageVolumeInput) {
|
||||
bootValue, bootExists := d.GetOk("bootable")
|
||||
input.Bootable = bootExists
|
||||
if bootExists {
|
||||
configs := bootValue.([]interface{})
|
||||
config := configs[0].(map[string]interface{})
|
||||
|
||||
input.ImageList = config["image_list"].(string)
|
||||
input.ImageListEntry = config["image_list_entry"].(int)
|
||||
}
|
||||
}
|
||||
|
||||
func flattenOPCStorageVolumeOptionalFields(d *schema.ResourceData, result *compute.StorageVolumeInfo) {
|
||||
d.Set("bootable", result.Bootable)
|
||||
d.Set("image_list", result.ImageList)
|
||||
d.Set("image_list_entry", result.ImageListEntry)
|
||||
}
|
||||
|
||||
func flattenOPCStorageVolumeComputedFields(d *schema.ResourceData, result *compute.StorageVolumeInfo) {
|
||||
d.Set("hypervisor", result.Hypervisor)
|
||||
d.Set("machine_image", result.MachineImage)
|
||||
|
|
|
@ -116,14 +116,56 @@ func TestAccOPCStorageVolume_Bootable(t *testing.T) {
|
|||
})
|
||||
}
|
||||
|
||||
func TestAccOPCStorageVolume_FromSnapshot(t *testing.T) {
|
||||
func TestAccOPCStorageVolume_ImageListEntry(t *testing.T) {
|
||||
volumeResourceName := "opc_compute_storage_volume.test"
|
||||
rInt := acctest.RandInt()
|
||||
ri := acctest.RandInt()
|
||||
config := fmt.Sprintf(testAccStorageVolumeImageListEntry, ri, ri)
|
||||
|
||||
resource.Test(t, resource.TestCase{
|
||||
PreCheck: func() { testAccPreCheck(t) },
|
||||
Providers: testAccProviders,
|
||||
CheckDestroy: opcResourceCheck(volumeResourceName, testAccCheckStorageVolumeDestroyed),
|
||||
Steps: []resource.TestStep{
|
||||
{
|
||||
Config: config,
|
||||
Check: resource.ComposeTestCheckFunc(
|
||||
opcResourceCheck(volumeResourceName, testAccCheckStorageVolumeExists),
|
||||
),
|
||||
},
|
||||
},
|
||||
})
|
||||
}
|
||||
|
||||
func TestAccOPCStorageVolume_LowLatency(t *testing.T) {
|
||||
volumeResourceName := "opc_compute_storage_volume.test"
|
||||
rInt := acctest.RandInt()
|
||||
resource.Test(t, resource.TestCase{
|
||||
PreCheck: func() {
|
||||
testAccPreCheck(t)
|
||||
},
|
||||
Providers: testAccProviders,
|
||||
CheckDestroy: opcResourceCheck(volumeResourceName, testAccCheckStorageVolumeDestroyed),
|
||||
Steps: []resource.TestStep{
|
||||
{
|
||||
Config: testAccStorageVolumeLowLatency(rInt),
|
||||
Check: resource.ComposeTestCheckFunc(
|
||||
opcResourceCheck(volumeResourceName, testAccCheckStorageVolumeExists),
|
||||
resource.TestCheckResourceAttr(volumeResourceName, "storage_type", "/oracle/public/storage/latency"),
|
||||
),
|
||||
},
|
||||
},
|
||||
})
|
||||
}
|
||||
|
||||
func TestAccOPCStorageVolume_FromSnapshot(t *testing.T) {
|
||||
volumeResourceName := "opc_compute_storage_volume.test"
|
||||
rInt := acctest.RandInt()
|
||||
resource.Test(t, resource.TestCase{
|
||||
PreCheck: func() {
|
||||
testAccPreCheck(t)
|
||||
},
|
||||
Providers: testAccProviders,
|
||||
CheckDestroy: opcResourceCheck(volumeResourceName, testAccCheckStorageVolumeDestroyed),
|
||||
Steps: []resource.TestStep{
|
||||
{
|
||||
Config: testAccStorageVolumeFromSnapshot(rInt),
|
||||
|
@ -206,17 +248,44 @@ resource "opc_compute_storage_volume" "test" {
|
|||
const testAccStorageVolumeBootable = `
|
||||
resource "opc_compute_image_list" "test" {
|
||||
name = "test-acc-stor-vol-bootable-image-list-%d"
|
||||
description = "Provider Acceptance Tests Storage Volume"
|
||||
description = "Provider Acceptance Tests Storage Volume Bootable"
|
||||
}
|
||||
|
||||
resource "opc_compute_image_list_entry" "test" {
|
||||
name = "${opc_compute_image_list.test.name}"
|
||||
machine_images = [ "/oracle/public/oel_6.7_apaas_16.4.5_1610211300" ]
|
||||
version = 1
|
||||
}
|
||||
|
||||
resource "opc_compute_storage_volume" "test" {
|
||||
name = "test-acc-stor-vol-bootable-%d"
|
||||
description = "Provider Acceptance Tests Storage Volume"
|
||||
size = 2
|
||||
description = "Provider Acceptance Tests Storage Volume Bootable"
|
||||
size = 20
|
||||
tags = ["bar", "foo"]
|
||||
bootable {
|
||||
bootable = true
|
||||
image_list = "${opc_compute_image_list.test.name}"
|
||||
image_list_entry = "${opc_compute_image_list_entry.test.version}"
|
||||
}
|
||||
`
|
||||
|
||||
const testAccStorageVolumeImageListEntry = `
|
||||
resource "opc_compute_image_list" "test" {
|
||||
name = "test-acc-stor-vol-bootable-image-list-%d"
|
||||
description = "Provider Acceptance Tests Storage Volume Image List Entry"
|
||||
}
|
||||
|
||||
resource "opc_compute_image_list_entry" "test" {
|
||||
name = "${opc_compute_image_list.test.name}"
|
||||
machine_images = [ "/oracle/public/oel_6.7_apaas_16.4.5_1610211300" ]
|
||||
version = 1
|
||||
}
|
||||
|
||||
resource "opc_compute_storage_volume" "test" {
|
||||
name = "test-acc-stor-vol-bootable-%d"
|
||||
description = "Provider Acceptance Tests Storage Volume Image List Entry"
|
||||
size = 20
|
||||
tags = ["bar", "foo"]
|
||||
image_list_entry = "${opc_compute_image_list_entry.test.version}"
|
||||
}
|
||||
`
|
||||
|
||||
|
@ -250,6 +319,15 @@ resource "opc_compute_storage_volume" "test" {
|
|||
description = "storage volume from snapshot"
|
||||
size = 5
|
||||
snapshot_id = "${opc_compute_storage_volume_snapshot.foo.snapshot_id}"
|
||||
}`, rInt, rInt, rInt)
|
||||
}
|
||||
`, rInt, rInt, rInt)
|
||||
|
||||
func testAccStorageVolumeLowLatency(rInt int) string {
|
||||
return fmt.Sprintf(`
|
||||
resource "opc_compute_storage_volume" "test" {
|
||||
name = "test-acc-stor-vol-ll-%d"
|
||||
description = "Acc Test Storage Volume Low Latency"
|
||||
storage_type = "/oracle/public/storage/latency"
|
||||
size = 5
|
||||
}`, rInt)
|
||||
}
|
||||
|
|
|
@ -1978,14 +1978,14 @@
|
|||
{
|
||||
"checksumSHA1": "DzK7lYwHt5Isq5Zf73cnQqBO2LI=",
|
||||
"path": "github.com/hashicorp/go-oracle-terraform/helper",
|
||||
"revision": "98fdaf3c4bde245e21947487ba722c3d0abaccb2",
|
||||
"revisionTime": "2017-03-29T21:19:34Z"
|
||||
"revision": "5508daed82ecd55b71d45e8a149e99d24825e5bb",
|
||||
"revisionTime": "2017-04-06T17:51:51Z"
|
||||
},
|
||||
{
|
||||
"checksumSHA1": "AyNRs19Es9pDw2VMxVKWuLx3Afg=",
|
||||
"path": "github.com/hashicorp/go-oracle-terraform/opc",
|
||||
"revision": "98fdaf3c4bde245e21947487ba722c3d0abaccb2",
|
||||
"revisionTime": "2017-03-29T21:19:34Z"
|
||||
"revision": "5508daed82ecd55b71d45e8a149e99d24825e5bb",
|
||||
"revisionTime": "2017-04-06T17:51:51Z"
|
||||
},
|
||||
{
|
||||
"checksumSHA1": "b0nQutPMJHeUmz4SjpreotAo6Yk=",
|
||||
|
|
|
@ -30,14 +30,20 @@ resource "opc_compute_image_list" "test" {
|
|||
description = "Description for the Image List"
|
||||
}
|
||||
|
||||
resource "opc_compute_image_list_entry" "test" {
|
||||
name = "${opc_compute_image_list.test.name}"
|
||||
machine_images = [ "/oracle/public/oel_6.7_apaas_16.4.5_1610211300" ]
|
||||
version = 1
|
||||
}
|
||||
|
||||
resource "opc_compute_storage_volume" "test" {
|
||||
name = "storageVolume1"
|
||||
description = "Description for the Bootable Storage Volume"
|
||||
size = 30
|
||||
tags = ["first", "second"]
|
||||
bootable {
|
||||
bootable = true
|
||||
image_list = "${opc_compute_image_list.test.name}"
|
||||
}
|
||||
image_list_entry = "${opc_compute_image_list_entry.test.version}"
|
||||
}
|
||||
```
|
||||
|
||||
|
@ -49,15 +55,10 @@ The following arguments are supported:
|
|||
* `description` (Optional) The description of the storage volume.
|
||||
* `size` (Required) The size of this storage volume in GB. The allowed range is from 1 GB to 2 TB (2048 GB).
|
||||
* `storage_type` - (Optional) - The Type of Storage to provision. Possible values are `/oracle/public/storage/latency` or `/oracle/public/storage/default`. Defaults to `/oracle/public/storage/default`.
|
||||
* `bootable` - (Optional) A `bootable` block as defined below.
|
||||
* `bootable` - (Optional) Is the Volume Bootable? Defaults to `false`.
|
||||
* `image_list` - (Optional) Defines an image list. Required if `bootable` is set to `true`, optional if set to `false`.
|
||||
* `image_list_entry` - (Optional) Defines an image list entry. Required if `bootable` is set to `true`, optional if set to `false`.
|
||||
* `tags` - (Optional) Comma-separated strings that tag the storage volume.
|
||||
* `snapshot` - (Optional) Name of the storage volume snapshot if this storage volume is a clone.
|
||||
* `snapshot_account` - (Optional) Account of the parent snapshot from which the storage volume is restored.
|
||||
* `snapshot_id` - (Optional) Id of the parent snapshot from which the storage volume is restored or cloned.
|
||||
|
||||
`bootable` supports the following:
|
||||
* `image_list` - (Required) Defines an image list.
|
||||
* `image_list_entry` - (Optional) Defines an image list entry.
|
||||
|
||||
## Attributes Reference
|
||||
|
||||
|
|
Loading…
Reference in New Issue