From e2815a83f61f26037564f998e41b15006a2211e7 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ville=20V=C3=A4lim=C3=A4ki?= <110451292+villevsv-upcloud@users.noreply.github.com> Date: Mon, 23 Oct 2023 20:31:42 +0300 Subject: [PATCH] fix(managedobjectstorage): populate users on update only if changed (#423) --- CHANGELOG.md | 3 +++ .../managed_object_storage.go | 19 +++++++++++++++++-- 2 files changed, 20 insertions(+), 2 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index a021aea5..51e3aaff 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -5,6 +5,9 @@ See updating [Changelog example here](https://keepachangelog.com/en/1.0.0/) ## [Unreleased] +### Fixed +- managed_object_storage: `managed_object_storage` update to retain service users in all cases + ## [3.0.0] - 2023-10-23 ### Added diff --git a/internal/service/managedobjectstorage/managed_object_storage.go b/internal/service/managedobjectstorage/managed_object_storage.go index 67c873ac..1e1240a9 100644 --- a/internal/service/managedobjectstorage/managed_object_storage.go +++ b/internal/service/managedobjectstorage/managed_object_storage.go @@ -241,8 +241,8 @@ func resourceManagedObjectStorageUpdate(ctx context.Context, d *schema.ResourceD req.Networks = &networks } - userReqs := make([]request.ManagedObjectStorageUser, 0) if d.HasChange("users") { + userReqs := make([]request.ManagedObjectStorageUser, 0) users := d.Get("users") for _, user := range users.(*schema.Set).List() { r := request.ManagedObjectStorageUser{ @@ -250,13 +250,28 @@ func resourceManagedObjectStorageUpdate(ctx context.Context, d *schema.ResourceD } userReqs = append(userReqs, r) } + req.Users = &userReqs } - req.Users = &userReqs storage, err := svc.ModifyManagedObjectStorage(ctx, req) if err != nil { return diag.FromErr(err) } + waitReq := &request.WaitForManagedObjectStorageOperationalStateRequest{ + DesiredState: upcloud.ManagedObjectStorageOperationalStateRunning, + Timeout: time.Minute * 20, + UUID: storage.UUID, + } + + if storage.ConfiguredStatus == upcloud.ManagedObjectStorageConfiguredStatusStopped { + waitReq.DesiredState = upcloud.ManagedObjectStorageOperationalStateStopped + } + + storage, err = svc.WaitForManagedObjectStorageOperationalState(ctx, waitReq) + if err != nil { + return diag.FromErr(err) + } + return setManagedObjectStorageData(d, storage) }