From d6f3e79c75db4b23760a42ea20a465520d5906d2 Mon Sep 17 00:00:00 2001 From: ismirlia <90468712+ismirlia@users.noreply.github.com> Date: Thu, 9 Jan 2025 11:53:28 -0600 Subject: [PATCH] [Refactor] Resource Volume Onboarding (#5906) * Refactor volume onboarding resource * Update volume onboarding markdown --- ibm/service/power/ibm_pi_constants.go | 20 +++ .../resource_ibm_pi_volume_onboarding.go | 169 +++++++++--------- .../resource_ibm_pi_volume_onboarding_test.go | 15 +- .../docs/r/pi_volume_onboarding.html.markdown | 59 +++--- 4 files changed, 139 insertions(+), 124 deletions(-) diff --git a/ibm/service/power/ibm_pi_constants.go b/ibm/service/power/ibm_pi_constants.go index f587aa1c9a..5c8e1b245d 100644 --- a/ibm/service/power/ibm_pi_constants.go +++ b/ibm/service/power/ibm_pi_constants.go @@ -10,6 +10,8 @@ const ( Arg_AffinityVolume = "pi_affinity_volume" Arg_AntiAffinityInstances = "pi_anti_affinity_instances" Arg_AntiAffinityVolumes = "pi_anti_affinity_volumes" + Arg_AuxiliaryVolumeName = "pi_auxiliary_volume_name" + Arg_AuxiliaryVolumes = "pi_auxiliary_volumes" Arg_BootVolumeReplicationEnabled = "pi_boot_volume_replication_enabled" Arg_Cidr = "pi_cidr" Arg_CloudConnectionID = "pi_cloud_connection_id" @@ -25,6 +27,7 @@ const ( Arg_DhcpID = "pi_dhcp_id" Arg_DhcpName = "pi_dhcp_name" Arg_DhcpSnatEnabled = "pi_dhcp_snat_enabled" + Arg_DisplayName = "pi_display_name" Arg_DNS = "pi_dns" Arg_DnsServer = "pi_dns_server" Arg_EndingIPAddress = "pi_ending_ip_address" @@ -65,6 +68,7 @@ const ( Arg_NetworkSecurityGroupMemberID = "pi_network_security_group_member_id" Arg_NetworkSecurityGroupRuleID = "pi_network_security_group_rule_id" Arg_NetworkType = "pi_network_type" + Arg_OnboardingVolumes = "pi_onboarding_volumes" Arg_PinPolicy = "pi_pin_policy" Arg_PlacementGroupID = "pi_placement_group_id" Arg_PlacementGroupName = "pi_placement_group_name" @@ -97,6 +101,7 @@ const ( Arg_SnapshotID = "pi_snapshot_id" Arg_SnapShotName = "pi_snap_shot_name" Arg_SnapshotName = "pi_snapshot_name" + Arg_SourceCRN = "pi_source_crn" Arg_SourcePorts = "pi_source_ports" Arg_SPPPlacementGroupID = "pi_spp_placement_group_id" Arg_SPPPlacementGroupName = "pi_spp_placement_group_name" @@ -318,6 +323,7 @@ const ( Attr_NetworkSecurityGroupMemberID = "network_security_group_member_id" Attr_NetworkSecurityGroups = "network_security_groups" Attr_NumberOfVolumes = "number_of_volumes" + Attr_OnboardingID = "onboarding_id" Attr_Onboardings = "onboardings" Attr_OperatingSystem = "operating_system" Attr_OSType = "os_type" @@ -616,6 +622,20 @@ const ( // TODO: Second Half Cleanup, remove extra variables + PIConsoleLanguageCode = "pi_language_code" + PIInstanceMigratable = "pi_migratable" + + // Volume Clone + PIVolumeCloneName = "pi_volume_clone_name" + PIVolumeCloneTaskID = "pi_volume_clone_task_id" + PITargetStorageTier = "pi_target_storage_tier" + + // IBM PI Volume Group + PIVolumeGroupID = "pi_volume_group_id" + PIVolumeGroupName = "pi_volume_group_name" + PIVolumeGroupConsistencyGroupName = "pi_consistency_group_name" + PIVolumeGroupAction = "pi_volume_group_action" + // VPN PIVPNConnectionId = "connection_id" PIVPNConnectionStatus = "connection_status" diff --git a/ibm/service/power/resource_ibm_pi_volume_onboarding.go b/ibm/service/power/resource_ibm_pi_volume_onboarding.go index f91977de7d..8fdb6634de 100644 --- a/ibm/service/power/resource_ibm_pi_volume_onboarding.go +++ b/ibm/service/power/resource_ibm_pi_volume_onboarding.go @@ -8,23 +8,13 @@ import ( "fmt" "time" - st "github.com/IBM-Cloud/power-go-client/clients/instance" - "github.com/IBM-Cloud/power-go-client/helpers" + "github.com/IBM-Cloud/power-go-client/clients/instance" "github.com/IBM-Cloud/power-go-client/power/models" "github.com/IBM-Cloud/terraform-provider-ibm/ibm/conns" "github.com/hashicorp/terraform-plugin-sdk/v2/diag" "github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema" ) -const ( - piOnboardingVolumes = "pi_onboarding_volumes" - piAuxiliaryVolumes = "pi_auxiliary_volumes" - piAuxiliaryVolumeName = "pi_auxiliary_volume_name" - piSourceCRN = "pi_source_crn" - piDisplayName = "pi_display_name" - piDescription = "pi_description" -) - func ResourceIBMPIVolumeOnboarding() *schema.Resource { return &schema.Resource{ CreateContext: resourceIBMPIVolumeOnboardingCreate, @@ -38,105 +28,108 @@ func ResourceIBMPIVolumeOnboarding() *schema.Resource { }, Schema: map[string]*schema.Schema{ - - helpers.PICloudInstanceId: { - Type: schema.TypeString, - Required: true, + // Arguments + Arg_CloudInstanceID: { + Description: "The GUID of the service instance associated with an account.", ForceNew: true, - Description: "Cloud Instance ID - This is the service_instance_id.", + Required: true, + Type: schema.TypeString, }, - - piOnboardingVolumes: { - Type: schema.TypeList, - Required: true, - ForceNew: true, - MinItems: 1, + Arg_Description: { + Computed: true, + Description: "Description of the volume onboarding operation", + Optional: true, + Type: schema.TypeString, + }, + Arg_OnboardingVolumes: { + Description: "List of onboarding volumes.", Elem: &schema.Resource{ Schema: map[string]*schema.Schema{ - piSourceCRN: { - Type: schema.TypeString, - Required: true, - Description: "CRN of source ServiceBroker instance from where auxiliary volumes need to be onboarded", - }, - piAuxiliaryVolumes: { - Type: schema.TypeList, - Optional: true, - MinItems: 1, + Arg_AuxiliaryVolumes: { + Description: "List auxiliary volumes.", Elem: &schema.Resource{ Schema: map[string]*schema.Schema{ - piAuxiliaryVolumeName: { - Type: schema.TypeString, + Arg_AuxiliaryVolumeName: { + Description: "The auxiliary volume name.", Required: true, - Description: "Auxiliary volume name at storage host level", - }, - piDisplayName: { Type: schema.TypeString, + }, + Arg_DisplayName: { + Description: "The display name of auxiliary volume which is to be onboarded.", Optional: true, - Description: "Display name of auxVolumeName once onboarded,auxVolumeName will be set to display name if not provided.", + Type: schema.TypeString, }, }, }, + MinItems: 1, + Optional: true, + Type: schema.TypeList, + }, + Arg_SourceCRN: { + Description: "The crn of source service broker instance from where auxiliary volumes need to be onboarded.", + Required: true, + Type: schema.TypeString, }, }, }, - }, - piDescription: { - Type: schema.TypeString, - Optional: true, - Computed: true, - Description: "Description of the volume onboarding operation", + ForceNew: true, + MinItems: 1, + Required: true, + Type: schema.TypeList, }, - // Computed Attribute - "create_time": { - Type: schema.TypeString, + // Attributes + Attr_CreateTime: { Computed: true, - Description: "Indicates the create-time of volume onboarding operation", - }, - "onboarding_id": { + Description: "The create time of volume onboarding operation.", Type: schema.TypeString, - Computed: true, - Description: "Indicates the volume onboarding operation id", }, - "input_volumes": { - Type: schema.TypeList, + Attr_InputVolumes: { Computed: true, - Description: "List of volumes requested to be onboarded", + Description: "List of volumes requested to be onboarded.", Elem: &schema.Schema{Type: schema.TypeString}, + Type: schema.TypeList, }, - "progress": { - Type: schema.TypeFloat, + Attr_OnboardingID: { Computed: true, - Description: "Indicates the progress of volume onboarding operation", + Description: "The volume onboarding ID.", + Type: schema.TypeString, }, - "results_onboarded_volumes": { - Type: schema.TypeList, + Attr_Progress: { + Computed: true, + Description: "The progress of volume onboarding operation.", + Type: schema.TypeFloat, + }, + Attr_ResultsOnboardedVolumes: { Computed: true, - Description: "List of volumes which are onboarded successfully", + Description: "List of volumes which are onboarded successfully.", Elem: &schema.Schema{Type: schema.TypeString}, + Type: schema.TypeList, }, - "results_volume_onboarding_failures": { - Type: schema.TypeList, - Computed: true, + Attr_ResultsVolumeOnboardingFailures: { + Computed: true, + Description: "The volume onboarding failure details.", Elem: &schema.Resource{ Schema: map[string]*schema.Schema{ - "failure_message": { - Type: schema.TypeString, + Attr_FailureMessage: { Computed: true, Description: "The failure reason for the volumes which have failed to be onboarded", + Type: schema.TypeString, }, - "volumes": { - Type: schema.TypeList, + Attr_Volumes: { Computed: true, Description: "List of volumes which have failed to be onboarded", Elem: &schema.Schema{Type: schema.TypeString}, + Type: schema.TypeList, }, - }}, + }, + }, + Type: schema.TypeList, }, - "status": { - Type: schema.TypeString, + Attr_Status: { Computed: true, - Description: "Indicates the status of volume onboarding operation", + Description: "The status of volume onboarding operation.", + Type: schema.TypeString, }, }, } @@ -147,10 +140,10 @@ func resourceIBMPIVolumeOnboardingCreate(ctx context.Context, d *schema.Resource if err != nil { return diag.FromErr(err) } - cloudInstanceID := d.Get(helpers.PICloudInstanceId).(string) - client := st.NewIBMPIVolumeOnboardingClient(ctx, sess, cloudInstanceID) + cloudInstanceID := d.Get(Arg_CloudInstanceID).(string) + client := instance.NewIBMPIVolumeOnboardingClient(ctx, sess, cloudInstanceID) - vol, err := expandCreateVolumeOnboarding(d.Get(piOnboardingVolumes).([]interface{})) + vol, err := expandCreateVolumeOnboarding(d.Get(Arg_OnboardingVolumes).([]interface{})) if err != nil { return diag.FromErr(err) } @@ -159,7 +152,7 @@ func resourceIBMPIVolumeOnboardingCreate(ctx context.Context, d *schema.Resource Volumes: vol, } - if v, ok := d.GetOk(piDescription); ok { + if v, ok := d.GetOk(Arg_Description); ok { body.Description = v.(string) } @@ -184,21 +177,21 @@ func resourceIBMPIVolumeOnboardingRead(ctx context.Context, d *schema.ResourceDa return diag.FromErr(err) } - client := st.NewIBMPIVolumeOnboardingClient(ctx, sess, cloudInstanceID) + client := instance.NewIBMPIVolumeOnboardingClient(ctx, sess, cloudInstanceID) onboardingData, err := client.Get(onboardingID) if err != nil { return diag.FromErr(err) } - d.Set("onboarding_id", *onboardingData.ID) - d.Set("create_time", onboardingData.CreationTimestamp.String()) - d.Set(piDescription, onboardingData.Description) - d.Set("input_volumes", onboardingData.InputVolumes) - d.Set("progress", onboardingData.Progress) - d.Set("status", onboardingData.Status) - d.Set("results_onboarded_volumes", onboardingData.Results.OnboardedVolumes) - d.Set("results_volume_onboarding_failures", flattenVolumeOnboardingFailures(onboardingData.Results.VolumeOnboardingFailures)) + d.Set(Arg_Description, onboardingData.Description) + d.Set(Attr_CreateTime, onboardingData.CreationTimestamp.String()) + d.Set(Attr_InputVolumes, onboardingData.InputVolumes) + d.Set(Attr_OnboardingID, *onboardingData.ID) + d.Set(Attr_Progress, onboardingData.Progress) + d.Set(Attr_ResultsOnboardedVolumes, onboardingData.Results.OnboardedVolumes) + d.Set(Attr_ResultsVolumeOnboardingFailures, flattenVolumeOnboardingFailures(onboardingData.Results.VolumeOnboardingFailures)) + d.Set(Attr_Status, onboardingData.Status) return nil } @@ -247,12 +240,12 @@ func expandAuxiliaryVolumeForOnboarding(data []interface{}) []*models.AuxiliaryV var auxVolumeName, displayName string resource := d.(map[string]interface{}) - if v, ok := resource["pi_auxiliary_volume_name"]; ok && v != "" { - auxVolumeName = resource["pi_auxiliary_volume_name"].(string) + if v, ok := resource[Arg_AuxiliaryVolumeName]; ok && v != "" { + auxVolumeName = resource[Arg_AuxiliaryVolumeName].(string) } - if v, ok := resource["pi_display_name"]; ok && v != "" { - displayName = resource["pi_display_name"].(string) + if v, ok := resource[Arg_DisplayName]; ok && v != "" { + displayName = resource[Arg_DisplayName].(string) } auxVolumeForOnboarding = append(auxVolumeForOnboarding, &models.AuxiliaryVolumeForOnboarding{ diff --git a/ibm/service/power/resource_ibm_pi_volume_onboarding_test.go b/ibm/service/power/resource_ibm_pi_volume_onboarding_test.go index 14c01fb51d..1fbcea9584 100644 --- a/ibm/service/power/resource_ibm_pi_volume_onboarding_test.go +++ b/ibm/service/power/resource_ibm_pi_volume_onboarding_test.go @@ -9,14 +9,14 @@ import ( "fmt" "testing" - "github.com/hashicorp/terraform-plugin-sdk/v2/helper/acctest" - "github.com/hashicorp/terraform-plugin-sdk/v2/helper/resource" - "github.com/hashicorp/terraform-plugin-sdk/v2/terraform" - - st "github.com/IBM-Cloud/power-go-client/clients/instance" acc "github.com/IBM-Cloud/terraform-provider-ibm/ibm/acctest" + + "github.com/IBM-Cloud/power-go-client/clients/instance" "github.com/IBM-Cloud/terraform-provider-ibm/ibm/conns" "github.com/IBM-Cloud/terraform-provider-ibm/ibm/flex" + "github.com/hashicorp/terraform-plugin-sdk/v2/helper/acctest" + "github.com/hashicorp/terraform-plugin-sdk/v2/helper/resource" + "github.com/hashicorp/terraform-plugin-sdk/v2/terraform" ) func TestAccIBMPIVolumeOnboardingbasic(t *testing.T) { @@ -60,7 +60,7 @@ func testAccCheckIBMPIVolumeOnboardingExists(n string) resource.TestCheckFunc { return err } cloudInstanceID, onboardID := ids[0], ids[1] - client := st.NewIBMPIVolumeOnboardingClient(context.Background(), sess, cloudInstanceID) + client := instance.NewIBMPIVolumeOnboardingClient(context.Background(), sess, cloudInstanceID) _, err = client.Get(onboardID) if err != nil { @@ -82,6 +82,5 @@ func testAccCheckIBMPIVolumeOnboardingConfig(name string) string { pi_display_name = "%[2]s-1" } } - } - `, acc.Pi_cloud_instance_id, name, acc.Pi_volume_onboarding_source_crn, acc.Pi_auxiliary_volume_name) + }`, acc.Pi_cloud_instance_id, name, acc.Pi_volume_onboarding_source_crn, acc.Pi_auxiliary_volume_name) } diff --git a/website/docs/r/pi_volume_onboarding.html.markdown b/website/docs/r/pi_volume_onboarding.html.markdown index 0331a767aa..f4771823e3 100644 --- a/website/docs/r/pi_volume_onboarding.html.markdown +++ b/website/docs/r/pi_volume_onboarding.html.markdown @@ -1,5 +1,4 @@ --- - subcategory: "Power Systems" layout: "ibm" page_title: "IBM: pi_volume_onboarding" @@ -8,33 +7,35 @@ description: |- --- # ibm_pi_volume_onboarding -Creates volume onboarding. For more information, about managing volume groups, see [getting started with IBM Power Systems Virtual Servers](https://cloud.ibm.com/docs/power-iaas?topic=power-iaas-getting-started). +Creates volume onboarding. For more information, about managing volume groups, see [getting started with IBM Power Systems Virtual Servers](https://cloud.ibm.com/docs/power-iaas?topic=power-iaas-getting-started). ## Example usage + The following example attaches volume to a power systems virtual server instance. ```terraform -resource "ibm_pi_volume_onboarding" "testacc_volume_onboarding"{ - pi_cloud_instance_id = "" - pi_description = "volume-onboarding-1" - pi_onboarding_volumes { - pi_source_crn = "< source crn >" - pi_auxiliary_volumes { - pi_auxiliary_volume_name = "< auxiliary volume name >" - pi_display_name = "< display name >" - } - } +resource "ibm_pi_volume_onboarding" "testacc_volume_onboarding" { + pi_cloud_instance_id = "" + pi_description = "volume-onboarding-1" + pi_onboarding_volumes { + pi_source_crn = "< source crn >" + pi_auxiliary_volumes { + pi_auxiliary_volume_name = "< auxiliary volume name >" + pi_display_name = "< display name >" + } + } } ``` -**Note** -* Please find [supported Regions](https://cloud.ibm.com/apidocs/power-cloud#endpoint) for endpoints. -* If a Power cloud instance is provisioned at `lon04`, The provider level attributes should be as follows: - * `region` - `lon` - * `zone` - `lon04` +### Notes + +- Please find [supported Regions](https://cloud.ibm.com/apidocs/power-cloud#endpoint) for endpoints. +- If a Power cloud instance is provisioned at `lon04`, The provider level attributes should be as follows: + - `region` - `lon` + - `zone` - `lon04` - Example usage: +Example usage: ```terraform provider "ibm" { @@ -50,8 +51,9 @@ ibm_pi_volume_onboarding provides the following [timeouts](https://www.terraform - **create** - (Default 15 minutes) Used for attaching volume. - **delete** - (Default 15 minutes) Used for detaching volume. -## Argument reference -Review the argument references that you can specify for your resource. +## Argument reference + +Review the argument references that you can specify for your resource. - `pi_cloud_instance_id` - (Required, Forces new resource, String) The GUID of the service instance associated with an account. - `pi_description` - (Optional, String) The description of the volume onboarding operation. @@ -59,8 +61,8 @@ Review the argument references that you can specify for your resource. - Constraints: The minimum length is `1` items. Nested scheme for **pi_onboarding_volumes**: - - `pi_source_crn` - (Required, String) The crn of source ServiceBroker instance from where auxiliary volumes need to be onboarded. - - `pi_auxiliary_volumes` - (Required, List of objects) List auxiliary volumes . + - `pi_auxiliary_volumes` - (Required, List of objects) List auxiliary volumes. + - `pi_source_crn` - (Required, String) The crn of source service broker instance from where auxiliary volumes need to be onboarded. - Constraints: The minimum length is `1` items. Nested scheme for **pi_auxiliary_volumes**: @@ -68,13 +70,13 @@ Review the argument references that you can specify for your resource. - `pi_display_name` - (Optional, String) The display name of auxiliary volume which is to be onboarded. ## Attribute reference + In addition to all argument reference list, you can access the following attribute reference after your resource is created. -- `create_time` - (String) The create-time of volume onboarding operation. +- `create_time` - (String) The create time of volume onboarding operation. - `id` - (String) The unique identifier of the volume attach. The ID is composed of `/`. -- `onboarding_id` (String) The onboarding ID. - `input_volumes` - (List of strings) List of volumes requested to be onboarded. -- `status` - (String) The status of volume onboarding operation. +- `onboarding_id` - (String) The volume onboarding ID. - `progress` - (Float) The progress of volume onboarding operation. - `results_onboarded_volumes` - (List of strings) List of volumes which are onboarded successfully. - `results_volume_onboarding_failures` - (List of objects) - The volume onboarding failure details. @@ -82,13 +84,14 @@ In addition to all argument reference list, you can access the following attribu Nested scheme for `results_volume_onboarding_failures`: - `failure_message` - (String) The failure reason for the volumes which have failed to be onboarded. - `volumes` - (List of strings) List of volumes which have failed to be onboarded. +- `status` - (String) The status of volume onboarding operation. ## Import The `ibm_pi_volume_onboarding` resource can be imported by using `pi_cloud_instance_id` and `onboarding_id`. -**Example** +### Example -``` -$ terraform import ibm_pi_volume_onboarding.example d7bec597-4726-451f-8a63-e62e6f19c32c/49fba6c9-23f8-40bc-9899-aca322ee7d5b +```bash +terraform import ibm_pi_volume_onboarding.example d7bec597-4726-451f-8a63-e62e6f19c32c/49fba6c9-23f8-40bc-9899-aca322ee7d5b ```