From 8933960cd9b294f820fef42bfee698dce076c169 Mon Sep 17 00:00:00 2001 From: Alexander Kita Date: Wed, 30 Oct 2024 10:02:41 -0500 Subject: [PATCH] Add check for same instance ID --- .../resource_ibm_pi_virtual_serial_number.go | 38 ++++++++++--------- 1 file changed, 20 insertions(+), 18 deletions(-) diff --git a/ibm/service/power/resource_ibm_pi_virtual_serial_number.go b/ibm/service/power/resource_ibm_pi_virtual_serial_number.go index 811b154524..f181588793 100644 --- a/ibm/service/power/resource_ibm_pi_virtual_serial_number.go +++ b/ibm/service/power/resource_ibm_pi_virtual_serial_number.go @@ -124,28 +124,30 @@ func resourceIBMPIVirtualSerialNumberCreate(ctx context.Context, d *schema.Resou return diag.FromErr(err) } - serialNumber := d.Get(Arg_Serial).(string) - addBody := &models.AddServerVirtualSerialNumber{ - Serial: &serialNumber, - } - if v, ok := d.GetOk(Arg_Description); ok { - addBody.Description = v.(string) - } - err = client.PVMInstanceAttachVSN(pvmInstanceIdArg, addBody) - if err != nil { - return diag.FromErr(err) - } - - _, err = isWaitForPIInstanceStopped(ctx, instanceClient, pvmInstanceIdArg, d.Timeout(schema.TimeoutCreate)) - if err != nil { - return diag.FromErr(err) - } + if oldPvmInstanceId == "" { + serialNumber := d.Get(Arg_Serial).(string) + addBody := &models.AddServerVirtualSerialNumber{ + Serial: &serialNumber, + } + if v, ok := d.GetOk(Arg_Description); ok { + addBody.Description = v.(string) + } + err = client.PVMInstanceAttachVSN(pvmInstanceIdArg, addBody) + if err != nil { + return diag.FromErr(err) + } - if restartInstance { - err = startLparAfterVSNChange(ctx, instanceClient, pvmInstanceIdArg, d.Timeout(schema.TimeoutCreate)) + _, err = isWaitForPIInstanceStopped(ctx, instanceClient, pvmInstanceIdArg, d.Timeout(schema.TimeoutCreate)) if err != nil { return diag.FromErr(err) } + + if restartInstance { + err = startLparAfterVSNChange(ctx, instanceClient, pvmInstanceIdArg, d.Timeout(schema.TimeoutCreate)) + if err != nil { + return diag.FromErr(err) + } + } } if vsnArg == AutoAssign {