From 3bd582b3d5798d5441043a729d634f4bd80ae8ed Mon Sep 17 00:00:00 2001 From: Jake Champlin Date: Thu, 6 Apr 2017 12:29:13 -0400 Subject: [PATCH] Add fixes from comments - Adds docs to sidebar - Changes `volume` to `volume_name` in volume snapshot - Fixes tests - Changes `parent_volume_bootable` to boolean, and converts to string for API ``` $ make testacc TEST=./builtin/providers/opc TESTARGS="-run=TestAccOPCStorageVolumeSnapshot_basic" ==> Checking that code complies with gofmt requirements... go generate $(go list ./... | grep -v /terraform/vendor/) 2017/04/06 12:26:59 Generated command/internal_plugin_list.go TF_ACC=1 go test ./builtin/providers/opc -v -run=TestAccOPCStorageVolumeSnapshot_basic -timeout 120m === RUN TestAccOPCStorageVolumeSnapshot_basic --- PASS: TestAccOPCStorageVolumeSnapshot_basic (24.45s) PASS ok github.com/hashicorp/terraform/builtin/providers/opc 24.476s ``` --- .../opc/resource_storage_volume_snapshot.go | 24 ++++++++++++------- .../resource_storage_volume_snapshot_test.go | 2 +- .../opc/resource_storage_volume_test.go | 8 +++---- ...pute_storage_volume_snapshot.html.markdown | 3 ++- website/source/layouts/opc.erb | 3 +++ 5 files changed, 26 insertions(+), 14 deletions(-) diff --git a/builtin/providers/opc/resource_storage_volume_snapshot.go b/builtin/providers/opc/resource_storage_volume_snapshot.go index 629dc2f3c..5fb0d9847 100644 --- a/builtin/providers/opc/resource_storage_volume_snapshot.go +++ b/builtin/providers/opc/resource_storage_volume_snapshot.go @@ -2,6 +2,7 @@ package opc import ( "fmt" + "strconv" "github.com/hashicorp/go-oracle-terraform/compute" "github.com/hashicorp/terraform/helper/schema" @@ -18,7 +19,7 @@ func resourceOPCStorageVolumeSnapshot() *schema.Resource { Schema: map[string]*schema.Schema{ // Required Attributes - "volume": { + "volume_name": { Type: schema.TypeString, Required: true, ForceNew: true, @@ -40,10 +41,10 @@ func resourceOPCStorageVolumeSnapshot() *schema.Resource { }, "parent_volume_bootable": { - Type: schema.TypeString, + Type: schema.TypeBool, Optional: true, ForceNew: true, - Default: "false", + Default: false, }, "collocated": { @@ -124,7 +125,7 @@ func resourceOPCStorageVolumeSnapshotCreate(d *schema.ResourceData, meta interfa // Get required attribute input := &compute.CreateStorageVolumeSnapshotInput{ - Volume: d.Get("volume").(string), + Volume: d.Get("volume_name").(string), } if v, ok := d.GetOk("description"); ok { @@ -135,8 +136,10 @@ func resourceOPCStorageVolumeSnapshotCreate(d *schema.ResourceData, meta interfa input.Name = v.(string) } - if v, ok := d.GetOk("parent_volume_bootable"); ok { - input.ParentVolumeBootable = v.(string) + // Convert parent_volume_bootable to string + bootable := d.Get("parent_volume_bootable").(bool) + if bootable { + input.ParentVolumeBootable = "true" } collocated := d.Get("collocated").(bool) @@ -180,10 +183,9 @@ func resourceOPCStorageVolumeSnapshotRead(d *schema.ResourceData, meta interface return nil } - d.Set("volume", result.Volume) + d.Set("volume_name", result.Volume) d.Set("description", result.Description) d.Set("name", result.Name) - d.Set("parent_volume_bootable", result.ParentVolumeBootable) d.Set("property", result.Property) d.Set("platform", result.Platform) d.Set("account", result.Account) @@ -197,6 +199,12 @@ func resourceOPCStorageVolumeSnapshotRead(d *schema.ResourceData, meta interface d.Set("status_timestamp", result.StatusTimestamp) d.Set("uri", result.URI) + bootable, err := strconv.ParseBool(result.ParentVolumeBootable) + if err != nil { + return fmt.Errorf("Error converting parent volume to boolean: %v", err) + } + d.Set("parent_volume_bootable", bootable) + if result.Property != compute.SnapshotPropertyCollocated { d.Set("collocated", false) } else { diff --git a/builtin/providers/opc/resource_storage_volume_snapshot_test.go b/builtin/providers/opc/resource_storage_volume_snapshot_test.go index 9d0c40798..9d4b08ee0 100644 --- a/builtin/providers/opc/resource_storage_volume_snapshot_test.go +++ b/builtin/providers/opc/resource_storage_volume_snapshot_test.go @@ -82,7 +82,7 @@ resource "opc_compute_storage_volume_snapshot" "test" { name = "test-acc-stor-vol-%d" description = "storage volume snapshot" collocated = true - volume = "${opc_compute_storage_volume.foo.name}" + volume_name = "${opc_compute_storage_volume.foo.name}" } `, rInt, rInt) } diff --git a/builtin/providers/opc/resource_storage_volume_test.go b/builtin/providers/opc/resource_storage_volume_test.go index 0c6ec0d90..fc157ef94 100644 --- a/builtin/providers/opc/resource_storage_volume_test.go +++ b/builtin/providers/opc/resource_storage_volume_test.go @@ -238,10 +238,10 @@ resource "opc_compute_storage_volume" "foo" { } resource "opc_compute_storage_volume_snapshot" "foo" { - description = "testing-acc" - name = "test-acc-stor-snapshot-%d" - collocated = true - volume = "${opc_compute_storage_volume.foo.name}" + description = "testing-acc" + name = "test-acc-stor-snapshot-%d" + collocated = true + volume_name = "${opc_compute_storage_volume.foo.name}" } // Create storage volume from snapshot diff --git a/website/source/docs/providers/opc/r/opc_compute_storage_volume_snapshot.html.markdown b/website/source/docs/providers/opc/r/opc_compute_storage_volume_snapshot.html.markdown index f7ba88e06..13ba265a5 100644 --- a/website/source/docs/providers/opc/r/opc_compute_storage_volume_snapshot.html.markdown +++ b/website/source/docs/providers/opc/r/opc_compute_storage_volume_snapshot.html.markdown @@ -18,6 +18,7 @@ resource "opc_compute_storage_volume_snapshot" "test" { description = "Description for the Storage Volume" tags = ["bar", "foo"] collocated = true + volume_name = "${opc_compute_storage_volume.foo.name}" } ``` @@ -25,7 +26,7 @@ resource "opc_compute_storage_volume_snapshot" "test" { The following arguments are supported: -* `volume` (Required) The name of the storage volume to create the snapshot from. +* `volume_name` (Required) The name of the storage volume to create the snapshot from. * `description` (Optional) The description of the storage volume snapshot. * `name` (Optional) The name of the storage volume snapshot. Will be generated if unspecified. * `parent_volume_bootable` (Optional) A string value of whether or not the parent volume is 'bootable' or not. Defaults to `"false"`. diff --git a/website/source/layouts/opc.erb b/website/source/layouts/opc.erb index f27a27e8b..0bc3e3ab4 100644 --- a/website/source/layouts/opc.erb +++ b/website/source/layouts/opc.erb @@ -85,6 +85,9 @@ > opc_compute_storage_volume + > + opc_compute_storage_volume_snapshot + > opc_compute_vnic_set