fix: re-implement acl part in top level

feat: implement tf identity
This commit is contained in:
Marcel S. Henselin 2025-12-30 16:30:18 +01:00
parent 1027643f95
commit 29f693308e
6 changed files with 116 additions and 36 deletions

View file

@ -17,6 +17,26 @@ import (
// checks if the CreateInstanceRequestPayload type satisfies the MappedNullable interface at compile time
var _ MappedNullable = &CreateInstanceRequestPayload{}
/*
types and functions for acl
*/
// isArray
type CreateInstanceRequestPayloadGetAclAttributeType = *[]string
type CreateInstanceRequestPayloadGetAclArgType = []string
type CreateInstanceRequestPayloadGetAclRetType = []string
func getCreateInstanceRequestPayloadGetAclAttributeTypeOk(arg CreateInstanceRequestPayloadGetAclAttributeType) (ret CreateInstanceRequestPayloadGetAclRetType, ok bool) {
if arg == nil {
return ret, false
}
return *arg, true
}
func setCreateInstanceRequestPayloadGetAclAttributeType(arg *CreateInstanceRequestPayloadGetAclAttributeType, val CreateInstanceRequestPayloadGetAclRetType) {
*arg = &val
}
/*
types and functions for backupSchedule
*/
@ -203,6 +223,7 @@ type CreateInstanceRequestPayloadGetVersionRetType = string
// CreateInstanceRequestPayload struct for CreateInstanceRequestPayload
type CreateInstanceRequestPayload struct {
Acl CreateInstanceRequestPayloadGetAclAttributeType `json:"acl" required:"true"`
// The schedule for on what time and how often the database backup will be created. The schedule is written as a cron schedule.
// REQUIRED
BackupSchedule CreateInstanceRequestPayloadGetBackupScheduleAttributeType `json:"backupSchedule" required:"true"`

View file

@ -1,5 +1,3 @@
// Copyright (c) STACKIT
package wait
import (
@ -14,15 +12,18 @@ import (
"github.com/stackitcloud/stackit-sdk-go/core/wait"
)
// "READY" "PENDING" "PROGRESSING" "FAILURE" "UNKNOWN" "TERMINATING"
const (
InstanceStateEmpty = ""
InstanceStateProgressing = "Progressing"
InstanceStateSuccess = "Ready"
InstanceStateFailed = "Failure"
InstanceStateDeleted = "Deleted"
InstanceStateProgressing = "PROGRESSING"
InstanceStateSuccess = "READY"
InstanceStateFailed = "FAILURE"
InstanceStateTerminating = "TERMINATING"
InstanceStateUnknown = "UNKNOWN"
InstanceStatePending = "PENDING"
)
// Interface needed for tests
// APIClientInstanceInterface Interface needed for tests
type APIClientInstanceInterface interface {
GetInstanceRequestExecute(ctx context.Context, projectId, region, instanceId string) (
*postgresflex.GetInstanceResponse,
@ -30,12 +31,14 @@ type APIClientInstanceInterface interface {
)
ListUsersRequestExecute(
ctx context.Context, projectId string, region string,
ctx context.Context,
projectId string,
region string,
instanceId string,
) (*postgresflex.ListUserResponse, error)
}
// Interface needed for tests
// APIClientUserInterface Interface needed for tests
type APIClientUserInterface interface {
GetUserRequestExecute(ctx context.Context, projectId, region, instanceId string, userId int64) (
*postgresflex.GetUserResponse,
@ -66,6 +69,10 @@ func CreateInstanceWaitHandler(
return true, s, fmt.Errorf("instance with id %s has unexpected status %s", instanceId, *s.Status)
case InstanceStateEmpty:
return false, nil, nil
case InstanceStatePending:
return false, nil, nil
case InstanceStateUnknown:
return false, nil, nil
case InstanceStateProgressing:
return false, nil, nil
case InstanceStateSuccess:
@ -80,7 +87,10 @@ func CreateInstanceWaitHandler(
instanceCreated = true
instanceGetResponse = s
case InstanceStateFailed:
return true, s, fmt.Errorf("create failed for instance with id %s", instanceId)
tflog.Warn(ctx, fmt.Sprintf("Wait handler got status FAILURE for instance: %s", instanceId))
return false, nil, nil
// API responds with FAILURE for some seconds and then the instance goes to READY
// return true, s, fmt.Errorf("create failed for instance with id %s", instanceId)
}
}
@ -90,7 +100,7 @@ func CreateInstanceWaitHandler(
if err == nil {
return true, instanceGetResponse, nil
}
oapiErr, ok := err.(*oapierror.GenericOpenAPIError) //nolint:errorlint //complaining that error.As should be used to catch wrapped errors, but this error should not be wrapped
oapiErr, ok := err.(*oapierror.GenericOpenAPIError) // nolint:errorlint //complaining that error.As should be used to catch wrapped errors, but this error should not be wrapped
if !ok {
return false, nil, err
}
@ -127,7 +137,9 @@ func PartialUpdateInstanceWaitHandler(
return true, s, fmt.Errorf("instance with id %s has unexpected status %s", instanceId, *s.Status)
case InstanceStateEmpty:
return false, nil, nil
case InstanceStateProgressing:
case InstanceStateUnknown:
return false, nil, nil
case InstanceStateTerminating:
return false, nil, nil
case InstanceStateSuccess:
return true, s, nil
@ -155,20 +167,31 @@ func DeleteInstanceWaitHandler(
if s == nil || s.Id == nil || *s.Id != instanceId || s.Status == nil {
return false, nil, nil
}
switch *s.Status {
default:
return true, nil, fmt.Errorf("instance with id %s has unexpected status %s", instanceId, *s.Status)
case InstanceStateSuccess:
return false, nil, nil
case InstanceStateDeleted:
return true, nil, nil
// TODO - maybe we want to validate status if no 404 error (only unknown or terminating should be valid)
//switch *s.Status {
//default:
// return true, nil, fmt.Errorf("instance with id %s has unexpected status %s", instanceId, *s.Status)
//case InstanceStateSuccess:
// return false, nil, nil
//case InstanceStateTerminating:
// return false, nil, nil
//}
// TODO - add tflog for ignored cases
oapiErr, ok := err.(*oapierror.GenericOpenAPIError) //nolint:errorlint //complaining that error.As should be used to catch wrapped errors, but this error should not be wrapped
if !ok {
return false, nil, err
}
if oapiErr.StatusCode != 404 {
return false, nil, err
}
return true, nil, nil
},
)
handler.SetTimeout(5 * time.Minute)
return handler
}
// TODO - remove
// ForceDeleteInstanceWaitHandler will wait for instance deletion
func ForceDeleteInstanceWaitHandler(
ctx context.Context,