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
5 changes: 5 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,8 @@
## Release (2025-MM-DD)
- `iaas`: [v0.30.0](services/iaas/CHANGELOG.md#v0300)
- **Feature:** Add waiter to wait until the preconditions for network area deletion are met: `ReadyForNetworkAreaDeletionWaitHandler`


## Release (2025-09-11)
- `cdn`: [v1.5.0](services/cdn/CHANGELOG.md#v150)
- **Feature:** Added Attribute `LogSink` to `ConfigPatch`
Expand Down
3 changes: 3 additions & 0 deletions services/iaas/CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,6 @@
## v0.30.0
- **Feature:** Add waiter to wait until the preconditions for network area deletion are met: `ReadyForNetworkAreaDeletionWaitHandler`

## v0.29.2
- Increase Timeouts for network area and network wait handlers to 30 minutes

Expand Down
2 changes: 1 addition & 1 deletion services/iaas/VERSION
Original file line number Diff line number Diff line change
@@ -1 +1 @@
v0.29.2
v0.30.0
1 change: 1 addition & 0 deletions services/iaas/go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ go 1.21
require (
github.com/google/go-cmp v0.7.0
github.com/stackitcloud/stackit-sdk-go/core v0.17.3
github.com/stackitcloud/stackit-sdk-go/services/resourcemanager v0.17.1
)

require (
Expand Down
2 changes: 2 additions & 0 deletions services/iaas/go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -6,3 +6,5 @@ github.com/google/uuid v1.6.0 h1:NIvaJDMOsjHA8n1jAhLSgzrAzy1Hgr+hNrb57e+94F0=
github.com/google/uuid v1.6.0/go.mod h1:TIyPZe4MgqvfeYDBFedMoGGpEw/LqOeaOT+nhxU+yHo=
github.com/stackitcloud/stackit-sdk-go/core v0.17.3 h1:GsZGmRRc/3GJLmCUnsZswirr5wfLRrwavbnL/renOqg=
github.com/stackitcloud/stackit-sdk-go/core v0.17.3/go.mod h1:HBCXJGPgdRulplDzhrmwC+Dak9B/x0nzNtmOpu+1Ahg=
github.com/stackitcloud/stackit-sdk-go/services/resourcemanager v0.17.1 h1:r7oaINTwLmIG31AaqKTuQHHFF8YNuYGzi+46DOuSjw4=
github.com/stackitcloud/stackit-sdk-go/services/resourcemanager v0.17.1/go.mod h1:ipcrPRbwfQXHH18dJVfY7K5ujHF5dTT6isoXgmA7YwQ=
56 changes: 54 additions & 2 deletions services/iaas/wait/wait.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,15 +2,16 @@ package wait

import (
"context"
"errors"
"fmt"
"net/http"
"strings"
"time"

"errors"

"github.com/stackitcloud/stackit-sdk-go/core/oapierror"
"github.com/stackitcloud/stackit-sdk-go/core/wait"
"github.com/stackitcloud/stackit-sdk-go/services/iaas"
"github.com/stackitcloud/stackit-sdk-go/services/resourcemanager"
)

const (
Expand Down Expand Up @@ -48,6 +49,7 @@ const (
// Interfaces needed for tests
type APIClientInterface interface {
GetNetworkAreaExecute(ctx context.Context, organizationId, areaId string) (*iaas.NetworkArea, error)
ListNetworkAreaProjectsExecute(ctx context.Context, organizationId, areaId string) (*iaas.ProjectListResponse, error)
GetProjectRequestExecute(ctx context.Context, projectId string, requestId string) (*iaas.Request, error)
GetNetworkExecute(ctx context.Context, projectId, networkId string) (*iaas.Network, error)
GetVolumeExecute(ctx context.Context, projectId string, volumeId string) (*iaas.Volume, error)
Expand All @@ -58,6 +60,10 @@ type APIClientInterface interface {
GetSnapshotExecute(ctx context.Context, projectId string, snapshotId string) (*iaas.Snapshot, error)
}

type ResourceManagerAPIClientInterface interface {
GetProjectExecute(ctx context.Context, id string) (*resourcemanager.GetProjectResponse, error)
}

// CreateNetworkAreaWaitHandler will wait for network area creation
func CreateNetworkAreaWaitHandler(ctx context.Context, a APIClientInterface, organizationId, areaId string) *wait.AsyncActionHandler[iaas.NetworkArea] {
handler := wait.New(func() (waitFinished bool, response *iaas.NetworkArea, err error) {
Expand Down Expand Up @@ -98,6 +104,52 @@ func UpdateNetworkAreaWaitHandler(ctx context.Context, a APIClientInterface, org
return handler
}

// ReadyForNetworkAreaDeletionWaitHandler will wait until a deletion of network area is possible
// Workaround for https://github.com/stackitcloud/terraform-provider-stackit/issues/907.
// When the deletion for a project is triggered, the backend starts a workflow in the background which cleans up all resources
// within a project and deletes the project in each service. When the project is attached to an SNA, the SNA can't be
// deleted until the workflow inform the IaaS-API that the project is deleted.
func ReadyForNetworkAreaDeletionWaitHandler(ctx context.Context, a APIClientInterface, r ResourceManagerAPIClientInterface, organizationId, areaId string) *wait.AsyncActionHandler[iaas.ProjectListResponse] {
handler := wait.New(func() (waitFinished bool, response *iaas.ProjectListResponse, err error) {
projectList, err := a.ListNetworkAreaProjectsExecute(ctx, organizationId, areaId)
if err != nil {
return false, projectList, err
}
if projectList == nil || projectList.Items == nil {
return false, nil, fmt.Errorf("read failed for projects in network area with id %s, the response is not valid: the items are missing", areaId)
}
if len(*projectList.Items) == 0 {
return true, projectList, nil
}
var activeProjects, forbiddenProjects []string
for _, projectId := range *projectList.Items {
_, err := r.GetProjectExecute(ctx, projectId)
if err == nil {
activeProjects = append(activeProjects, projectId)
continue
}
var oapiErr *oapierror.GenericOpenAPIError
ok := errors.As(err, &oapiErr)
if !ok {
return false, nil, fmt.Errorf("could not convert error to oapierror.GenericOpenAPIError")
}
// The resource manager api responds with StatusForbidden(=403) when a project is deleted or if the project does not exist
if oapiErr.StatusCode == http.StatusNotFound || oapiErr.StatusCode == http.StatusForbidden {
forbiddenProjects = append(forbiddenProjects, projectId)
}
}
if len(activeProjects) > 0 {
return false, nil, fmt.Errorf("network area with id %s has still active projects: %s", areaId, strings.Join(activeProjects, ","))
}
if len(forbiddenProjects) > 0 {
return false, nil, nil
}
return true, projectList, nil
})
handler.SetTimeout(1 * time.Minute)
return handler
}

// DeleteNetworkAreaWaitHandler will wait for network area deletion
func DeleteNetworkAreaWaitHandler(ctx context.Context, a APIClientInterface, organizationId, areaId string) *wait.AsyncActionHandler[iaas.NetworkArea] {
handler := wait.New(func() (waitFinished bool, response *iaas.NetworkArea, err error) {
Expand Down
Loading
Loading