From 2cda0cfdb77b1aea11e02f925e52690edcb91e37 Mon Sep 17 00:00:00 2001 From: dhirendersingh19 Date: Tue, 9 Jan 2024 13:20:22 +0530 Subject: [PATCH] Feedback resolved --- .../power/data_source_ibm_pi_volume_clone.go | 25 ++++---- .../data_source_ibm_pi_volume_clone_test.go | 4 +- ibm/service/power/ibm_pi_constants.go | 22 +++---- .../power/resource_ibm_pi_volume_clone.go | 57 ++++++++++--------- .../resource_ibm_pi_volume_clone_test.go | 14 +++-- website/docs/d/pi_volume_clone.html.markdown | 11 ++-- website/docs/r/pi_volume_clone.html.markdown | 22 +++---- 7 files changed, 81 insertions(+), 74 deletions(-) diff --git a/ibm/service/power/data_source_ibm_pi_volume_clone.go b/ibm/service/power/data_source_ibm_pi_volume_clone.go index fc44cb856b..87a9c5f12f 100644 --- a/ibm/service/power/data_source_ibm_pi_volume_clone.go +++ b/ibm/service/power/data_source_ibm_pi_volume_clone.go @@ -1,4 +1,4 @@ -// Copyright IBM Corp. 2023, 2024 All Rights Reserved. +// Copyright IBM Corp. 2024 All Rights Reserved. // Licensed under the Mozilla Public License v2.0 package power @@ -22,30 +22,31 @@ func DataSourceIBMPIVolumeClone() *schema.Resource { PIVolumeCloneTaskID: { Type: schema.TypeString, Required: true, - Description: "Clone task ID", + Description: "The ID of the volume clone task.", ValidateFunc: validation.NoZeroValues, }, - helpers.PICloudInstanceId: { + Arg_CloudInstanceID: { Type: schema.TypeString, Required: true, ValidateFunc: validation.NoZeroValues, + Description: "The GUID of the service instance associated with an account.", }, // Computed attributes "cloned_volumes": clonedVolumesSchema(), - "volume_clone_failure_reason": { + "failure_reason": { Type: schema.TypeString, Computed: true, - Description: "The reason the clone volumes task has failed", + Description: "The reason the clone volumes task has failed.", }, - "volume_clone_percent_complete": { + "percent_complete": { Type: schema.TypeInt, Computed: true, - Description: "Clone task completion percentage", + Description: "The completion percentage of the volume clone task.", }, - "volume_clone_status": { + "status": { Type: schema.TypeString, Computed: true, - Description: "Status of the clone volumes task", + Description: "The status of the volume clone task.", }, }, } @@ -66,11 +67,11 @@ func dataSourceIBMPIVolumeCloneRead(ctx context.Context, d *schema.ResourceData, d.SetId(d.Get(PIVolumeCloneTaskID).(string)) if volClone.Status != nil { - d.Set("volume_clone_status", *volClone.Status) + d.Set("status", *volClone.Status) } - d.Set("volume_clone_failure_reason", volClone.FailedReason) + d.Set("failure_reason", volClone.FailedReason) if volClone.PercentComplete != nil { - d.Set("volume_clone_percent_complete", *volClone.PercentComplete) + d.Set("percent_complete", *volClone.PercentComplete) } d.Set("cloned_volumes", flattenClonedVolumes(volClone.ClonedVolumes)) diff --git a/ibm/service/power/data_source_ibm_pi_volume_clone_test.go b/ibm/service/power/data_source_ibm_pi_volume_clone_test.go index 03de00a663..a8b8d805d4 100644 --- a/ibm/service/power/data_source_ibm_pi_volume_clone_test.go +++ b/ibm/service/power/data_source_ibm_pi_volume_clone_test.go @@ -1,4 +1,4 @@ -// Copyright IBM Corp. 2023, 2024 All Rights Reserved. +// Copyright IBM Corp. 2024 All Rights Reserved. // Licensed under the Mozilla Public License v2.0 package power_test @@ -21,7 +21,7 @@ func TestAccIBMPIVolumeClone_basic(t *testing.T) { Config: testAccCheckIBMPIVolumeCloneBasicConfig(), Check: resource.ComposeTestCheckFunc( resource.TestCheckResourceAttrSet("data.ibm_pi_volume_clone.testacc_ds_volume_clone", "id"), - resource.TestCheckResourceAttrSet("data.ibm_pi_volume_clone.testacc_ds_volume_clone", "volume_clone_status"), + resource.TestCheckResourceAttrSet("data.ibm_pi_volume_clone.testacc_ds_volume_clone", "status"), ), }, }, diff --git a/ibm/service/power/ibm_pi_constants.go b/ibm/service/power/ibm_pi_constants.go index 427273d497..b4f18b330c 100644 --- a/ibm/service/power/ibm_pi_constants.go +++ b/ibm/service/power/ibm_pi_constants.go @@ -145,16 +145,18 @@ const ( // status // common status states - StatusShutoff = "SHUTOFF" - StatusActive = "ACTIVE" - StatusResize = "RESIZE" - StatusError = "ERROR" - StatusBuild = "BUILD" - StatusPending = "PENDING" - SctionStart = "start" - SctionStop = "stop" - PIVolumeCloneCompleted = "completed" - PIVolumeCloneRunning = "running" + StatusShutoff = "SHUTOFF" + StatusActive = "ACTIVE" + StatusResize = "RESIZE" + StatusError = "ERROR" + StatusBuild = "BUILD" + StatusPending = "PENDING" + SctionStart = "start" + SctionStop = "stop" + + // volume clone task status + VolumeCloneCompleted = "completed" + VolumeCloneRunning = "running" // Workspaces Attr_WorkspaceCapabilities = "pi_workspace_capabilities" diff --git a/ibm/service/power/resource_ibm_pi_volume_clone.go b/ibm/service/power/resource_ibm_pi_volume_clone.go index 05a64f7d16..c874863c95 100644 --- a/ibm/service/power/resource_ibm_pi_volume_clone.go +++ b/ibm/service/power/resource_ibm_pi_volume_clone.go @@ -1,4 +1,4 @@ -// Copyright IBM Corp. 2023, 2024 All Rights Reserved. +// Copyright IBM Corp. 2024 All Rights Reserved. // Licensed under the Mozilla Public License v2.0 package power @@ -32,17 +32,17 @@ func ResourceIBMPIVolumeClone() *schema.Resource { }, Schema: map[string]*schema.Schema{ - helpers.PICloudInstanceId: { + Arg_CloudInstanceID: { Type: schema.TypeString, Required: true, ForceNew: true, - Description: "Cloud Instance ID - This is the service_instance_id.", + Description: "The GUID of the service instance associated with an account.", }, PIVolumeCloneName: { Type: schema.TypeString, Required: true, ForceNew: true, - Description: "Base name of the new cloned volume(s)", + Description: "The base name of the newly cloned volume(s).", }, PIVolumeIds: { Type: schema.TypeSet, @@ -50,42 +50,42 @@ func ResourceIBMPIVolumeClone() *schema.Resource { ForceNew: true, Elem: &schema.Schema{Type: schema.TypeString}, Set: schema.HashString, - Description: "List of volumes to be cloned", + Description: "List of volumes to be cloned.", }, PITargetStorageTier: { Type: schema.TypeString, Optional: true, ForceNew: true, - Description: "Target storage tier for the cloned volumes.", + Description: "The storage tier for the cloned volume(s).", }, helpers.PIReplicationEnabled: { Type: schema.TypeBool, Optional: true, ForceNew: true, - Description: "By default, cloned volume replication is determined by the source volume unless explicitly specified", + Description: "Indicates whether the cloned volume should have replication enabled. If no value is provided, it will default to the replication status of the source volume(s).", }, // Computed attributes - "volume_clone_task_id": { + "task_id": { Type: schema.TypeString, Computed: true, - Description: "Clone task ID", + Description: "The ID of the volume clone task.", }, "cloned_volumes": clonedVolumesSchema(), - "volume_clone_failure_reason": { + "failure_reason": { Type: schema.TypeString, Computed: true, - Description: "The reason the clone volumes task has failed", + Description: "The reason for the failure of the volume clone task.", }, - "volume_clone_percent_complete": { + "percent_complete": { Type: schema.TypeInt, Computed: true, - Description: "Clone task completion percentage", + Description: "The completion percentage of the volume clone task.", }, - "volume_clone_status": { + "status": { Type: schema.TypeString, Computed: true, - Description: "Status of the clone volumes task", + Description: "The status of the volume clone task.", }, }, } @@ -148,13 +148,13 @@ func resourceIBMPIVolumeCloneRead(ctx context.Context, d *schema.ResourceData, m return diag.FromErr(err) } - d.Set("volume_clone_task_id", vcTaskID) + d.Set("task_id", vcTaskID) if volCloneTask.Status != nil { - d.Set("volume_clone_status", *volCloneTask.Status) + d.Set("status", *volCloneTask.Status) } - d.Set("volume_clone_failure_reason", volCloneTask.FailedReason) + d.Set("failure_reason", volCloneTask.FailedReason) if volCloneTask.PercentComplete != nil { - d.Set("volume_clone_percent_complete", *volCloneTask.PercentComplete) + d.Set("percent_complete", *volCloneTask.PercentComplete) } d.Set("cloned_volumes", flattenClonedVolumes(volCloneTask.ClonedVolumes)) @@ -186,8 +186,8 @@ func isWaitForIBMPIVolumeCloneCompletion(ctx context.Context, client *st.IBMPICl log.Printf("Waiting for Volume clone (%s) to be completed.", id) stateConf := &resource.StateChangeConf{ - Pending: []string{PIVolumeCloneRunning}, - Target: []string{PIVolumeCloneCompleted}, + Pending: []string{VolumeCloneRunning}, + Target: []string{VolumeCloneCompleted}, Refresh: isIBMPIVolumeCloneRefreshFunc(client, id), Delay: 10 * time.Second, MinTimeout: 2 * time.Minute, @@ -204,29 +204,30 @@ func isIBMPIVolumeCloneRefreshFunc(client *st.IBMPICloneVolumeClient, id string) return nil, "", err } - if *volClone.Status == PIVolumeCloneCompleted { - return volClone, PIVolumeCloneCompleted, nil + if *volClone.Status == VolumeCloneCompleted { + return volClone, VolumeCloneCompleted, nil } - return volClone, PIVolumeCloneRunning, nil + return volClone, VolumeCloneRunning, nil } } func clonedVolumesSchema() *schema.Schema { return &schema.Schema{ - Type: schema.TypeList, - Computed: true, + Type: schema.TypeList, + Computed: true, + Description: "The List of cloned volumes.", Elem: &schema.Resource{ Schema: map[string]*schema.Schema{ "clone_volume_id": { Type: schema.TypeString, Computed: true, - Description: "ID of the new cloned volume", + Description: "The ID of the newly cloned volume.", }, "source_volume_id": { Type: schema.TypeString, Computed: true, - Description: "ID of the source volume to be cloned", + Description: "The ID of the source volume.", }, }, }, diff --git a/ibm/service/power/resource_ibm_pi_volume_clone_test.go b/ibm/service/power/resource_ibm_pi_volume_clone_test.go index f68c49d343..4a5da2446f 100644 --- a/ibm/service/power/resource_ibm_pi_volume_clone_test.go +++ b/ibm/service/power/resource_ibm_pi_volume_clone_test.go @@ -1,4 +1,4 @@ -// Copyright IBM Corp. 2023, 2024 All Rights Reserved. +// Copyright IBM Corp. 2024 All Rights Reserved. // Licensed under the Mozilla Public License v2.0 package power_test @@ -19,6 +19,7 @@ import ( ) func TestAccIBMPIVolumeClone(t *testing.T) { + resVolumeClone := "ibm_pi_volume_clone.power_volume_clone" name := fmt.Sprintf("tf-pi-volume-clone-%d", acctest.RandIntRange(10, 100)) resource.Test(t, resource.TestCase{ PreCheck: func() { acc.TestAccPreCheck(t) }, @@ -27,9 +28,12 @@ func TestAccIBMPIVolumeClone(t *testing.T) { { Config: testAccCheckIBMPIVolumeCloneConfig(name), Check: resource.ComposeTestCheckFunc( - testAccCheckIBMPIVolumeCloneExists("ibm_pi_volume_clone.power_volume_clone"), - resource.TestCheckResourceAttrSet("ibm_pi_volume_clone.power_volume_clone", "id"), - resource.TestCheckResourceAttrSet("ibm_pi_volume_clone.power_volume_clone", "volume_clone_status"), + testAccCheckIBMPIVolumeCloneExists(resVolumeClone), + resource.TestCheckResourceAttrSet(resVolumeClone, "id"), + resource.TestCheckResourceAttrSet(resVolumeClone, "status"), + resource.TestCheckResourceAttr(resVolumeClone, "status", "completed"), + resource.TestCheckResourceAttrSet(resVolumeClone, "percent_complete"), + resource.TestCheckResourceAttr(resVolumeClone, "percent_complete", "100"), ), }, }, @@ -74,7 +78,7 @@ func testAccCheckIBMPIVolumeCloneConfig(name string) string { resource "ibm_pi_volume_clone" "power_volume_clone" { pi_cloud_instance_id = "%[1]s" pi_volume_clone_name = "%[2]s" - pi_volume_ids = [ibm_pi_volume.power_volume[0].volume_id,ibm_pi_volume.power_volume[1].volume_id] + pi_volume_ids = ibm_pi_volume.power_volume.*.volume_id pi_target_storage_tier = "%[3]s" pi_replication_enabled = %[4]v } diff --git a/website/docs/d/pi_volume_clone.html.markdown b/website/docs/d/pi_volume_clone.html.markdown index 02d7ecb2ce..9c61c9b835 100644 --- a/website/docs/d/pi_volume_clone.html.markdown +++ b/website/docs/d/pi_volume_clone.html.markdown @@ -15,8 +15,8 @@ The following example retrieves information about the volume clone task that is ```terraform data "ibm_pi_volume_clone" "ds_volume_clone" { - pi_cloud_instance_id = "" - pi_volume_clone_task_id = "" + pi_cloud_instance_id = "" + pi_volume_clone_task_id = "" } ``` @@ -48,8 +48,7 @@ In addition to all argument reference list, you can access the following attribu Nested scheme for `cloned_volumes`: - `clone_volume_id` - (String) The ID of the newly cloned volume. - `source_volume_id` - (String) The ID of the source volume. +- `failure_reason` - (String) The reason for the failure of the clone volume task. - `id` - (String) The unique identifier of the volume clone task. -- `volume_clone_failure_reason` - (String) The reason for the failure of the clone volume task. -- `volume_clone_percent_complete` - (Integer) The completion percentage of the volume clone task. -- `volume_clone_status` - (String) The status of the volume clone task. -- `volume_clone_task_id` - (String) The ID of the volume clone task. +- `percent_complete` - (Integer) The completion percentage of the volume clone task. +- `status` - (String) The status of the volume clone task. diff --git a/website/docs/r/pi_volume_clone.html.markdown b/website/docs/r/pi_volume_clone.html.markdown index d6f78997a9..bf25d45455 100644 --- a/website/docs/r/pi_volume_clone.html.markdown +++ b/website/docs/r/pi_volume_clone.html.markdown @@ -15,11 +15,11 @@ The following example creates a volume clone. ```terraform resource "ibm_pi_volume_clone" "testacc_volume_clone" { - pi_cloud_instance_id = "" - pi_volume_clone_name = "test-volume-clone" - pi_volume_ids = [""] - pi_target_storage_tier = "" - pi_replication_enabled = true + pi_cloud_instance_id = "" + pi_volume_clone_name = "test-volume-clone" + pi_volume_ids = [""] + pi_target_storage_tier = "" + pi_replication_enabled = true } ``` @@ -61,15 +61,15 @@ In addition to all argument reference list, you can access the following attribu Nested scheme for `cloned_volumes`: - `clone_volume_id` - (String) The ID of the newly cloned volume. - `source_volume_id` - (String) The ID of the source volume. -- `id` - (String) The unique identifier of the volume clone. The ID is composed of `/`. -- `volume_clone_failure_reason` - (String) The reason for the failure of the volume clone task. -- `volume_clone_percent_complete` - (Integer) The completion percentage of the volume clone task. -- `volume_clone_status` - (String) The status of the volume clone task. -- `volume_clone_task_id` - (String) The ID of the volume clone task. +- `failure_reason` - (String) The reason for the failure of the volume clone task. +- `id` - (String) The unique identifier of the volume clone. The ID is composed of `/`. +- `percent_complete` - (Integer) The completion percentage of the volume clone task. +- `status` - (String) The status of the volume clone task. +- `task_id` - (String) The ID of the volume clone task. ## Import -The `ibm_pi_volume_clone` resource can be imported by using `power_instance_id` and `volume_clone_task_id`. +The `ibm_pi_volume_clone` resource can be imported by using `pi_cloud_instance_id` and `task_id`. **Example**