Skip to content
Merged
Show file tree
Hide file tree
Changes from all 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
10 changes: 7 additions & 3 deletions stackit/internal/services/resourcemanager/folder/resource.go
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ import (
"github.com/stackitcloud/terraform-provider-stackit/stackit/internal/conversion"
"github.com/stackitcloud/terraform-provider-stackit/stackit/internal/core"
resourcemanagerUtils "github.com/stackitcloud/terraform-provider-stackit/stackit/internal/services/resourcemanager/utils"
"github.com/stackitcloud/terraform-provider-stackit/stackit/internal/utils"
"github.com/stackitcloud/terraform-provider-stackit/stackit/internal/validate"
)

Expand Down Expand Up @@ -220,6 +221,9 @@ func (r *folderResource) Create(ctx context.Context, req resource.CreateRequest,

// This sleep is currently needed due to the IAM Cache.
time.Sleep(10 * time.Second)
ctx = utils.SetAndLogStateFields(ctx, &resp.Diagnostics, &resp.State, map[string]any{
"container_id": *folderCreateResp.ContainerId,
})

folderGetResponse, err := r.client.GetFolderDetails(ctx, *folderCreateResp.ContainerId).Execute()
if err != nil {
Expand Down Expand Up @@ -376,9 +380,9 @@ func (r *folderResource) ImportState(ctx context.Context, req resource.ImportSta
return
}

ctx = tflog.SetField(ctx, "container_id", req.ID)

resp.Diagnostics.Append(resp.State.SetAttribute(ctx, path.Root("container_id"), req.ID)...)
ctx = utils.SetAndLogStateFields(ctx, &resp.Diagnostics, &resp.State, map[string]any{
"container_id": req.ID,
})
tflog.Info(ctx, "Resource Manager folder state imported")
}

Expand Down
18 changes: 15 additions & 3 deletions stackit/internal/services/resourcemanager/project/resource.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ import (
"time"

resourcemanagerUtils "github.com/stackitcloud/terraform-provider-stackit/stackit/internal/services/resourcemanager/utils"
"github.com/stackitcloud/terraform-provider-stackit/stackit/internal/utils"

"github.com/google/uuid"
"github.com/hashicorp/terraform-plugin-framework-validators/mapvalidator"
Expand Down Expand Up @@ -216,7 +217,18 @@ func (r *projectResource) Create(ctx context.Context, req resource.CreateRequest

ctx = core.LogResponse(ctx)

if createResp.ContainerId == nil {
core.LogAndAddError(ctx, &resp.Diagnostics, "Error creating project", "Got empty container id")
return
}
respContainerId := *createResp.ContainerId
// Write id attributes to state before polling via the wait handler - just in case anything goes wrong during the wait handler
ctx = utils.SetAndLogStateFields(ctx, &resp.Diagnostics, &resp.State, map[string]any{
"container_id": respContainerId,
})
if resp.Diagnostics.HasError() {
return
}

// If the request has not been processed yet and the containerId doesn't exist,
// the waiter will fail with authentication error, so wait some time before checking the creation
Expand Down Expand Up @@ -379,9 +391,9 @@ func (r *projectResource) ImportState(ctx context.Context, req resource.ImportSt
return
}

ctx = tflog.SetField(ctx, "container_id", req.ID)

resp.Diagnostics.Append(resp.State.SetAttribute(ctx, path.Root("container_id"), req.ID)...)
ctx = utils.SetAndLogStateFields(ctx, &resp.Diagnostics, &resp.State, map[string]any{
"container_id": req.ID,
})
tflog.Info(ctx, "Resource Manager Project state imported")
}

Expand Down
Loading