Skip to content

Commit 16d8c67

Browse files
Add check to pvm assignment in create
1 parent 73f7fe0 commit 16d8c67

File tree

2 files changed

+9
-6
lines changed

2 files changed

+9
-6
lines changed

ibm/service/power/resource_ibm_pi_virtual_serial_number.go

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -83,20 +83,21 @@ func resourceIBMPIVirtualSerialNumberCreate(ctx context.Context, d *schema.Resou
8383
}
8484

8585
serialString := ""
86+
oldPvmInstanceId := ""
8687
if vsnArg != AutoAssign {
8788
vsn, err := client.Get(vsnArg)
8889
if err != nil {
8990
return diag.FromErr(err)
9091
}
92+
oldPvmInstanceId = *vsn.PvmInstanceID
9193
if v, ok := d.GetOk(Arg_Description); ok {
9294
description := v.(string)
9395
if description != *vsn.Description {
94-
pvmInstanceId := *vsn.PvmInstanceID
95-
if pvmInstanceId != "" {
96+
if oldPvmInstanceId != "" {
9697
updateBody := &models.UpdateServerVirtualSerialNumber{
9798
Description: &description,
9899
}
99-
_, err := client.PVMInstanceUpdateVSN(pvmInstanceId, updateBody)
100+
_, err := client.PVMInstanceUpdateVSN(oldPvmInstanceId, updateBody)
100101
if err != nil {
101102
return diag.FromErr(err)
102103
}
@@ -116,6 +117,9 @@ func resourceIBMPIVirtualSerialNumberCreate(ctx context.Context, d *schema.Resou
116117

117118
if pvmInstanceId, ok := d.GetOk(Arg_PVMInstanceId); ok {
118119
pvmInstanceIdArg := pvmInstanceId.(string)
120+
if oldPvmInstanceId != "" && pvmInstanceIdArg != oldPvmInstanceId {
121+
return diag.Errorf("please detach virtual serial number from current pvm instance before specifying %s in creation", Arg_PVMInstanceId)
122+
}
119123
instanceClient := instance.NewIBMPIInstanceClient(ctx, sess, cloudInstanceID)
120124
restartInstance, err := stopLparForVSNChange(ctx, instanceClient, pvmInstanceIdArg, d.Timeout(schema.TimeoutCreate))
121125
if err != nil {
@@ -127,8 +131,7 @@ func resourceIBMPIVirtualSerialNumberCreate(ctx context.Context, d *schema.Resou
127131
Serial: &serialNumber,
128132
}
129133
if v, ok := d.GetOk(Arg_Description); ok {
130-
description := v.(string)
131-
addBody.Description = description
134+
addBody.Description = v.(string)
132135
}
133136
err = client.PVMInstanceAttachVSN(pvmInstanceIdArg, addBody)
134137
if err != nil {

website/docs/r/pi_virtual_serial_number.html.markdown

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -52,7 +52,7 @@ Review the argument references that you can specify for your resource.
5252

5353
- `pi_cloud_instance_id` - (Required, String) The GUID of the service instance associated with an account.
5454
- `pi_description` - (Optional, String) Desired description for virtual serial number. Cannot set description back to empty once set.
55-
- `pi_instance_id` - (Optional, String) Power instance ID to assign created or existing virtual serial number to.
55+
- `pi_instance_id` - (Optional, String) Power instance ID to assign created or existing virtual serial number to. Must unassign from previous power instance if different than current assignment.
5656
- `pi_retain_virtual_serial_number` - (Optional, Boolean) Indicates whether to reserve or delete virtual serial number when detached from power instance during delete. Required with `pi_instance_id`.
5757
- `pi_serial` - (Required, String) Virtual serial number of existing serial. Cannot use 'auto-assign' unless `pi_instance_id` is specified.
5858

0 commit comments

Comments
 (0)