From c276f7fd29d332ab6d1f8ae2b1cc96cf87fc6d07 Mon Sep 17 00:00:00 2001 From: Diptipowervs Date: Mon, 18 Mar 2024 20:10:16 +0530 Subject: [PATCH 1/4] Volume-attach --- ibm/service/power/ibm_pi_constants.go | 6 +++ .../power/resource_ibm_pi_volume_attach.go | 51 +++++++++---------- .../resource_ibm_pi_volume_attach_test.go | 6 +-- website/docs/r/pi_volume_attach.html.markdown | 3 +- 4 files changed, 34 insertions(+), 32 deletions(-) diff --git a/ibm/service/power/ibm_pi_constants.go b/ibm/service/power/ibm_pi_constants.go index c06f0b7d80..2d5b27a0fc 100644 --- a/ibm/service/power/ibm_pi_constants.go +++ b/ibm/service/power/ibm_pi_constants.go @@ -8,6 +8,7 @@ const ( Arg_CloudInstanceID = "pi_cloud_instance_id" Arg_ImageName = "pi_image_name" Arg_InstanceName = "pi_instance_name" + Arg_InstanceId = "pi_instace_id" Arg_Key = "pi_ssh_key" Arg_KeyName = "pi_key_name" Arg_NetworkName = "pi_network_name" @@ -160,6 +161,7 @@ const ( Attr_Pool = "pool" Attr_PoolName = "pool_name" Attr_Port = "port" + Attr_PowerVolumeAttachDeleting = "power_volume_attach_deleting" Attr_PortID = "portid" Attr_PrimaryRole = "primary_role" Attr_ProcType = "proctype" @@ -242,10 +244,14 @@ const ( Attr_VPCCRNs = "vpc_crns" Attr_VPCEnabled = "vpc_enabled" Attr_VirtualCoresAssigned = "virtual_cores_assigned" + Attr_VolumeAllowableAttachStatus = "volume_allowable_attach_status" + Attr_VolumeAttachStatus = "volume_attach_status" Attr_VolumeGroupName = "volume_group_name" Attr_VolumeGroups = "volume_groups" Attr_VolumeIDs = "volume_ids" Attr_VolumePool = "volume_pool" + Attr_VolumeProvisioning = "volume_provisioning" + Attr_VolumeProvisioningDone = "volume_provisioning_done" Attr_VolumeSnapshots = "volume_snapshots" Attr_Volumes = "volumes" Attr_WWN = "wwn" diff --git a/ibm/service/power/resource_ibm_pi_volume_attach.go b/ibm/service/power/resource_ibm_pi_volume_attach.go index cc17613006..35a6cfaee4 100644 --- a/ibm/service/power/resource_ibm_pi_volume_attach.go +++ b/ibm/service/power/resource_ibm_pi_volume_attach.go @@ -10,8 +10,7 @@ import ( "log" "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/client/p_cloud_volumes" "github.com/IBM-Cloud/terraform-provider-ibm/ibm/conns" "github.com/IBM-Cloud/terraform-provider-ibm/ibm/flex" @@ -34,21 +33,21 @@ func ResourceIBMPIVolumeAttach() *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.", }, - helpers.PIVolumeId: { + Arg_VolumeID: { Type: schema.TypeString, Required: true, ForceNew: true, Description: "Id of the volume to attach. Note these volumes should have been created", }, - helpers.PIInstanceId: { + Arg_InstanceId: { Type: schema.TypeString, Required: true, ForceNew: true, @@ -56,7 +55,7 @@ func ResourceIBMPIVolumeAttach() *schema.Resource { }, // Computed Attribute - helpers.PIVolumeAttachStatus: { + Attr_VolumeAttachStatus: { Type: schema.TypeString, Computed: true, }, @@ -70,11 +69,11 @@ func resourceIBMPIVolumeAttachCreate(ctx context.Context, d *schema.ResourceData return diag.FromErr(err) } - volumeID := d.Get(helpers.PIVolumeId).(string) - pvmInstanceID := d.Get(helpers.PIInstanceId).(string) - cloudInstanceID := d.Get(helpers.PICloudInstanceId).(string) + volumeID := d.Get(Arg_VolumeID).(string) + pvmInstanceID := d.Get(Arg_InstanceId).(string) + cloudInstanceID := d.Get(Arg_CloudInstanceID).(string) - volClient := st.NewIBMPIVolumeClient(ctx, sess, cloudInstanceID) + volClient := instance.NewIBMPIVolumeClient(ctx, sess, cloudInstanceID) volinfo, err := volClient.Get(volumeID) if err != nil { return diag.FromErr(err) @@ -89,7 +88,7 @@ func resourceIBMPIVolumeAttachCreate(ctx context.Context, d *schema.ResourceData log.Printf("Volume State /Status is permitted and hence attaching the volume to the instance") } - if volinfo.State == helpers.PIVolumeAllowableAttachStatus && !*volinfo.Shareable { + if volinfo.State == Attr_VolumeAllowableAttachStatus && !*volinfo.Shareable { return diag.Errorf("the volume cannot be attached in the current state. The volume must be in the *available* state. No other states are permissible") } @@ -121,14 +120,14 @@ func resourceIBMPIVolumeAttachRead(ctx context.Context, d *schema.ResourceData, } cloudInstanceID, pvmInstanceID, volumeID := ids[0], ids[1], ids[2] - client := st.NewIBMPIVolumeClient(ctx, sess, cloudInstanceID) + client := instance.NewIBMPIVolumeClient(ctx, sess, cloudInstanceID) vol, err := client.CheckVolumeAttach(pvmInstanceID, volumeID) if err != nil { return diag.FromErr(err) } - d.Set(helpers.PIVolumeAttachStatus, vol.State) + d.Set(Attr_VolumeAttachStatus, vol.State) return nil } @@ -143,7 +142,7 @@ func resourceIBMPIVolumeAttachDelete(ctx context.Context, d *schema.ResourceData return diag.FromErr(err) } cloudInstanceID, pvmInstanceID, volumeID := ids[0], ids[1], ids[2] - client := st.NewIBMPIVolumeClient(ctx, sess, cloudInstanceID) + client := instance.NewIBMPIVolumeClient(ctx, sess, cloudInstanceID) log.Printf("the id of the volume to detach is %s ", volumeID) @@ -170,12 +169,12 @@ func resourceIBMPIVolumeAttachDelete(ctx context.Context, d *schema.ResourceData return nil } -func isWaitForIBMPIVolumeAttachAvailable(ctx context.Context, client *st.IBMPIVolumeClient, id, cloudInstanceID, pvmInstanceID string, timeout time.Duration) (interface{}, error) { +func isWaitForIBMPIVolumeAttachAvailable(ctx context.Context, client *instance.IBMPIVolumeClient, id, cloudInstanceID, pvmInstanceID string, timeout time.Duration) (interface{}, error) { log.Printf("Waiting for Volume (%s) to be available for attachment", id) stateConf := &resource.StateChangeConf{ - Pending: []string{"retry", helpers.PIVolumeProvisioning}, - Target: []string{helpers.PIVolumeAllowableAttachStatus}, + Pending: []string{"retry", Attr_VolumeProvisioning}, + Target: []string{Attr_VolumeAllowableAttachStatus}, Refresh: isIBMPIVolumeAttachRefreshFunc(client, id, cloudInstanceID, pvmInstanceID), Delay: 10 * time.Second, MinTimeout: 30 * time.Second, @@ -185,7 +184,7 @@ func isWaitForIBMPIVolumeAttachAvailable(ctx context.Context, client *st.IBMPIVo return stateConf.WaitForStateContext(ctx) } -func isIBMPIVolumeAttachRefreshFunc(client *st.IBMPIVolumeClient, id, cloudInstanceID, pvmInstanceID string) resource.StateRefreshFunc { +func isIBMPIVolumeAttachRefreshFunc(client *instance.IBMPIVolumeClient, id, cloudInstanceID, pvmInstanceID string) resource.StateRefreshFunc { return func() (interface{}, string, error) { vol, err := client.Get(id) if err != nil { @@ -193,19 +192,19 @@ func isIBMPIVolumeAttachRefreshFunc(client *st.IBMPIVolumeClient, id, cloudInsta } if vol.State == "in-use" && flex.StringContains(vol.PvmInstanceIDs, pvmInstanceID) { - return vol, helpers.PIVolumeAllowableAttachStatus, nil + return vol, Attr_VolumeAllowableAttachStatus, nil } - return vol, helpers.PIVolumeProvisioning, nil + return vol, Attr_VolumeProvisioning, nil } } -func isWaitForIBMPIVolumeDetach(ctx context.Context, client *st.IBMPIVolumeClient, id, cloudInstanceID, pvmInstanceID string, timeout time.Duration) (interface{}, error) { +func isWaitForIBMPIVolumeDetach(ctx context.Context, client *instance.IBMPIVolumeClient, id, cloudInstanceID, pvmInstanceID string, timeout time.Duration) (interface{}, error) { log.Printf("Waiting for Volume (%s) to be available after detachment", id) stateConf := &resource.StateChangeConf{ - Pending: []string{"detaching", helpers.PowerVolumeAttachDeleting}, - Target: []string{helpers.PIVolumeProvisioningDone}, + Pending: []string{"detaching", Attr_PowerVolumeAttachDeleting}, + Target: []string{Attr_VolumeProvisioningDone}, Refresh: isIBMPIVolumeDetachRefreshFunc(client, id, cloudInstanceID, pvmInstanceID), Delay: 10 * time.Second, MinTimeout: 30 * time.Second, @@ -215,7 +214,7 @@ func isWaitForIBMPIVolumeDetach(ctx context.Context, client *st.IBMPIVolumeClien return stateConf.WaitForStateContext(ctx) } -func isIBMPIVolumeDetachRefreshFunc(client *st.IBMPIVolumeClient, id, cloudInstanceID, pvmInstanceID string) resource.StateRefreshFunc { +func isIBMPIVolumeDetachRefreshFunc(client *instance.IBMPIVolumeClient, id, cloudInstanceID, pvmInstanceID string) resource.StateRefreshFunc { return func() (interface{}, string, error) { vol, err := client.Get(id) if err != nil { @@ -223,7 +222,7 @@ func isIBMPIVolumeDetachRefreshFunc(client *st.IBMPIVolumeClient, id, cloudInsta switch uErr.(type) { case *p_cloud_volumes.PcloudCloudinstancesVolumesGetNotFound: log.Printf("[DEBUG] volume does not exist while detaching %v", err) - return vol, helpers.PIVolumeProvisioningDone, nil + return vol, Attr_VolumeProvisioningDone, nil } return nil, "", err } @@ -233,7 +232,7 @@ func isIBMPIVolumeDetachRefreshFunc(client *st.IBMPIVolumeClient, id, cloudInsta // In case of Sharable Volume it can be `in-use` state if !flex.StringContains(vol.PvmInstanceIDs, pvmInstanceID) && (*vol.Shareable || (!*vol.Shareable && vol.State == "available")) { - return vol, helpers.PIVolumeProvisioningDone, nil + return vol, Attr_VolumeProvisioningDone, nil } return vol, "detaching", nil diff --git a/ibm/service/power/resource_ibm_pi_volume_attach_test.go b/ibm/service/power/resource_ibm_pi_volume_attach_test.go index 287e5b08c6..6b3720744e 100644 --- a/ibm/service/power/resource_ibm_pi_volume_attach_test.go +++ b/ibm/service/power/resource_ibm_pi_volume_attach_test.go @@ -139,8 +139,7 @@ func testAccCheckIBMPIVolumeAttachConfig(name string) string { pi_cloud_instance_id = "%[1]s" pi_volume_id = ibm_pi_volume.power_volume.volume_id pi_instance_id = ibm_pi_instance.power_instance.instance_id - } - `, acc.Pi_cloud_instance_id, name, acc.Pi_image, acc.Pi_network_name) + }`, acc.Pi_cloud_instance_id, name, acc.Pi_image, acc.Pi_network_name) } func testAccCheckIBMPIShareableVolumeAttachConfig(name string) string { @@ -171,6 +170,5 @@ func testAccCheckIBMPIShareableVolumeAttachConfig(name string) string { pi_cloud_instance_id = "%[1]s" pi_volume_id = ibm_pi_volume.power_volume.volume_id pi_instance_id = ibm_pi_instance.power_instance[1].instance_id - } - `, acc.Pi_cloud_instance_id, name, acc.Pi_image, acc.Pi_network_name) + }`, acc.Pi_cloud_instance_id, name, acc.Pi_image, acc.Pi_network_name) } diff --git a/website/docs/r/pi_volume_attach.html.markdown b/website/docs/r/pi_volume_attach.html.markdown index 12aeddf359..e8ad14f6cf 100644 --- a/website/docs/r/pi_volume_attach.html.markdown +++ b/website/docs/r/pi_volume_attach.html.markdown @@ -1,5 +1,4 @@ --- - subcategory: "Power Systems" layout: "ibm" page_title: "IBM: pi_volume_attach" @@ -21,7 +20,7 @@ resource "ibm_pi_volume_attach" "testacc_volume_attach"{ } ``` -**Note** +**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` From f1683b10d20ba723d1123c90d35739029c92b110 Mon Sep 17 00:00:00 2001 From: Diptipowervs Date: Mon, 18 Mar 2024 20:15:01 +0530 Subject: [PATCH 2/4] Sort stanza --- .../power/resource_ibm_pi_volume_attach.go | 18 +++++++++--------- 1 file changed, 9 insertions(+), 9 deletions(-) diff --git a/ibm/service/power/resource_ibm_pi_volume_attach.go b/ibm/service/power/resource_ibm_pi_volume_attach.go index 35a6cfaee4..f95de6bc68 100644 --- a/ibm/service/power/resource_ibm_pi_volume_attach.go +++ b/ibm/service/power/resource_ibm_pi_volume_attach.go @@ -34,24 +34,24 @@ func ResourceIBMPIVolumeAttach() *schema.Resource { Schema: map[string]*schema.Schema{ Arg_CloudInstanceID: { - Type: schema.TypeString, - Required: true, - ForceNew: true, Description: " Cloud Instance ID - This is the service_instance_id.", + ForceNew: true, + Required: true, + Type: schema.TypeString, }, Arg_VolumeID: { - Type: schema.TypeString, - Required: true, - ForceNew: true, Description: "Id of the volume to attach. Note these volumes should have been created", + ForceNew: true, + Required: true, + Type: schema.TypeString, }, Arg_InstanceId: { - Type: schema.TypeString, - Required: true, - ForceNew: true, Description: "PI Instance Id", + ForceNew: true, + Required: true, + Type: schema.TypeString, }, // Computed Attribute From 2e4457c52fa7e423da4fa4a86efaf455580a7b51 Mon Sep 17 00:00:00 2001 From: Diptipowervs Date: Tue, 26 Mar 2024 19:03:04 +0530 Subject: [PATCH 3/4] Update const --- ibm/service/power/ibm_pi_constants.go | 19 +++++++-------- .../power/resource_ibm_pi_volume_attach.go | 24 +++++++++---------- 2 files changed, 21 insertions(+), 22 deletions(-) diff --git a/ibm/service/power/ibm_pi_constants.go b/ibm/service/power/ibm_pi_constants.go index 2d5b27a0fc..d170d82d55 100644 --- a/ibm/service/power/ibm_pi_constants.go +++ b/ibm/service/power/ibm_pi_constants.go @@ -8,7 +8,6 @@ const ( Arg_CloudInstanceID = "pi_cloud_instance_id" Arg_ImageName = "pi_image_name" Arg_InstanceName = "pi_instance_name" - Arg_InstanceId = "pi_instace_id" Arg_Key = "pi_ssh_key" Arg_KeyName = "pi_key_name" Arg_NetworkName = "pi_network_name" @@ -244,14 +243,11 @@ const ( Attr_VPCCRNs = "vpc_crns" Attr_VPCEnabled = "vpc_enabled" Attr_VirtualCoresAssigned = "virtual_cores_assigned" - Attr_VolumeAllowableAttachStatus = "volume_allowable_attach_status" Attr_VolumeAttachStatus = "volume_attach_status" Attr_VolumeGroupName = "volume_group_name" Attr_VolumeGroups = "volume_groups" Attr_VolumeIDs = "volume_ids" Attr_VolumePool = "volume_pool" - Attr_VolumeProvisioning = "volume_provisioning" - Attr_VolumeProvisioningDone = "volume_provisioning_done" Attr_VolumeSnapshots = "volume_snapshots" Attr_Volumes = "volumes" Attr_WWN = "wwn" @@ -339,12 +335,15 @@ const ( PIPlacementGroupMembers = "members" // Volume - PIVolumeIds = "pi_volume_ids" - PIAffinityPolicy = "pi_affinity_policy" - PIAffinityVolume = "pi_affinity_volume" - PIAffinityInstance = "pi_affinity_instance" - PIAntiAffinityInstances = "pi_anti_affinity_instances" - PIAntiAffinityVolumes = "pi_anti_affinity_volumes" + PIAffinityPolicy = "pi_affinity_policy" + PIAffinityVolume = "pi_affinity_volume" + PIAffinityInstance = "pi_affinity_instance" + PIAntiAffinityInstances = "pi_anti_affinity_instances" + PIAntiAffinityVolumes = "pi_anti_affinity_volumes" + PIVolumeIds = "pi_volume_ids" + PIVolumeAllowableAttachStatus = "in-use" + PIVolumeProvisioning = "creating" + PIVolumeProvisioningDone = "available" // Volume Clone PIVolumeCloneName = "pi_volume_clone_name" diff --git a/ibm/service/power/resource_ibm_pi_volume_attach.go b/ibm/service/power/resource_ibm_pi_volume_attach.go index f95de6bc68..71ac31993d 100644 --- a/ibm/service/power/resource_ibm_pi_volume_attach.go +++ b/ibm/service/power/resource_ibm_pi_volume_attach.go @@ -47,7 +47,7 @@ func ResourceIBMPIVolumeAttach() *schema.Resource { Type: schema.TypeString, }, - Arg_InstanceId: { + Arg_PVMInstanceId: { Description: "PI Instance Id", ForceNew: true, Required: true, @@ -55,7 +55,7 @@ func ResourceIBMPIVolumeAttach() *schema.Resource { }, // Computed Attribute - Attr_VolumeAttachStatus: { + Attr_Status: { Type: schema.TypeString, Computed: true, }, @@ -70,7 +70,7 @@ func resourceIBMPIVolumeAttachCreate(ctx context.Context, d *schema.ResourceData } volumeID := d.Get(Arg_VolumeID).(string) - pvmInstanceID := d.Get(Arg_InstanceId).(string) + pvmInstanceID := d.Get(Arg_PVMInstanceId).(string) cloudInstanceID := d.Get(Arg_CloudInstanceID).(string) volClient := instance.NewIBMPIVolumeClient(ctx, sess, cloudInstanceID) @@ -88,7 +88,7 @@ func resourceIBMPIVolumeAttachCreate(ctx context.Context, d *schema.ResourceData log.Printf("Volume State /Status is permitted and hence attaching the volume to the instance") } - if volinfo.State == Attr_VolumeAllowableAttachStatus && !*volinfo.Shareable { + if volinfo.State == PIVolumeAllowableAttachStatus && !*volinfo.Shareable { return diag.Errorf("the volume cannot be attached in the current state. The volume must be in the *available* state. No other states are permissible") } @@ -127,7 +127,7 @@ func resourceIBMPIVolumeAttachRead(ctx context.Context, d *schema.ResourceData, return diag.FromErr(err) } - d.Set(Attr_VolumeAttachStatus, vol.State) + d.Set(Attr_Status, vol.State) return nil } @@ -173,8 +173,8 @@ func isWaitForIBMPIVolumeAttachAvailable(ctx context.Context, client *instance.I log.Printf("Waiting for Volume (%s) to be available for attachment", id) stateConf := &resource.StateChangeConf{ - Pending: []string{"retry", Attr_VolumeProvisioning}, - Target: []string{Attr_VolumeAllowableAttachStatus}, + Pending: []string{"retry", PIVolumeProvisioning}, + Target: []string{PIVolumeAllowableAttachStatus}, Refresh: isIBMPIVolumeAttachRefreshFunc(client, id, cloudInstanceID, pvmInstanceID), Delay: 10 * time.Second, MinTimeout: 30 * time.Second, @@ -192,10 +192,10 @@ func isIBMPIVolumeAttachRefreshFunc(client *instance.IBMPIVolumeClient, id, clou } if vol.State == "in-use" && flex.StringContains(vol.PvmInstanceIDs, pvmInstanceID) { - return vol, Attr_VolumeAllowableAttachStatus, nil + return vol, PIVolumeAllowableAttachStatus, nil } - return vol, Attr_VolumeProvisioning, nil + return vol, PIVolumeProvisioning, nil } } @@ -204,7 +204,7 @@ func isWaitForIBMPIVolumeDetach(ctx context.Context, client *instance.IBMPIVolum stateConf := &resource.StateChangeConf{ Pending: []string{"detaching", Attr_PowerVolumeAttachDeleting}, - Target: []string{Attr_VolumeProvisioningDone}, + Target: []string{PIVolumeProvisioningDone}, Refresh: isIBMPIVolumeDetachRefreshFunc(client, id, cloudInstanceID, pvmInstanceID), Delay: 10 * time.Second, MinTimeout: 30 * time.Second, @@ -222,7 +222,7 @@ func isIBMPIVolumeDetachRefreshFunc(client *instance.IBMPIVolumeClient, id, clou switch uErr.(type) { case *p_cloud_volumes.PcloudCloudinstancesVolumesGetNotFound: log.Printf("[DEBUG] volume does not exist while detaching %v", err) - return vol, Attr_VolumeProvisioningDone, nil + return vol, PIVolumeProvisioningDone, nil } return nil, "", err } @@ -232,7 +232,7 @@ func isIBMPIVolumeDetachRefreshFunc(client *instance.IBMPIVolumeClient, id, clou // In case of Sharable Volume it can be `in-use` state if !flex.StringContains(vol.PvmInstanceIDs, pvmInstanceID) && (*vol.Shareable || (!*vol.Shareable && vol.State == "available")) { - return vol, Attr_VolumeProvisioningDone, nil + return vol, PIVolumeProvisioningDone, nil } return vol, "detaching", nil From 22ab2788e5edbedb390420a81dfcdcdaf768416f Mon Sep 17 00:00:00 2001 From: Diptipowervs Date: Thu, 28 Mar 2024 20:52:20 +0530 Subject: [PATCH 4/4] Add Attr_Provisioning --- ibm/service/power/ibm_pi_constants.go | 36 +++++++++---------- .../power/resource_ibm_pi_volume_attach.go | 16 ++++----- 2 files changed, 26 insertions(+), 26 deletions(-) diff --git a/ibm/service/power/ibm_pi_constants.go b/ibm/service/power/ibm_pi_constants.go index d170d82d55..96b3037e0e 100644 --- a/ibm/service/power/ibm_pi_constants.go +++ b/ibm/service/power/ibm_pi_constants.go @@ -243,15 +243,15 @@ const ( Attr_VPCCRNs = "vpc_crns" Attr_VPCEnabled = "vpc_enabled" Attr_VirtualCoresAssigned = "virtual_cores_assigned" - Attr_VolumeAttachStatus = "volume_attach_status" - Attr_VolumeGroupName = "volume_group_name" - Attr_VolumeGroups = "volume_groups" - Attr_VolumeIDs = "volume_ids" - Attr_VolumePool = "volume_pool" - Attr_VolumeSnapshots = "volume_snapshots" - Attr_Volumes = "volumes" - Attr_WWN = "wwn" - Attr_Workspaces = "workspaces" + //Attr_VolumeAttachStatus = "volume_attach_status" + Attr_VolumeGroupName = "volume_group_name" + Attr_VolumeGroups = "volume_groups" + Attr_VolumeIDs = "volume_ids" + Attr_VolumePool = "volume_pool" + Attr_VolumeSnapshots = "volume_snapshots" + Attr_Volumes = "volumes" + Attr_WWN = "wwn" + Attr_Workspaces = "workspaces" // TODO: Second Half Cleanup, remove extra variables @@ -335,15 +335,15 @@ const ( PIPlacementGroupMembers = "members" // Volume - PIAffinityPolicy = "pi_affinity_policy" - PIAffinityVolume = "pi_affinity_volume" - PIAffinityInstance = "pi_affinity_instance" - PIAntiAffinityInstances = "pi_anti_affinity_instances" - PIAntiAffinityVolumes = "pi_anti_affinity_volumes" - PIVolumeIds = "pi_volume_ids" - PIVolumeAllowableAttachStatus = "in-use" - PIVolumeProvisioning = "creating" - PIVolumeProvisioningDone = "available" + PIAffinityPolicy = "pi_affinity_policy" + PIAffinityVolume = "pi_affinity_volume" + PIAffinityInstance = "pi_affinity_instance" + PIAntiAffinityInstances = "pi_anti_affinity_instances" + PIAntiAffinityVolumes = "pi_anti_affinity_volumes" + PIVolumeIds = "pi_volume_ids" + Attr_VolumeAllowableAttachStatus = "in-use" + Attr_VolumeProvisioning = "creating" + Attr_VolumeProvisioningDone = "available" // Volume Clone PIVolumeCloneName = "pi_volume_clone_name" diff --git a/ibm/service/power/resource_ibm_pi_volume_attach.go b/ibm/service/power/resource_ibm_pi_volume_attach.go index 71ac31993d..8aaa92c618 100644 --- a/ibm/service/power/resource_ibm_pi_volume_attach.go +++ b/ibm/service/power/resource_ibm_pi_volume_attach.go @@ -88,7 +88,7 @@ func resourceIBMPIVolumeAttachCreate(ctx context.Context, d *schema.ResourceData log.Printf("Volume State /Status is permitted and hence attaching the volume to the instance") } - if volinfo.State == PIVolumeAllowableAttachStatus && !*volinfo.Shareable { + if volinfo.State == Attr_VolumeAllowableAttachStatus && !*volinfo.Shareable { return diag.Errorf("the volume cannot be attached in the current state. The volume must be in the *available* state. No other states are permissible") } @@ -173,8 +173,8 @@ func isWaitForIBMPIVolumeAttachAvailable(ctx context.Context, client *instance.I log.Printf("Waiting for Volume (%s) to be available for attachment", id) stateConf := &resource.StateChangeConf{ - Pending: []string{"retry", PIVolumeProvisioning}, - Target: []string{PIVolumeAllowableAttachStatus}, + Pending: []string{"retry", Attr_VolumeProvisioning}, + Target: []string{Attr_VolumeAllowableAttachStatus}, Refresh: isIBMPIVolumeAttachRefreshFunc(client, id, cloudInstanceID, pvmInstanceID), Delay: 10 * time.Second, MinTimeout: 30 * time.Second, @@ -192,10 +192,10 @@ func isIBMPIVolumeAttachRefreshFunc(client *instance.IBMPIVolumeClient, id, clou } if vol.State == "in-use" && flex.StringContains(vol.PvmInstanceIDs, pvmInstanceID) { - return vol, PIVolumeAllowableAttachStatus, nil + return vol, Attr_VolumeAllowableAttachStatus, nil } - return vol, PIVolumeProvisioning, nil + return vol, Attr_VolumeProvisioning, nil } } @@ -204,7 +204,7 @@ func isWaitForIBMPIVolumeDetach(ctx context.Context, client *instance.IBMPIVolum stateConf := &resource.StateChangeConf{ Pending: []string{"detaching", Attr_PowerVolumeAttachDeleting}, - Target: []string{PIVolumeProvisioningDone}, + Target: []string{Attr_VolumeProvisioningDone}, Refresh: isIBMPIVolumeDetachRefreshFunc(client, id, cloudInstanceID, pvmInstanceID), Delay: 10 * time.Second, MinTimeout: 30 * time.Second, @@ -222,7 +222,7 @@ func isIBMPIVolumeDetachRefreshFunc(client *instance.IBMPIVolumeClient, id, clou switch uErr.(type) { case *p_cloud_volumes.PcloudCloudinstancesVolumesGetNotFound: log.Printf("[DEBUG] volume does not exist while detaching %v", err) - return vol, PIVolumeProvisioningDone, nil + return vol, Attr_VolumeProvisioningDone, nil } return nil, "", err } @@ -232,7 +232,7 @@ func isIBMPIVolumeDetachRefreshFunc(client *instance.IBMPIVolumeClient, id, clou // In case of Sharable Volume it can be `in-use` state if !flex.StringContains(vol.PvmInstanceIDs, pvmInstanceID) && (*vol.Shareable || (!*vol.Shareable && vol.State == "available")) { - return vol, PIVolumeProvisioningDone, nil + return vol, Attr_VolumeProvisioningDone, nil } return vol, "detaching", nil