-
Notifications
You must be signed in to change notification settings - Fork 681
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add volume clone resource and data source (#5019)
* Add volume clone resource and data source * Docs improved * power-go-client update in go.mod * feedback resolved * testcase func renamed * Resolved conflicts * feedback resolved renamed targetReplicationEnabled to replicationEnabled * Alphabetically sorted documentation attributes. * Improved minor naming convention & docs * Added some use case scenarios * Feedback resolved * Fix: Document formatting * Making use of the correct cloudInstanceId constant
- Loading branch information
1 parent
7fc2c5a
commit d4c803b
Showing
14 changed files
with
627 additions
and
16 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,78 @@ | ||
// Copyright IBM Corp. 2024 All Rights Reserved. | ||
// Licensed under the Mozilla Public License v2.0 | ||
|
||
package power | ||
|
||
import ( | ||
"context" | ||
|
||
"github.com/hashicorp/terraform-plugin-sdk/v2/diag" | ||
"github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema" | ||
"github.com/hashicorp/terraform-plugin-sdk/v2/helper/validation" | ||
|
||
st "github.com/IBM-Cloud/power-go-client/clients/instance" | ||
"github.com/IBM-Cloud/terraform-provider-ibm/ibm/conns" | ||
) | ||
|
||
func DataSourceIBMPIVolumeClone() *schema.Resource { | ||
return &schema.Resource{ | ||
ReadContext: dataSourceIBMPIVolumeCloneRead, | ||
Schema: map[string]*schema.Schema{ | ||
PIVolumeCloneTaskID: { | ||
Type: schema.TypeString, | ||
Required: true, | ||
Description: "The ID of the volume clone task.", | ||
ValidateFunc: validation.NoZeroValues, | ||
}, | ||
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(), | ||
"failure_reason": { | ||
Type: schema.TypeString, | ||
Computed: true, | ||
Description: "The reason the clone volumes task has failed.", | ||
}, | ||
"percent_complete": { | ||
Type: schema.TypeInt, | ||
Computed: true, | ||
Description: "The completion percentage of the volume clone task.", | ||
}, | ||
"status": { | ||
Type: schema.TypeString, | ||
Computed: true, | ||
Description: "The status of the volume clone task.", | ||
}, | ||
}, | ||
} | ||
} | ||
|
||
func dataSourceIBMPIVolumeCloneRead(ctx context.Context, d *schema.ResourceData, meta interface{}) diag.Diagnostics { | ||
sess, err := meta.(conns.ClientSession).IBMPISession() | ||
if err != nil { | ||
return diag.FromErr(err) | ||
} | ||
|
||
cloudInstanceID := d.Get(Arg_CloudInstanceID).(string) | ||
client := st.NewIBMPICloneVolumeClient(ctx, sess, cloudInstanceID) | ||
volClone, err := client.Get(d.Get(PIVolumeCloneTaskID).(string)) | ||
if err != nil { | ||
return diag.FromErr(err) | ||
} | ||
|
||
d.SetId(d.Get(PIVolumeCloneTaskID).(string)) | ||
if volClone.Status != nil { | ||
d.Set("status", *volClone.Status) | ||
} | ||
d.Set("failure_reason", volClone.FailedReason) | ||
if volClone.PercentComplete != nil { | ||
d.Set("percent_complete", *volClone.PercentComplete) | ||
} | ||
d.Set("cloned_volumes", flattenClonedVolumes(volClone.ClonedVolumes)) | ||
|
||
return nil | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,38 @@ | ||
// Copyright IBM Corp. 2024 All Rights Reserved. | ||
// Licensed under the Mozilla Public License v2.0 | ||
|
||
package power_test | ||
|
||
import ( | ||
"fmt" | ||
"testing" | ||
|
||
acc "github.com/IBM-Cloud/terraform-provider-ibm/ibm/acctest" | ||
|
||
"github.com/hashicorp/terraform-plugin-sdk/v2/helper/resource" | ||
) | ||
|
||
func TestAccIBMPIVolumeClone_basic(t *testing.T) { | ||
resource.Test(t, resource.TestCase{ | ||
PreCheck: func() { acc.TestAccPreCheck(t) }, | ||
Providers: acc.TestAccProviders, | ||
Steps: []resource.TestStep{ | ||
{ | ||
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", "status"), | ||
), | ||
}, | ||
}, | ||
}) | ||
} | ||
|
||
func testAccCheckIBMPIVolumeCloneBasicConfig() string { | ||
return fmt.Sprintf(` | ||
data "ibm_pi_volume_clone" "testacc_ds_volume_clone" { | ||
pi_volume_clone_task_id = "%s" | ||
pi_cloud_instance_id = "%s" | ||
}`, acc.Pi_volume_clone_task_id, acc.Pi_cloud_instance_id) | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.