Skip to content

Commit

Permalink
Feedback resolved
Browse files Browse the repository at this point in the history
  • Loading branch information
dhirendersingh19 committed Jan 9, 2024
1 parent 512b6fc commit 2cda0cf
Show file tree
Hide file tree
Showing 7 changed files with 81 additions and 74 deletions.
25 changes: 13 additions & 12 deletions ibm/service/power/data_source_ibm_pi_volume_clone.go
Original file line number Diff line number Diff line change
@@ -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
Expand All @@ -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.",
},
},
}
Expand All @@ -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))

Expand Down
4 changes: 2 additions & 2 deletions ibm/service/power/data_source_ibm_pi_volume_clone_test.go
Original file line number Diff line number Diff line change
@@ -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
Expand All @@ -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"),
),
},
},
Expand Down
22 changes: 12 additions & 10 deletions ibm/service/power/ibm_pi_constants.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down
57 changes: 29 additions & 28 deletions ibm/service/power/resource_ibm_pi_volume_clone.go
Original file line number Diff line number Diff line change
@@ -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
Expand Down Expand Up @@ -32,60 +32,60 @@ 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,
Required: true,
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.",
},
},
}
Expand Down Expand Up @@ -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))

Expand Down Expand Up @@ -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,
Expand All @@ -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.",
},
},
},
Expand Down
14 changes: 9 additions & 5 deletions ibm/service/power/resource_ibm_pi_volume_clone_test.go
Original file line number Diff line number Diff line change
@@ -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
Expand All @@ -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) },
Expand All @@ -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"),
),
},
},
Expand Down Expand Up @@ -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
}
Expand Down
11 changes: 5 additions & 6 deletions website/docs/d/pi_volume_clone.html.markdown
Original file line number Diff line number Diff line change
Expand Up @@ -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 = "<value of the cloud_instance_id>"
pi_volume_clone_task_id = "<clone task id>"
pi_cloud_instance_id = "<value of the cloud_instance_id>"
pi_volume_clone_task_id = "<clone task id>"
}
```

Expand Down Expand Up @@ -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.
22 changes: 11 additions & 11 deletions website/docs/r/pi_volume_clone.html.markdown
Original file line number Diff line number Diff line change
Expand Up @@ -15,11 +15,11 @@ The following example creates a volume clone.

```terraform
resource "ibm_pi_volume_clone" "testacc_volume_clone" {
pi_cloud_instance_id = "<value of the cloud_instance_id>"
pi_volume_clone_name = "test-volume-clone"
pi_volume_ids = ["<Volume ID>"]
pi_target_storage_tier = "<storage tier>"
pi_replication_enabled = true
pi_cloud_instance_id = "<value of the cloud_instance_id>"
pi_volume_clone_name = "test-volume-clone"
pi_volume_ids = ["<Volume ID>"]
pi_target_storage_tier = "<storage tier>"
pi_replication_enabled = true
}
```

Expand Down Expand Up @@ -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 `<pi_cloud_instance_id>/<volume_clone_task_id>`.
- `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 `<pi_cloud_instance_id>/<task_id>`.
- `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**

Expand Down

0 comments on commit 2cda0cf

Please sign in to comment.