Skip to content

Commit

Permalink
Add wait in creation for user tags
Browse files Browse the repository at this point in the history
  • Loading branch information
Alexander-Kita committed Oct 1, 2024
1 parent 099366b commit 3540346
Show file tree
Hide file tree
Showing 2 changed files with 30 additions and 0 deletions.
16 changes: 16 additions & 0 deletions ibm/service/power/resource_ibm_pi_capture.go
Original file line number Diff line number Diff line change
Expand Up @@ -192,6 +192,22 @@ func resourceIBMPICaptureCreate(ctx context.Context, d *schema.ResourceData, met
if err != nil {
return diag.FromErr(err)
}

if _, ok := d.GetOk(Arg_UserTags); ok && capturedestination != cloudStorageDestination {
imageClient := st.NewIBMPIImageClient(ctx, sess, cloudInstanceID)
imagedata, err := imageClient.Get(capturename)
if err != nil {
log.Printf("Error on get of ibm pi capture (%s) while applying pi_user_tags: %s", capturename, err)
}
if imagedata.Crn != "" {
oldList, newList := d.GetChange(Arg_UserTags)
err = flex.UpdateGlobalTagsUsingCRN(oldList, newList, meta, string(imagedata.Crn), "", UserTagType)
if err != nil {
log.Printf("Error on update of pi capture (%s) pi_user_tags during creation: %s", *imagedata.ImageID, err)
}
}
}

return resourceIBMPICaptureRead(ctx, d, meta)
}

Expand Down
14 changes: 14 additions & 0 deletions ibm/service/power/resource_ibm_pi_instance.go
Original file line number Diff line number Diff line change
Expand Up @@ -484,6 +484,20 @@ func resourceIBMPIInstanceCreate(ctx context.Context, d *schema.ResourceData, me
}
}
}

// If user tags are set, make sure tags are set correctly before moving on
if _, ok := d.GetOk(Arg_UserTags); ok {
oldList, newList := d.GetChange(Arg_UserTags)
for _, s := range *pvmList {
if s.Crn != "" {
err := flex.UpdateGlobalTagsUsingCRN(oldList, newList, meta, string(s.Crn), "", UserTagType)
if err != nil {
log.Printf("Error on update of pi instance (%s) pi_user_tags during creation: %s", *s.PvmInstanceID, err)
}
}
}
}

// If virtual optical device provided then update cloud initialization
if vod, ok := d.GetOk(Arg_VirtualOpticalDevice); ok {
for _, s := range *pvmList {
Expand Down

0 comments on commit 3540346

Please sign in to comment.