Skip to content
Open
Show file tree
Hide file tree
Changes from 11 commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ go 1.24.2
require (
github.com/IBM-Cloud/bluemix-go v0.0.0-20251001005609-37dbcddbe871
github.com/IBM-Cloud/container-services-go-sdk v0.0.0-20240725064144-454a2ae23113
github.com/IBM-Cloud/power-go-client v1.13.0
github.com/IBM-Cloud/power-go-client v1.14.0-beta13
github.com/IBM/appconfiguration-go-admin-sdk v0.5.1
github.com/IBM/appid-management-go-sdk v0.0.0-20210908164609-dd0e0eaf732f
github.com/IBM/cloud-databases-go-sdk v0.8.1
Expand Down
6 changes: 2 additions & 4 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -93,8 +93,8 @@ github.com/IBM-Cloud/bluemix-go v0.0.0-20251001005609-37dbcddbe871 h1:0NrvGUWBoG
github.com/IBM-Cloud/bluemix-go v0.0.0-20251001005609-37dbcddbe871/go.mod h1:lU1/3aolIs4y062yTTokFEiIEssAZqqjdj/5qvkBeq8=
github.com/IBM-Cloud/container-services-go-sdk v0.0.0-20240725064144-454a2ae23113 h1:f2Erqfea1dKpaTFagTJM6W/wnD3JGq/Vn9URh8nuRwk=
github.com/IBM-Cloud/container-services-go-sdk v0.0.0-20240725064144-454a2ae23113/go.mod h1:xUQL9SGAjoZFd4GNjrjjtEpjpkgU7RFXRyHesbKTjiY=
github.com/IBM-Cloud/power-go-client v1.13.0 h1:TqxPlkJe0VkNdV9hYOD5NRepxEFhhyKXWXfg22x2zhU=
github.com/IBM-Cloud/power-go-client v1.13.0/go.mod h1:SpTK1ttW8bfMNUVQS8qOEuWn2KOkzaCLyzfze8MG1JE=
github.com/IBM-Cloud/power-go-client v1.14.0-beta13 h1:PHvq/pUaMOvlsHTrPZOsdJWmTZEqUug+TZ0NzerLta0=
github.com/IBM-Cloud/power-go-client v1.14.0-beta13/go.mod h1:SpTK1ttW8bfMNUVQS8qOEuWn2KOkzaCLyzfze8MG1JE=
github.com/IBM-Cloud/softlayer-go v1.0.5-tf h1:koUAyF9b6X78lLLruGYPSOmrfY2YcGYKOj/Ug9nbKNw=
github.com/IBM-Cloud/softlayer-go v1.0.5-tf/go.mod h1:6HepcfAXROz0Rf63krk5hPZyHT6qyx2MNvYyHof7ik4=
github.com/IBM/appconfiguration-go-admin-sdk v0.5.1 h1:EAotl3yQ/u5u/uBryySJMm0COgsYhtNzQ1g2IChtlE0=
Expand Down Expand Up @@ -125,8 +125,6 @@ github.com/IBM/go-sdk-core/v5 v5.6.3/go.mod h1:tt/B9rxLkRtglE7pvqLuYikgCXaZFL3bt
github.com/IBM/go-sdk-core/v5 v5.9.5/go.mod h1:YlOwV9LeuclmT/qi/LAK2AsobbAP42veV0j68/rlZsE=
github.com/IBM/go-sdk-core/v5 v5.10.2/go.mod h1:WZPFasUzsKab/2mzt29xPcfruSk5js2ywAPwW4VJjdI=
github.com/IBM/go-sdk-core/v5 v5.17.4/go.mod h1:KsAAI7eStAWwQa4F96MLy+whYSh39JzNjklZRbN/8ns=
github.com/IBM/go-sdk-core/v5 v5.20.1 h1:dzeyifh1kfRLw8VfAIIS5okZYuqLTqplPZP/Kcsgdlo=
github.com/IBM/go-sdk-core/v5 v5.20.1/go.mod h1:Q3BYO6iDA2zweQPDGbNTtqft5tDcEpm6RTuqMlPcvbw=
github.com/IBM/go-sdk-core/v5 v5.21.0 h1:DUnYhvC4SoC8T84rx5omnhY3+xcQg/Whyoa3mDPIMkk=
github.com/IBM/go-sdk-core/v5 v5.21.0/go.mod h1:Q3BYO6iDA2zweQPDGbNTtqft5tDcEpm6RTuqMlPcvbw=
github.com/IBM/ibm-backup-recovery-sdk-go v1.0.3 h1:9TZHocmCfgmF8TGVrpP1kFyQbjcqLNW7+bM07lefpKQ=
Expand Down
1 change: 1 addition & 0 deletions ibm/acctest/acctest.go
Original file line number Diff line number Diff line change
Expand Up @@ -261,6 +261,7 @@ var (
Pi_spp_placement_group_id string
Pi_storage_connection string
Pi_target_storage_tier string
Pi_target_crn string
Pi_virtual_serial_number string
Pi_volume_clone_task_id string
Pi_volume_group_id string
Expand Down
2 changes: 2 additions & 0 deletions ibm/service/power/ibm_pi_constants.go
Original file line number Diff line number Diff line change
Expand Up @@ -167,6 +167,7 @@ const (
Arg_StorageType = "pi_storage_type"
Arg_SysType = "pi_sys_type"
Arg_Target = "pi_target"
Arg_TargetCRN = "pi_target_crn"
Arg_TargetStorageTier = "pi_target_storage_tier"
Arg_Type = "pi_type"
Arg_UserData = "pi_user_data"
Expand Down Expand Up @@ -451,6 +452,7 @@ const (
Attr_ReplicationPoolMap = "replication_pool_map"
Attr_ReplicationSites = "replication_sites"
Attr_ReplicationStatus = "replication_status"
Attr_ReplicationTargetCRN = "replication_target_crn"
Attr_ReplicationType = "replication_type"
Attr_ReservedCore = "reserved_core"
Attr_ReservedCores = "reserved_cores"
Expand Down
91 changes: 63 additions & 28 deletions ibm/service/power/resource_ibm_pi_volume.go
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ func ResourceIBMPIVolume() *schema.Resource {
Delete: schema.DefaultTimeout(10 * time.Minute),
},
CustomizeDiff: customdiff.Sequence(
func(_ context.Context, diff *schema.ResourceDiff, v interface{}) error {
func(_ context.Context, diff *schema.ResourceDiff, v any) error {
return flex.ResourcePowerUserTagsCustomizeDiff(diff)
},
),
Expand Down Expand Up @@ -249,10 +249,12 @@ func ResourceIBMPIVolumeValidator() *validate.ResourceValidator {
return &ibmPIVolumeResourceValidator
}

func resourceIBMPIVolumeCreate(ctx context.Context, d *schema.ResourceData, meta interface{}) diag.Diagnostics {
func resourceIBMPIVolumeCreate(ctx context.Context, d *schema.ResourceData, meta any) diag.Diagnostics {
sess, err := meta.(conns.ClientSession).IBMPISession()
if err != nil {
return diag.FromErr(err)
tfErr := flex.TerraformErrorf(err, fmt.Sprintf("IBMPISession failed: %s", err.Error()), "ibm_pi_volume", "create")
log.Printf("[DEBUG]\n%s", tfErr.GetDebugMessage())
return tfErr.GetDiag()
}

name := d.Get(Arg_VolumeName).(string)
Expand Down Expand Up @@ -283,7 +285,10 @@ func resourceIBMPIVolumeCreate(ctx context.Context, d *schema.ResourceData, meta
if d.Get(Arg_ReplicationEnabled).(bool) {
body.ReplicationSites = flex.FlattenSet(v.(*schema.Set))
} else {
return diag.Errorf("Replication (%s) must be enabled if replication sites are specified.", Arg_ReplicationEnabled)
err = flex.FmtErrorf("Replication (%s) must be enabled if replication sites are specified.", Arg_ReplicationEnabled)
tfErr := flex.TerraformErrorf(err, fmt.Sprintf("operation failed: %s", err.Error()), "ibm_pi_volume", "create")
log.Printf("[DEBUG]\n%s", tfErr.GetDebugMessage())
return tfErr.GetDiag()
}
}
if ap, ok := d.GetOk(Arg_AffinityPolicy); ok {
Expand All @@ -301,11 +306,11 @@ func resourceIBMPIVolumeCreate(ctx context.Context, d *schema.ResourceData, meta
}
} else {
if avs, ok := d.GetOk(Arg_AntiAffinityVolumes); ok {
afvols := flex.ExpandStringList(avs.([]interface{}))
afvols := flex.ExpandStringList(avs.([]any))
body.AntiAffinityVolumes = afvols
}
if ais, ok := d.GetOk(Arg_AntiAffinityInstances); ok {
afinss := flex.ExpandStringList(ais.([]interface{}))
afinss := flex.ExpandStringList(ais.([]any))
body.AntiAffinityPVMInstances = afinss
}
}
Expand All @@ -318,15 +323,19 @@ func resourceIBMPIVolumeCreate(ctx context.Context, d *schema.ResourceData, meta
client := instance.NewIBMPIVolumeClient(ctx, sess, cloudInstanceID)
vol, err := client.CreateVolume(body)
if err != nil {
return diag.FromErr(err)
tfErr := flex.TerraformErrorf(err, fmt.Sprintf("CreateVolume failed: %s", err.Error()), "ibm_pi_volume", "create")
log.Printf("[DEBUG]\n%s", tfErr.GetDebugMessage())
return tfErr.GetDiag()
}

volumeid := *vol.VolumeID
d.SetId(fmt.Sprintf("%s/%s", cloudInstanceID, volumeid))

_, err = isWaitForIBMPIVolumeAvailable(ctx, client, volumeid, d.Timeout(schema.TimeoutCreate))
if err != nil {
return diag.FromErr(err)
tfErr := flex.TerraformErrorf(err, fmt.Sprintf("isWaitForIBMPIVolumeAvailable failed: %s", err.Error()), "ibm_pi_volume", "create")
log.Printf("[DEBUG]\n%s", tfErr.GetDebugMessage())
return tfErr.GetDiag()
}

if _, ok := d.GetOk(Arg_UserTags); ok {
Expand All @@ -340,22 +349,28 @@ func resourceIBMPIVolumeCreate(ctx context.Context, d *schema.ResourceData, meta
return resourceIBMPIVolumeRead(ctx, d, meta)
}

func resourceIBMPIVolumeRead(ctx context.Context, d *schema.ResourceData, meta interface{}) diag.Diagnostics {
func resourceIBMPIVolumeRead(ctx context.Context, d *schema.ResourceData, meta any) diag.Diagnostics {
sess, err := meta.(conns.ClientSession).IBMPISession()
if err != nil {
return diag.FromErr(err)
tfErr := flex.TerraformErrorf(err, fmt.Sprintf("IBMPISession failed: %s", err.Error()), "ibm_pi_volume", "read")
log.Printf("[DEBUG]\n%s", tfErr.GetDebugMessage())
return tfErr.GetDiag()
}

cloudInstanceID, volumeID, err := splitID(d.Id())
if err != nil {
return diag.FromErr(err)
tfErr := flex.TerraformErrorf(err, fmt.Sprintf("splitID failed: %s", err.Error()), "ibm_pi_volume", "read")
log.Printf("[DEBUG]\n%s", tfErr.GetDebugMessage())
return tfErr.GetDiag()
}

client := instance.NewIBMPIVolumeClient(ctx, sess, cloudInstanceID)

vol, err := client.Get(volumeID)
if err != nil {
return diag.FromErr(err)
tfErr := flex.TerraformErrorf(err, fmt.Sprintf("Get failed: %s", err.Error()), "ibm_pi_volume", "read")
log.Printf("[DEBUG]\n%s", tfErr.GetDebugMessage())
return tfErr.GetDiag()
}
d.Set(Arg_CloudInstanceID, cloudInstanceID)
if vol.VolumeID != nil {
Expand Down Expand Up @@ -399,15 +414,19 @@ func resourceIBMPIVolumeRead(ctx context.Context, d *schema.ResourceData, meta i
return nil
}

func resourceIBMPIVolumeUpdate(ctx context.Context, d *schema.ResourceData, meta interface{}) diag.Diagnostics {
func resourceIBMPIVolumeUpdate(ctx context.Context, d *schema.ResourceData, meta any) diag.Diagnostics {
sess, err := meta.(conns.ClientSession).IBMPISession()
if err != nil {
return diag.FromErr(err)
tfErr := flex.TerraformErrorf(err, fmt.Sprintf("IBMPISession failed: %s", err.Error()), "ibm_pi_volume", "update")
log.Printf("[DEBUG]\n%s", tfErr.GetDebugMessage())
return tfErr.GetDiag()
}

cloudInstanceID, volumeID, err := splitID(d.Id())
if err != nil {
return diag.FromErr(err)
tfErr := flex.TerraformErrorf(err, fmt.Sprintf("splitID failed: %s", err.Error()), "ibm_pi_volume", "update")
log.Printf("[DEBUG]\n%s", tfErr.GetDebugMessage())
return tfErr.GetDiag()
}

client := instance.NewIBMPIVolumeClient(ctx, sess, cloudInstanceID)
Expand All @@ -425,11 +444,15 @@ func resourceIBMPIVolumeUpdate(ctx context.Context, d *schema.ResourceData, meta
}
volrequest, err := client.UpdateVolume(volumeID, body)
if err != nil {
return diag.FromErr(err)
tfErr := flex.TerraformErrorf(err, fmt.Sprintf("UpdateVolume failed: %s", err.Error()), "ibm_pi_volume", "update")
log.Printf("[DEBUG]\n%s", tfErr.GetDebugMessage())
return tfErr.GetDiag()
}
_, err = isWaitForIBMPIVolumeAvailable(ctx, client, *volrequest.VolumeID, d.Timeout(schema.TimeoutUpdate))
if err != nil {
return diag.FromErr(err)
tfErr := flex.TerraformErrorf(err, fmt.Sprintf("isWaitForIBMPIVolumeAvailable failed: %s", err.Error()), "ibm_pi_volume", "update")
log.Printf("[DEBUG]\n%s", tfErr.GetDebugMessage())
return tfErr.GetDiag()
}

if d.HasChanges(Arg_ReplicationEnabled, Arg_VolumeType) {
Expand All @@ -442,11 +465,15 @@ func resourceIBMPIVolumeUpdate(ctx context.Context, d *schema.ResourceData, meta
}
err = client.VolumeAction(volumeID, &volActionBody)
if err != nil {
return diag.FromErr(err)
tfErr := flex.TerraformErrorf(err, fmt.Sprintf("VolumeAction failed: %s", err.Error()), "ibm_pi_volume", "update")
log.Printf("[DEBUG]\n%s", tfErr.GetDebugMessage())
return tfErr.GetDiag()
}
_, err = isWaitForIBMPIVolumeAvailable(ctx, client, volumeID, d.Timeout(schema.TimeoutUpdate))
if err != nil {
return diag.FromErr(err)
tfErr := flex.TerraformErrorf(err, fmt.Sprintf("isWaitForIBMPIVolumeAvailable failed: %s", err.Error()), "ibm_pi_volume", "update")
log.Printf("[DEBUG]\n%s", tfErr.GetDebugMessage())
return tfErr.GetDiag()
}
}

Expand All @@ -463,31 +490,39 @@ func resourceIBMPIVolumeUpdate(ctx context.Context, d *schema.ResourceData, meta
return resourceIBMPIVolumeRead(ctx, d, meta)
}

func resourceIBMPIVolumeDelete(ctx context.Context, d *schema.ResourceData, meta interface{}) diag.Diagnostics {
func resourceIBMPIVolumeDelete(ctx context.Context, d *schema.ResourceData, meta any) diag.Diagnostics {
sess, err := meta.(conns.ClientSession).IBMPISession()
if err != nil {
return diag.FromErr(err)
tfErr := flex.TerraformErrorf(err, fmt.Sprintf("IBMPISession failed: %s", err.Error()), "ibm_pi_volume", "delete")
log.Printf("[DEBUG]\n%s", tfErr.GetDebugMessage())
return tfErr.GetDiag()
}

cloudInstanceID, volumeID, err := splitID(d.Id())
if err != nil {
return diag.FromErr(err)
tfErr := flex.TerraformErrorf(err, fmt.Sprintf("splitID failed: %s", err.Error()), "ibm_pi_volume", "delete")
log.Printf("[DEBUG]\n%s", tfErr.GetDebugMessage())
return tfErr.GetDiag()
}

client := instance.NewIBMPIVolumeClient(ctx, sess, cloudInstanceID)
err = client.DeleteVolume(volumeID)
if err != nil {
return diag.FromErr(err)
tfErr := flex.TerraformErrorf(err, fmt.Sprintf("DeleteVolume failed: %s", err.Error()), "ibm_pi_volume", "delete")
log.Printf("[DEBUG]\n%s", tfErr.GetDebugMessage())
return tfErr.GetDiag()
}
_, err = isWaitForIBMPIVolumeDeleted(ctx, client, volumeID, d.Timeout(schema.TimeoutDelete))
if err != nil {
return diag.FromErr(err)
tfErr := flex.TerraformErrorf(err, fmt.Sprintf("isWaitForIBMPIVolumeDeleted failed: %s", err.Error()), "ibm_pi_volume", "delete")
log.Printf("[DEBUG]\n%s", tfErr.GetDebugMessage())
return tfErr.GetDiag()
}
d.SetId("")
return nil
}

func isWaitForIBMPIVolumeAvailable(ctx context.Context, client *instance.IBMPIVolumeClient, id string, timeout time.Duration) (interface{}, error) {
func isWaitForIBMPIVolumeAvailable(ctx context.Context, client *instance.IBMPIVolumeClient, id string, timeout time.Duration) (any, error) {
log.Printf("Waiting for Volume (%s) to be available.", id)

stateConf := &retry.StateChangeConf{
Expand All @@ -503,7 +538,7 @@ func isWaitForIBMPIVolumeAvailable(ctx context.Context, client *instance.IBMPIVo
}

func isIBMPIVolumeRefreshFunc(client *instance.IBMPIVolumeClient, id string) retry.StateRefreshFunc {
return func() (interface{}, string, error) {
return func() (any, string, error) {
vol, err := client.Get(id)
if err != nil {
return nil, "", err
Expand All @@ -517,7 +552,7 @@ func isIBMPIVolumeRefreshFunc(client *instance.IBMPIVolumeClient, id string) ret
}
}

func isWaitForIBMPIVolumeDeleted(ctx context.Context, client *instance.IBMPIVolumeClient, id string, timeout time.Duration) (interface{}, error) {
func isWaitForIBMPIVolumeDeleted(ctx context.Context, client *instance.IBMPIVolumeClient, id string, timeout time.Duration) (any, error) {
stateConf := &retry.StateChangeConf{
Pending: []string{State_Deleting, State_Creating},
Target: []string{State_Deleted},
Expand All @@ -530,7 +565,7 @@ func isWaitForIBMPIVolumeDeleted(ctx context.Context, client *instance.IBMPIVolu
}

func isIBMPIVolumeDeleteRefreshFunc(client *instance.IBMPIVolumeClient, id string) retry.StateRefreshFunc {
return func() (interface{}, string, error) {
return func() (any, string, error) {
vol, err := client.Get(id)
if err != nil {
uErr := errors.Unwrap(err)
Expand Down
Loading
Loading