chore: fixing tests
This commit is contained in:
parent
a861661036
commit
feef0b61d6
14 changed files with 1452 additions and 561 deletions
|
|
@ -1,5 +1,3 @@
|
|||
// Copyright (c) STACKIT
|
||||
|
||||
/*
|
||||
PostgreSQL Flex API
|
||||
|
||||
|
|
|
|||
|
|
@ -1,5 +1,3 @@
|
|||
// Copyright (c) STACKIT
|
||||
|
||||
package wait
|
||||
|
||||
import (
|
||||
|
|
@ -29,7 +27,7 @@ type APIClientInstanceInterface interface {
|
|||
|
||||
// Interface needed for tests
|
||||
type APIClientUserInterface interface {
|
||||
GetUserExecute(ctx context.Context, projectId, region, instanceId, userId string) (*postgresflex.GetUserResponse, error)
|
||||
GetUserRequestExecute(ctx context.Context, projectId, region, instanceId string, userId int64) (*postgresflex.GetUserResponse, error)
|
||||
}
|
||||
|
||||
// CreateInstanceWaitHandler will wait for instance creation
|
||||
|
|
@ -152,9 +150,9 @@ func ForceDeleteInstanceWaitHandler(ctx context.Context, a APIClientInstanceInte
|
|||
}
|
||||
|
||||
// DeleteUserWaitHandler will wait for delete
|
||||
func DeleteUserWaitHandler(ctx context.Context, a APIClientUserInterface, projectId, region, instanceId, userId string) *wait.AsyncActionHandler[struct{}] {
|
||||
func DeleteUserWaitHandler(ctx context.Context, a APIClientUserInterface, projectId, region, instanceId string, userId int64) *wait.AsyncActionHandler[struct{}] {
|
||||
handler := wait.New(func() (waitFinished bool, response *struct{}, err error) {
|
||||
_, err = a.GetUserExecute(ctx, projectId, region, instanceId, userId)
|
||||
_, err = a.GetUserRequestExecute(ctx, projectId, region, instanceId, userId)
|
||||
if err == nil {
|
||||
return false, nil, nil
|
||||
}
|
||||
|
|
|
|||
|
|
@ -1,5 +1,3 @@
|
|||
// Copyright (c) STACKIT
|
||||
|
||||
package wait
|
||||
|
||||
import (
|
||||
|
|
@ -10,7 +8,7 @@ import (
|
|||
"github.com/google/go-cmp/cmp"
|
||||
"github.com/stackitcloud/stackit-sdk-go/core/oapierror"
|
||||
"github.com/stackitcloud/stackit-sdk-go/core/utils"
|
||||
"github.com/stackitcloud/stackit-sdk-go/services/postgresflex"
|
||||
postgresflex "github.com/stackitcloud/terraform-provider-stackit/pkg/postgresflexalpha"
|
||||
)
|
||||
|
||||
// Used for testing instance operations
|
||||
|
|
@ -22,7 +20,7 @@ type apiClientInstanceMocked struct {
|
|||
usersGetErrorStatus int
|
||||
}
|
||||
|
||||
func (a *apiClientInstanceMocked) GetInstanceExecute(_ context.Context, _, _, _ string) (*postgresflex.InstanceResponse, error) {
|
||||
func (a *apiClientInstanceMocked) GetInstanceRequestExecute(_ context.Context, _, _, _ string) (*postgresflex.GetInstanceResponse, error) {
|
||||
if a.instanceGetFails {
|
||||
return nil, &oapierror.GenericOpenAPIError{
|
||||
StatusCode: 500,
|
||||
|
|
@ -35,15 +33,13 @@ func (a *apiClientInstanceMocked) GetInstanceExecute(_ context.Context, _, _, _
|
|||
}
|
||||
}
|
||||
|
||||
return &postgresflex.InstanceResponse{
|
||||
Item: &postgresflex.Instance{
|
||||
Id: &a.instanceId,
|
||||
Status: &a.instanceState,
|
||||
},
|
||||
return &postgresflex.GetInstanceResponse{
|
||||
Id: &a.instanceId,
|
||||
Status: postgresflex.GetInstanceResponseGetStatusAttributeType(&a.instanceState),
|
||||
}, nil
|
||||
}
|
||||
|
||||
func (a *apiClientInstanceMocked) ListUsersExecute(_ context.Context, _, _, _ string) (*postgresflex.ListUsersResponse, error) {
|
||||
func (a *apiClientInstanceMocked) ListUsersRequestExecute(_ context.Context, _, _, _ string) (*postgresflex.ListUserResponse, error) {
|
||||
if a.usersGetErrorStatus != 0 {
|
||||
return nil, &oapierror.GenericOpenAPIError{
|
||||
StatusCode: a.usersGetErrorStatus,
|
||||
|
|
@ -51,20 +47,22 @@ func (a *apiClientInstanceMocked) ListUsersExecute(_ context.Context, _, _, _ st
|
|||
}
|
||||
|
||||
aux := int64(0)
|
||||
return &postgresflex.ListUsersResponse{
|
||||
Count: &aux,
|
||||
Items: &[]postgresflex.ListUsersResponseItem{},
|
||||
return &postgresflex.ListUserResponse{
|
||||
Pagination: &postgresflex.Pagination{
|
||||
TotalRows: &aux,
|
||||
},
|
||||
Users: &[]postgresflex.ListUser{},
|
||||
}, nil
|
||||
}
|
||||
|
||||
// Used for testing user operations
|
||||
type apiClientUserMocked struct {
|
||||
getFails bool
|
||||
userId string
|
||||
userId int64
|
||||
isUserDeleted bool
|
||||
}
|
||||
|
||||
func (a *apiClientUserMocked) GetUserExecute(_ context.Context, _, _, _, _ string) (*postgresflex.GetUserResponse, error) {
|
||||
func (a *apiClientUserMocked) GetUserRequestExecute(_ context.Context, _, _, _ string, _ int64) (*postgresflex.GetUserResponse, error) {
|
||||
if a.getFails {
|
||||
return nil, &oapierror.GenericOpenAPIError{
|
||||
StatusCode: 500,
|
||||
|
|
@ -78,9 +76,7 @@ func (a *apiClientUserMocked) GetUserExecute(_ context.Context, _, _, _, _ strin
|
|||
}
|
||||
|
||||
return &postgresflex.GetUserResponse{
|
||||
Item: &postgresflex.UserResponse{
|
||||
Id: &a.userId,
|
||||
},
|
||||
Id: &a.userId,
|
||||
}, nil
|
||||
}
|
||||
|
||||
|
|
@ -155,13 +151,11 @@ func TestCreateInstanceWaitHandler(t *testing.T) {
|
|||
usersGetErrorStatus: tt.usersGetErrorStatus,
|
||||
}
|
||||
|
||||
var wantRes *postgresflex.InstanceResponse
|
||||
var wantRes *postgresflex.GetInstanceResponse
|
||||
if tt.wantResp {
|
||||
wantRes = &postgresflex.InstanceResponse{
|
||||
Item: &postgresflex.Instance{
|
||||
Id: &instanceId,
|
||||
Status: utils.Ptr(tt.instanceState),
|
||||
},
|
||||
wantRes = &postgresflex.GetInstanceResponse{
|
||||
Id: &instanceId,
|
||||
Status: postgresflex.GetInstanceResponseGetStatusAttributeType(utils.Ptr(tt.instanceState)),
|
||||
}
|
||||
}
|
||||
|
||||
|
|
@ -232,13 +226,11 @@ func TestUpdateInstanceWaitHandler(t *testing.T) {
|
|||
instanceGetFails: tt.instanceGetFails,
|
||||
}
|
||||
|
||||
var wantRes *postgresflex.InstanceResponse
|
||||
var wantRes *postgresflex.GetInstanceResponse
|
||||
if tt.wantResp {
|
||||
wantRes = &postgresflex.InstanceResponse{
|
||||
Item: &postgresflex.Instance{
|
||||
Id: &instanceId,
|
||||
Status: utils.Ptr(tt.instanceState),
|
||||
},
|
||||
wantRes = &postgresflex.GetInstanceResponse{
|
||||
Id: &instanceId,
|
||||
Status: postgresflex.GetInstanceResponseGetStatusAttributeType(utils.Ptr(tt.instanceState)),
|
||||
}
|
||||
}
|
||||
|
||||
|
|
@ -377,7 +369,7 @@ func TestDeleteUserWaitHandler(t *testing.T) {
|
|||
}
|
||||
for _, tt := range tests {
|
||||
t.Run(tt.desc, func(t *testing.T) {
|
||||
userId := "foo-bar"
|
||||
userId := int64(1001)
|
||||
|
||||
apiClient := &apiClientUserMocked{
|
||||
getFails: tt.getFails,
|
||||
|
|
|
|||
|
|
@ -217,7 +217,7 @@ type DefaultApi interface {
|
|||
@param region The region which should be addressed
|
||||
@return ApiGetFlavorsRequestRequest
|
||||
*/
|
||||
GetFlavorsRequest(ctx context.Context, projectId string, region string) ApiGetFlavorsRequestRequest
|
||||
GetFlavorsRequest(ctx context.Context, projectId, region string, page, size *int64, sort FlavorSort) ApiGetFlavorsRequestRequest
|
||||
/*
|
||||
GetFlavorsRequestExecute executes the request
|
||||
|
||||
|
|
@ -227,7 +227,7 @@ type DefaultApi interface {
|
|||
@return GetFlavorsResponse
|
||||
|
||||
*/
|
||||
GetFlavorsRequestExecute(ctx context.Context, projectId string, region string) (*GetFlavorsResponse, error)
|
||||
GetFlavorsRequestExecute(ctx context.Context, projectId, region string, page, size *int64, sort FlavorSort) (*GetFlavorsResponse, error)
|
||||
/*
|
||||
GetInstanceRequest Get Specific Instance
|
||||
Get information about a specific available instance
|
||||
|
|
@ -2700,21 +2700,27 @@ Get all available flavors for a project.
|
|||
@param region The region which should be addressed
|
||||
@return ApiGetFlavorsRequestRequest
|
||||
*/
|
||||
func (a *APIClient) GetFlavorsRequest(ctx context.Context, projectId string, region string) ApiGetFlavorsRequestRequest {
|
||||
func (a *APIClient) GetFlavorsRequest(ctx context.Context, projectId, region string, page, size *int64, sort FlavorSort) ApiGetFlavorsRequestRequest {
|
||||
return GetFlavorsRequestRequest{
|
||||
apiService: a.defaultApi,
|
||||
ctx: ctx,
|
||||
apiService: a.defaultApi,
|
||||
projectId: projectId,
|
||||
region: region,
|
||||
page: page,
|
||||
size: size,
|
||||
sort: &sort,
|
||||
}
|
||||
}
|
||||
|
||||
func (a *APIClient) GetFlavorsRequestExecute(ctx context.Context, projectId string, region string) (*GetFlavorsResponse, error) {
|
||||
func (a *APIClient) GetFlavorsRequestExecute(ctx context.Context, projectId, region string, page, size *int64, sort FlavorSort) (*GetFlavorsResponse, error) {
|
||||
r := GetFlavorsRequestRequest{
|
||||
apiService: a.defaultApi,
|
||||
ctx: ctx,
|
||||
projectId: projectId,
|
||||
region: region,
|
||||
page: page,
|
||||
size: size,
|
||||
sort: &sort,
|
||||
}
|
||||
return r.Execute()
|
||||
}
|
||||
|
|
|
|||
|
|
@ -1,5 +1,3 @@
|
|||
// Copyright (c) STACKIT
|
||||
|
||||
/*
|
||||
STACKIT MSSQL Service API
|
||||
|
||||
|
|
@ -586,7 +584,9 @@ func Test_sqlserverflexalpha_DefaultApiService(t *testing.T) {
|
|||
projectId := projectIdValue
|
||||
region := regionValue
|
||||
|
||||
resp, reqErr := apiClient.GetFlavorsRequest(context.Background(), projectId, region).Execute()
|
||||
page := int64(1)
|
||||
size := int64(10)
|
||||
resp, reqErr := apiClient.GetFlavorsRequest(context.Background(), projectId, region, &page, &size, FLAVORSORT_ID_DESC).Execute()
|
||||
|
||||
if reqErr != nil {
|
||||
t.Fatalf("error in call: %v", reqErr)
|
||||
|
|
|
|||
|
|
@ -21,6 +21,22 @@ var _ MappedNullable = &GetBackupResponse{}
|
|||
types and functions for completionTime
|
||||
*/
|
||||
|
||||
//// isAny
|
||||
//type GetBackupResponseGetCompletionTimeAttributeType = any
|
||||
//type GetBackupResponseGetCompletionTimeArgType = any
|
||||
//type GetBackupResponseGetCompletionTimeRetType = any
|
||||
//
|
||||
//func getGetBackupResponseGetCompletionTimeAttributeTypeOk(arg GetBackupResponseGetCompletionTimeAttributeType) (ret GetBackupResponseGetCompletionTimeRetType, ok bool) {
|
||||
// if arg == nil {
|
||||
// return ret, false
|
||||
// }
|
||||
// return *arg, true
|
||||
//}
|
||||
//
|
||||
//func setGetBackupResponseGetCompletionTimeAttributeType(arg *GetBackupResponseGetCompletionTimeAttributeType, val GetBackupResponseGetCompletionTimeRetType) {
|
||||
// *arg = &val
|
||||
//}
|
||||
|
||||
// isModel
|
||||
type GetBackupResponseGetCompletionTimeAttributeType = *string
|
||||
type GetBackupResponseGetCompletionTimeArgType = string
|
||||
|
|
@ -41,6 +57,22 @@ func setGetBackupResponseGetCompletionTimeAttributeType(arg *GetBackupResponseGe
|
|||
types and functions for id
|
||||
*/
|
||||
|
||||
//// isAny
|
||||
//type GetBackupResponseGetIdAttributeType = any
|
||||
//type GetBackupResponseGetIdArgType = any
|
||||
//type GetBackupResponseGetIdRetType = any
|
||||
//
|
||||
//func getGetBackupResponseGetIdAttributeTypeOk(arg GetBackupResponseGetIdAttributeType) (ret GetBackupResponseGetIdRetType, ok bool) {
|
||||
// if arg == nil {
|
||||
// return ret, false
|
||||
// }
|
||||
// return *arg, true
|
||||
//}
|
||||
//
|
||||
//func setGetBackupResponseGetIdAttributeType(arg *GetBackupResponseGetIdAttributeType, val GetBackupResponseGetIdRetType) {
|
||||
// *arg = &val
|
||||
//}
|
||||
|
||||
// isModel
|
||||
type GetBackupResponseGetIdAttributeType = *int64
|
||||
type GetBackupResponseGetIdArgType = int64
|
||||
|
|
@ -60,6 +92,23 @@ func setGetBackupResponseGetIdAttributeType(arg *GetBackupResponseGetIdAttribute
|
|||
/*
|
||||
types and functions for name
|
||||
*/
|
||||
|
||||
//// isAny
|
||||
//type GetBackupResponseGetNameAttributeType = any
|
||||
//type GetBackupResponseGetNameArgType = any
|
||||
//type GetBackupResponseGetNameRetType = any
|
||||
//
|
||||
//func getGetBackupResponseGetNameAttributeTypeOk(arg GetBackupResponseGetNameAttributeType) (ret GetBackupResponseGetNameRetType, ok bool) {
|
||||
// if arg == nil {
|
||||
// return ret, false
|
||||
// }
|
||||
// return *arg, true
|
||||
//}
|
||||
//
|
||||
//func setGetBackupResponseGetNameAttributeType(arg *GetBackupResponseGetNameAttributeType, val GetBackupResponseGetNameRetType) {
|
||||
// *arg = &val
|
||||
//}
|
||||
|
||||
// isModel
|
||||
type GetBackupResponseGetNameAttributeType = *string
|
||||
type GetBackupResponseGetNameArgType = string
|
||||
|
|
@ -80,6 +129,22 @@ func setGetBackupResponseGetNameAttributeType(arg *GetBackupResponseGetNameAttri
|
|||
types and functions for retainedUntil
|
||||
*/
|
||||
|
||||
//// isAny
|
||||
//type GetBackupResponseGetRetainedUntilAttributeType = any
|
||||
//type GetBackupResponseGetRetainedUntilArgType = any
|
||||
//type GetBackupResponseGetRetainedUntilRetType = any
|
||||
//
|
||||
//func getGetBackupResponseGetRetainedUntilAttributeTypeOk(arg GetBackupResponseGetRetainedUntilAttributeType) (ret GetBackupResponseGetRetainedUntilRetType, ok bool) {
|
||||
// if arg == nil {
|
||||
// return ret, false
|
||||
// }
|
||||
// return *arg, true
|
||||
//}
|
||||
//
|
||||
//func setGetBackupResponseGetRetainedUntilAttributeType(arg *GetBackupResponseGetRetainedUntilAttributeType, val GetBackupResponseGetRetainedUntilRetType) {
|
||||
// *arg = &val
|
||||
//}
|
||||
|
||||
// isModel
|
||||
type GetBackupResponseGetRetainedUntilAttributeType = *string
|
||||
type GetBackupResponseGetRetainedUntilArgType = string
|
||||
|
|
@ -100,6 +165,22 @@ func setGetBackupResponseGetRetainedUntilAttributeType(arg *GetBackupResponseGet
|
|||
types and functions for size
|
||||
*/
|
||||
|
||||
//// isAny
|
||||
//type GetBackupResponseGetSizeAttributeType = any
|
||||
//type GetBackupResponseGetSizeArgType = any
|
||||
//type GetBackupResponseGetSizeRetType = any
|
||||
//
|
||||
//func getGetBackupResponseGetSizeAttributeTypeOk(arg GetBackupResponseGetSizeAttributeType) (ret GetBackupResponseGetSizeRetType, ok bool) {
|
||||
// if arg == nil {
|
||||
// return ret, false
|
||||
// }
|
||||
// return *arg, true
|
||||
//}
|
||||
//
|
||||
//func setGetBackupResponseGetSizeAttributeType(arg *GetBackupResponseGetSizeAttributeType, val GetBackupResponseGetSizeRetType) {
|
||||
// *arg = &val
|
||||
//}
|
||||
|
||||
// isModel
|
||||
type GetBackupResponseGetSizeAttributeType = *int64
|
||||
type GetBackupResponseGetSizeArgType = int64
|
||||
|
|
@ -120,6 +201,22 @@ func setGetBackupResponseGetSizeAttributeType(arg *GetBackupResponseGetSizeAttri
|
|||
types and functions for type
|
||||
*/
|
||||
|
||||
//// isAny
|
||||
//type GetBackupResponseGetTypeAttributeType = any
|
||||
//type GetBackupResponseGetTypeArgType = any
|
||||
//type GetBackupResponseGetTypeRetType = any
|
||||
//
|
||||
//func getGetBackupResponseGetTypeAttributeTypeOk(arg GetBackupResponseGetTypeAttributeType) (ret GetBackupResponseGetTypeRetType, ok bool) {
|
||||
// if arg == nil {
|
||||
// return ret, false
|
||||
// }
|
||||
// return *arg, true
|
||||
//}
|
||||
//
|
||||
//func setGetBackupResponseGetTypeAttributeType(arg *GetBackupResponseGetTypeAttributeType, val GetBackupResponseGetTypeRetType) {
|
||||
// *arg = &val
|
||||
//}
|
||||
|
||||
// isModel
|
||||
type GetBackupResponseGetTypeAttributeType = *string
|
||||
type GetBackupResponseGetTypeArgType = string
|
||||
|
|
|
|||
|
|
@ -21,6 +21,22 @@ var _ MappedNullable = &ListBackup{}
|
|||
types and functions for completionTime
|
||||
*/
|
||||
|
||||
//// isAny
|
||||
//type ListBackupGetCompletionTimeAttributeType = any
|
||||
//type ListBackupGetCompletionTimeArgType = any
|
||||
//type ListBackupGetCompletionTimeRetType = any
|
||||
//
|
||||
//func getListBackupGetCompletionTimeAttributeTypeOk(arg ListBackupGetCompletionTimeAttributeType) (ret ListBackupGetCompletionTimeRetType, ok bool) {
|
||||
// if arg == nil {
|
||||
// return ret, false
|
||||
// }
|
||||
// return *arg, true
|
||||
//}
|
||||
//
|
||||
//func setListBackupGetCompletionTimeAttributeType(arg *ListBackupGetCompletionTimeAttributeType, val ListBackupGetCompletionTimeRetType) {
|
||||
// *arg = &val
|
||||
//}
|
||||
|
||||
// isModel
|
||||
type ListBackupGetCompletionTimeAttributeType = *string
|
||||
type ListBackupGetCompletionTimeArgType = string
|
||||
|
|
@ -41,6 +57,22 @@ func setListBackupGetCompletionTimeAttributeType(arg *ListBackupGetCompletionTim
|
|||
types and functions for id
|
||||
*/
|
||||
|
||||
// isAny
|
||||
//type ListBackupGetIdAttributeType = any
|
||||
//type ListBackupGetIdArgType = any
|
||||
//type ListBackupGetIdRetType = any
|
||||
//
|
||||
//func getListBackupGetIdAttributeTypeOk(arg ListBackupGetIdAttributeType) (ret ListBackupGetIdRetType, ok bool) {
|
||||
// if arg == nil {
|
||||
// return ret, false
|
||||
// }
|
||||
// return *arg, true
|
||||
//}
|
||||
//
|
||||
//func setListBackupGetIdAttributeType(arg *ListBackupGetIdAttributeType, val ListBackupGetIdRetType) {
|
||||
// *arg = &val
|
||||
//}
|
||||
|
||||
// isModel
|
||||
type ListBackupGetIdAttributeType = *int64
|
||||
type ListBackupGetIdArgType = int64
|
||||
|
|
@ -61,6 +93,22 @@ func setListBackupGetIdAttributeType(arg *ListBackupGetIdAttributeType, val List
|
|||
types and functions for name
|
||||
*/
|
||||
|
||||
//// isAny
|
||||
//type ListBackupGetNameAttributeType = any
|
||||
//type ListBackupGetNameArgType = any
|
||||
//type ListBackupGetNameRetType = any
|
||||
//
|
||||
//func getListBackupGetNameAttributeTypeOk(arg ListBackupGetNameAttributeType) (ret ListBackupGetNameRetType, ok bool) {
|
||||
// if arg == nil {
|
||||
// return ret, false
|
||||
// }
|
||||
// return *arg, true
|
||||
//}
|
||||
//
|
||||
//func setListBackupGetNameAttributeType(arg *ListBackupGetNameAttributeType, val ListBackupGetNameRetType) {
|
||||
// *arg = &val
|
||||
//}
|
||||
|
||||
// isModel
|
||||
type ListBackupGetNameAttributeType = *string
|
||||
type ListBackupGetNameArgType = string
|
||||
|
|
@ -81,6 +129,22 @@ func setListBackupGetNameAttributeType(arg *ListBackupGetNameAttributeType, val
|
|||
types and functions for retainedUntil
|
||||
*/
|
||||
|
||||
//// isAny
|
||||
//type ListBackupGetRetainedUntilAttributeType = any
|
||||
//type ListBackupGetRetainedUntilArgType = any
|
||||
//type ListBackupGetRetainedUntilRetType = any
|
||||
//
|
||||
//func getListBackupGetRetainedUntilAttributeTypeOk(arg ListBackupGetRetainedUntilAttributeType) (ret ListBackupGetRetainedUntilRetType, ok bool) {
|
||||
// if arg == nil {
|
||||
// return ret, false
|
||||
// }
|
||||
// return *arg, true
|
||||
//}
|
||||
//
|
||||
//func setListBackupGetRetainedUntilAttributeType(arg *ListBackupGetRetainedUntilAttributeType, val ListBackupGetRetainedUntilRetType) {
|
||||
// *arg = &val
|
||||
//}
|
||||
|
||||
// isModel
|
||||
type ListBackupGetRetainedUntilAttributeType = *string
|
||||
type ListBackupGetRetainedUntilArgType = string
|
||||
|
|
@ -97,6 +161,26 @@ func setListBackupGetRetainedUntilAttributeType(arg *ListBackupGetRetainedUntilA
|
|||
*arg = &val
|
||||
}
|
||||
|
||||
/*
|
||||
types and functions for size
|
||||
*/
|
||||
|
||||
//// isAny
|
||||
//type ListBackupGetSizeAttributeType = any
|
||||
//type ListBackupGetSizeArgType = any
|
||||
//type ListBackupGetSizeRetType = any
|
||||
//
|
||||
//func getListBackupGetSizeAttributeTypeOk(arg ListBackupGetSizeAttributeType) (ret ListBackupGetSizeRetType, ok bool) {
|
||||
// if arg == nil {
|
||||
// return ret, false
|
||||
// }
|
||||
// return *arg, true
|
||||
//}
|
||||
//
|
||||
//func setListBackupGetSizeAttributeType(arg *ListBackupGetSizeAttributeType, val ListBackupGetSizeRetType) {
|
||||
// *arg = &val
|
||||
//}
|
||||
|
||||
// isModel
|
||||
type ListBackupGetSizeAttributeType = *int64
|
||||
type ListBackupGetSizeArgType = int64
|
||||
|
|
@ -113,6 +197,26 @@ func setListBackupGetSizeAttributeType(arg *ListBackupGetSizeAttributeType, val
|
|||
*arg = &val
|
||||
}
|
||||
|
||||
/*
|
||||
types and functions for type
|
||||
*/
|
||||
|
||||
//// isAny
|
||||
//type ListBackupGetTypeAttributeType = any
|
||||
//type ListBackupGetTypeArgType = any
|
||||
//type ListBackupGetTypeRetType = any
|
||||
//
|
||||
//func getListBackupGetTypeAttributeTypeOk(arg ListBackupGetTypeAttributeType) (ret ListBackupGetTypeRetType, ok bool) {
|
||||
// if arg == nil {
|
||||
// return ret, false
|
||||
// }
|
||||
// return *arg, true
|
||||
//}
|
||||
//
|
||||
//func setListBackupGetTypeAttributeType(arg *ListBackupGetTypeAttributeType, val ListBackupGetTypeRetType) {
|
||||
// *arg = &val
|
||||
//}
|
||||
|
||||
// isModel
|
||||
type ListBackupGetTypeAttributeType = *string
|
||||
type ListBackupGetTypeArgType = string
|
||||
|
|
|
|||
|
|
@ -1,5 +1,3 @@
|
|||
// Copyright (c) STACKIT
|
||||
|
||||
package wait
|
||||
|
||||
import (
|
||||
|
|
@ -12,7 +10,7 @@ import (
|
|||
|
||||
"github.com/stackitcloud/stackit-sdk-go/core/oapierror"
|
||||
"github.com/stackitcloud/stackit-sdk-go/core/wait"
|
||||
"github.com/stackitcloud/stackit-sdk-go/services/sqlserverflex"
|
||||
sqlserverflex "github.com/stackitcloud/terraform-provider-stackit/pkg/sqlserverflexalpha"
|
||||
)
|
||||
|
||||
const (
|
||||
|
|
@ -25,20 +23,20 @@ const (
|
|||
|
||||
// Interface needed for tests
|
||||
type APIClientInstanceInterface interface {
|
||||
GetInstanceExecute(ctx context.Context, projectId, instanceId, region string) (*sqlserverflex.GetInstanceResponse, error)
|
||||
GetInstanceRequestExecute(ctx context.Context, projectId, region, instanceId string) (*sqlserverflex.GetInstanceResponse, error)
|
||||
}
|
||||
|
||||
// CreateInstanceWaitHandler will wait for instance creation
|
||||
func CreateInstanceWaitHandler(ctx context.Context, a APIClientInstanceInterface, projectId, instanceId, region string) *wait.AsyncActionHandler[sqlserverflex.GetInstanceResponse] {
|
||||
handler := wait.New(func() (waitFinished bool, response *sqlserverflex.GetInstanceResponse, err error) {
|
||||
s, err := a.GetInstanceExecute(ctx, projectId, instanceId, region)
|
||||
s, err := a.GetInstanceRequestExecute(ctx, projectId, region, instanceId)
|
||||
if err != nil {
|
||||
return false, nil, err
|
||||
}
|
||||
if s == nil || s.Item == nil || s.Item.Id == nil || *s.Item.Id != instanceId || s.Item.Status == nil {
|
||||
if s == nil || s.Id == nil || *s.Id != instanceId || s.Status == nil {
|
||||
return false, nil, nil
|
||||
}
|
||||
switch strings.ToLower(*s.Item.Status) {
|
||||
switch strings.ToLower(string(*s.Status)) {
|
||||
case strings.ToLower(InstanceStateSuccess):
|
||||
return true, s, nil
|
||||
case strings.ToLower(InstanceStateUnknown), strings.ToLower(InstanceStateFailed):
|
||||
|
|
@ -55,14 +53,14 @@ func CreateInstanceWaitHandler(ctx context.Context, a APIClientInstanceInterface
|
|||
// UpdateInstanceWaitHandler will wait for instance update
|
||||
func UpdateInstanceWaitHandler(ctx context.Context, a APIClientInstanceInterface, projectId, instanceId, region string) *wait.AsyncActionHandler[sqlserverflex.GetInstanceResponse] {
|
||||
handler := wait.New(func() (waitFinished bool, response *sqlserverflex.GetInstanceResponse, err error) {
|
||||
s, err := a.GetInstanceExecute(ctx, projectId, instanceId, region)
|
||||
s, err := a.GetInstanceRequestExecute(ctx, projectId, region, instanceId)
|
||||
if err != nil {
|
||||
return false, nil, err
|
||||
}
|
||||
if s == nil || s.Item == nil || s.Item.Id == nil || *s.Item.Id != instanceId || s.Item.Status == nil {
|
||||
if s == nil || s.Id == nil || *s.Id != instanceId || s.Status == nil {
|
||||
return false, nil, nil
|
||||
}
|
||||
switch strings.ToLower(*s.Item.Status) {
|
||||
switch strings.ToLower(string(*s.Status)) {
|
||||
case strings.ToLower(InstanceStateSuccess):
|
||||
return true, s, nil
|
||||
case strings.ToLower(InstanceStateUnknown), strings.ToLower(InstanceStateFailed):
|
||||
|
|
@ -84,7 +82,7 @@ func PartialUpdateInstanceWaitHandler(ctx context.Context, a APIClientInstanceIn
|
|||
// DeleteInstanceWaitHandler will wait for instance deletion
|
||||
func DeleteInstanceWaitHandler(ctx context.Context, a APIClientInstanceInterface, projectId, instanceId, region string) *wait.AsyncActionHandler[struct{}] {
|
||||
handler := wait.New(func() (waitFinished bool, response *struct{}, err error) {
|
||||
_, err = a.GetInstanceExecute(ctx, projectId, instanceId, region)
|
||||
_, err = a.GetInstanceRequestExecute(ctx, projectId, region, instanceId)
|
||||
if err == nil {
|
||||
return false, nil, nil
|
||||
}
|
||||
|
|
|
|||
|
|
@ -1,5 +1,3 @@
|
|||
// Copyright (c) STACKIT
|
||||
|
||||
package wait
|
||||
|
||||
import (
|
||||
|
|
@ -10,7 +8,7 @@ import (
|
|||
"github.com/google/go-cmp/cmp"
|
||||
"github.com/stackitcloud/stackit-sdk-go/core/oapierror"
|
||||
"github.com/stackitcloud/stackit-sdk-go/core/utils"
|
||||
"github.com/stackitcloud/stackit-sdk-go/services/sqlserverflex"
|
||||
sqlserverflex "github.com/stackitcloud/terraform-provider-stackit/pkg/sqlserverflexalpha"
|
||||
)
|
||||
|
||||
// Used for testing instance operations
|
||||
|
|
@ -21,7 +19,7 @@ type apiClientInstanceMocked struct {
|
|||
instanceGetFails bool
|
||||
}
|
||||
|
||||
func (a *apiClientInstanceMocked) GetInstanceExecute(_ context.Context, _, _, _ string) (*sqlserverflex.GetInstanceResponse, error) {
|
||||
func (a *apiClientInstanceMocked) GetInstanceRequestExecute(_ context.Context, _, _, _ string) (*sqlserverflex.GetInstanceResponse, error) {
|
||||
if a.instanceGetFails {
|
||||
return nil, &oapierror.GenericOpenAPIError{
|
||||
StatusCode: 500,
|
||||
|
|
@ -35,10 +33,8 @@ func (a *apiClientInstanceMocked) GetInstanceExecute(_ context.Context, _, _, _
|
|||
}
|
||||
|
||||
return &sqlserverflex.GetInstanceResponse{
|
||||
Item: &sqlserverflex.Instance{
|
||||
Id: &a.instanceId,
|
||||
Status: &a.instanceState,
|
||||
},
|
||||
Id: &a.instanceId,
|
||||
Status: sqlserverflex.GetInstanceResponseGetStatusAttributeType(&a.instanceState),
|
||||
}, nil
|
||||
}
|
||||
func TestCreateInstanceWaitHandler(t *testing.T) {
|
||||
|
|
@ -98,10 +94,8 @@ func TestCreateInstanceWaitHandler(t *testing.T) {
|
|||
var wantRes *sqlserverflex.GetInstanceResponse
|
||||
if tt.wantResp {
|
||||
wantRes = &sqlserverflex.GetInstanceResponse{
|
||||
Item: &sqlserverflex.Instance{
|
||||
Id: &instanceId,
|
||||
Status: utils.Ptr(tt.instanceState),
|
||||
},
|
||||
Id: &instanceId,
|
||||
Status: sqlserverflex.GetInstanceResponseGetStatusAttributeType(utils.Ptr(tt.instanceState)),
|
||||
}
|
||||
}
|
||||
|
||||
|
|
@ -175,10 +169,8 @@ func TestUpdateInstanceWaitHandler(t *testing.T) {
|
|||
var wantRes *sqlserverflex.GetInstanceResponse
|
||||
if tt.wantResp {
|
||||
wantRes = &sqlserverflex.GetInstanceResponse{
|
||||
Item: &sqlserverflex.Instance{
|
||||
Id: &instanceId,
|
||||
Status: utils.Ptr(tt.instanceState),
|
||||
},
|
||||
Id: &instanceId,
|
||||
Status: sqlserverflex.GetInstanceResponseGetStatusAttributeType(utils.Ptr(tt.instanceState)),
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -1,6 +1,4 @@
|
|||
// Copyright (c) STACKIT
|
||||
|
||||
package postgresflexa
|
||||
package postgresflex
|
||||
|
||||
import (
|
||||
"context"
|
||||
|
|
|
|||
File diff suppressed because it is too large
Load diff
|
|
@ -1,6 +1,6 @@
|
|||
// Copyright (c) STACKIT
|
||||
|
||||
package postgresflexa
|
||||
package postgresflex
|
||||
|
||||
import (
|
||||
"context"
|
||||
|
|
|
|||
|
|
@ -0,0 +1,430 @@
|
|||
package sqlserverflex
|
||||
|
||||
import (
|
||||
"context"
|
||||
"fmt"
|
||||
"strings"
|
||||
|
||||
"github.com/hashicorp/terraform-plugin-framework/attr"
|
||||
"github.com/hashicorp/terraform-plugin-framework/types"
|
||||
"github.com/hashicorp/terraform-plugin-framework/types/basetypes"
|
||||
sqlserverflex "github.com/stackitcloud/terraform-provider-stackit/pkg/sqlserverflexalpha"
|
||||
"github.com/stackitcloud/terraform-provider-stackit/stackit/internal/conversion"
|
||||
"github.com/stackitcloud/terraform-provider-stackit/stackit/internal/core"
|
||||
"github.com/stackitcloud/terraform-provider-stackit/stackit/internal/utils"
|
||||
)
|
||||
|
||||
type sqlserverflexClient interface {
|
||||
GetFlavorsRequestExecute(ctx context.Context, projectId, region string, page, size *int64, sort sqlserverflex.FlavorSort) (*sqlserverflex.GetFlavorsResponse, error)
|
||||
}
|
||||
|
||||
func mapFields(ctx context.Context, resp *sqlserverflex.GetInstanceResponse, model *Model, flavor *flavorModel, storage *storageModel, encryption *encryptionModel, network *networkModel, region string) error {
|
||||
if resp == nil {
|
||||
return fmt.Errorf("response input is nil")
|
||||
}
|
||||
if model == nil {
|
||||
return fmt.Errorf("model input is nil")
|
||||
}
|
||||
instance := resp
|
||||
|
||||
var instanceId string
|
||||
if model.InstanceId.ValueString() != "" {
|
||||
instanceId = model.InstanceId.ValueString()
|
||||
} else if instance.Id != nil {
|
||||
instanceId = *instance.Id
|
||||
} else {
|
||||
return fmt.Errorf("instance id not present")
|
||||
}
|
||||
|
||||
var flavorValues map[string]attr.Value
|
||||
if instance.FlavorId == nil {
|
||||
return fmt.Errorf("instance has no flavor id")
|
||||
}
|
||||
if *instance.FlavorId != flavor.Id.ValueString() {
|
||||
return fmt.Errorf("instance has different flavor id %s - %s", *instance.FlavorId, flavor.Id.ValueString())
|
||||
}
|
||||
|
||||
flavorValues = map[string]attr.Value{
|
||||
"id": flavor.Id,
|
||||
"description": flavor.Description,
|
||||
"cpu": flavor.CPU,
|
||||
"ram": flavor.RAM,
|
||||
"node_type": flavor.NodeType,
|
||||
}
|
||||
flavorObject, diags := types.ObjectValue(flavorTypes, flavorValues)
|
||||
if diags.HasError() {
|
||||
return fmt.Errorf("creating flavor: %w", core.DiagsToError(diags))
|
||||
}
|
||||
|
||||
var storageValues map[string]attr.Value
|
||||
if instance.Storage == nil {
|
||||
storageValues = map[string]attr.Value{
|
||||
"class": storage.Class,
|
||||
"size": storage.Size,
|
||||
}
|
||||
} else {
|
||||
storageValues = map[string]attr.Value{
|
||||
"class": types.StringValue(*instance.Storage.Class),
|
||||
"size": types.Int64PointerValue(instance.Storage.Size),
|
||||
}
|
||||
}
|
||||
storageObject, diags := types.ObjectValue(storageTypes, storageValues)
|
||||
if diags.HasError() {
|
||||
return fmt.Errorf("creating storage: %w", core.DiagsToError(diags))
|
||||
}
|
||||
|
||||
var encryptionValues map[string]attr.Value
|
||||
if instance.Encryption == nil {
|
||||
encryptionValues = map[string]attr.Value{
|
||||
"keyring_id": encryption.KeyRingId,
|
||||
"key_id": encryption.KeyId,
|
||||
"key_version": encryption.KeyVersion,
|
||||
"service_account": encryption.ServiceAccount,
|
||||
}
|
||||
} else {
|
||||
encryptionValues = map[string]attr.Value{
|
||||
"keyring_id": types.StringValue(*instance.Encryption.KekKeyRingId),
|
||||
"key_id": types.StringValue(*instance.Encryption.KekKeyId),
|
||||
"key_version": types.StringValue(*instance.Encryption.KekKeyVersion),
|
||||
"service_account": types.StringValue(*instance.Encryption.ServiceAccount),
|
||||
}
|
||||
}
|
||||
encryptionObject, diags := types.ObjectValue(encryptionTypes, encryptionValues)
|
||||
if diags.HasError() {
|
||||
return fmt.Errorf("creating encryption: %w", core.DiagsToError(diags))
|
||||
}
|
||||
|
||||
var networkValues map[string]attr.Value
|
||||
if instance.Network == nil {
|
||||
networkValues = map[string]attr.Value{
|
||||
"acl": network.ACL,
|
||||
"access_scope": network.AccessScope,
|
||||
"instance_address": network.InstanceAddress,
|
||||
"router_address": network.RouterAddress,
|
||||
}
|
||||
} else {
|
||||
aclList, diags := types.ListValueFrom(ctx, types.StringType, *instance.Network.Acl)
|
||||
if diags.HasError() {
|
||||
return fmt.Errorf("creating network (acl list): %w", core.DiagsToError(diags))
|
||||
}
|
||||
|
||||
var routerAddress string
|
||||
if instance.Network.RouterAddress != nil {
|
||||
routerAddress = *instance.Network.RouterAddress
|
||||
diags.AddWarning("field missing while mapping fields", "router_address was empty in API response")
|
||||
}
|
||||
if instance.Network.InstanceAddress == nil {
|
||||
return fmt.Errorf("creating network: no instance address returned")
|
||||
}
|
||||
networkValues = map[string]attr.Value{
|
||||
"acl": aclList,
|
||||
"access_scope": types.StringValue(string(*instance.Network.AccessScope)),
|
||||
"instance_address": types.StringValue(*instance.Network.InstanceAddress),
|
||||
"router_address": types.StringValue(routerAddress),
|
||||
}
|
||||
}
|
||||
networkObject, diags := types.ObjectValue(networkTypes, networkValues)
|
||||
if diags.HasError() {
|
||||
return fmt.Errorf("creating network: %w", core.DiagsToError(diags))
|
||||
}
|
||||
|
||||
simplifiedModelBackupSchedule := utils.SimplifyBackupSchedule(model.BackupSchedule.ValueString())
|
||||
// If the value returned by the API is different from the one in the model after simplification,
|
||||
// we update the model so that it causes an error in Terraform
|
||||
if simplifiedModelBackupSchedule != types.StringPointerValue(instance.BackupSchedule).ValueString() {
|
||||
model.BackupSchedule = types.StringPointerValue(instance.BackupSchedule)
|
||||
}
|
||||
|
||||
if instance.Replicas == nil {
|
||||
return fmt.Errorf("instance has no replicas set")
|
||||
}
|
||||
|
||||
if instance.RetentionDays == nil {
|
||||
return fmt.Errorf("instance has no retention days set")
|
||||
}
|
||||
|
||||
if instance.Version == nil {
|
||||
return fmt.Errorf("instance has no version set")
|
||||
}
|
||||
|
||||
if instance.Edition == nil {
|
||||
return fmt.Errorf("instance has no edition set")
|
||||
}
|
||||
|
||||
if instance.Status == nil {
|
||||
return fmt.Errorf("instance has no status set")
|
||||
}
|
||||
|
||||
if instance.IsDeletable == nil {
|
||||
return fmt.Errorf("instance has no IsDeletable set")
|
||||
}
|
||||
|
||||
model.Id = utils.BuildInternalTerraformId(model.ProjectId.ValueString(), region, instanceId)
|
||||
model.InstanceId = types.StringValue(instanceId)
|
||||
model.Name = types.StringPointerValue(instance.Name)
|
||||
model.Flavor = flavorObject
|
||||
model.Replicas = types.Int64Value(int64(*instance.Replicas))
|
||||
model.Storage = storageObject
|
||||
model.Version = types.StringValue(string(*instance.Version))
|
||||
model.Edition = types.StringValue(string(*instance.Edition))
|
||||
model.Region = types.StringValue(region)
|
||||
model.Encryption = encryptionObject
|
||||
model.Network = networkObject
|
||||
model.RetentionDays = types.Int64Value(*instance.RetentionDays)
|
||||
model.Status = types.StringValue(string(*instance.Status))
|
||||
model.IsDeletable = types.BoolValue(*instance.IsDeletable)
|
||||
return nil
|
||||
}
|
||||
|
||||
func toCreatePayload(model *Model, storage *storageModel, encryption *encryptionModel, network *networkModel) (*sqlserverflex.CreateInstanceRequestPayload, error) {
|
||||
if model == nil {
|
||||
return nil, fmt.Errorf("nil model")
|
||||
}
|
||||
|
||||
if model.Flavor.IsNull() || model.Flavor.IsUnknown() {
|
||||
return nil, fmt.Errorf("nil flavor")
|
||||
}
|
||||
|
||||
storagePayload := &sqlserverflex.CreateInstanceRequestPayloadGetStorageArgType{}
|
||||
if storage != nil {
|
||||
storagePayload.Class = conversion.StringValueToPointer(storage.Class)
|
||||
storagePayload.Size = conversion.Int64ValueToPointer(storage.Size)
|
||||
}
|
||||
|
||||
encryptionPayload := &sqlserverflex.CreateInstanceRequestPayloadGetEncryptionArgType{}
|
||||
if encryption != nil {
|
||||
encryptionPayload.KekKeyId = conversion.StringValueToPointer(encryption.KeyId)
|
||||
encryptionPayload.KekKeyVersion = conversion.StringValueToPointer(encryption.KeyVersion)
|
||||
encryptionPayload.KekKeyRingId = conversion.StringValueToPointer(encryption.KeyRingId)
|
||||
encryptionPayload.ServiceAccount = conversion.StringValueToPointer(encryption.ServiceAccount)
|
||||
}
|
||||
|
||||
networkPayload := &sqlserverflex.CreateInstanceRequestPayloadGetNetworkArgType{}
|
||||
if network != nil {
|
||||
networkPayload.AccessScope = sqlserverflex.CreateInstanceRequestPayloadNetworkGetAccessScopeAttributeType(conversion.StringValueToPointer(network.AccessScope))
|
||||
}
|
||||
|
||||
flavorId := ""
|
||||
if !(model.Flavor.IsNull() || model.Flavor.IsUnknown()) {
|
||||
modelValues := model.Flavor.Attributes()
|
||||
if _, ok := modelValues["id"]; !ok {
|
||||
return nil, fmt.Errorf("flavor has not yet been created")
|
||||
}
|
||||
flavorId = strings.Trim(modelValues["id"].String(), "\"")
|
||||
}
|
||||
|
||||
var aclElements []string
|
||||
if network != nil && !(network.ACL.IsNull() || network.ACL.IsUnknown()) {
|
||||
aclElements = make([]string, 0, len(network.ACL.Elements()))
|
||||
diags := network.ACL.ElementsAs(nil, &aclElements, false)
|
||||
if diags.HasError() {
|
||||
return nil, fmt.Errorf("creating network: %w", core.DiagsToError(diags))
|
||||
}
|
||||
}
|
||||
|
||||
return &sqlserverflex.CreateInstanceRequestPayload{
|
||||
Acl: &aclElements,
|
||||
BackupSchedule: conversion.StringValueToPointer(model.BackupSchedule),
|
||||
FlavorId: &flavorId,
|
||||
Name: conversion.StringValueToPointer(model.Name),
|
||||
Storage: storagePayload,
|
||||
Version: sqlserverflex.CreateInstanceRequestPayloadGetVersionAttributeType(conversion.StringValueToPointer(model.Version)),
|
||||
Encryption: encryptionPayload,
|
||||
RetentionDays: conversion.Int64ValueToPointer(model.RetentionDays),
|
||||
Network: networkPayload,
|
||||
}, nil
|
||||
}
|
||||
|
||||
func toUpdatePayload(model *Model, storage *storageModel, network *networkModel) (*sqlserverflex.UpdateInstancePartiallyRequestPayload, error) {
|
||||
if model == nil {
|
||||
return nil, fmt.Errorf("nil model")
|
||||
}
|
||||
if model.Flavor.IsNull() || model.Flavor.IsUnknown() {
|
||||
return nil, fmt.Errorf("nil flavor")
|
||||
}
|
||||
var flavorMdl flavorModel
|
||||
diag := model.Flavor.As(context.Background(), &flavorMdl, basetypes.ObjectAsOptions{
|
||||
UnhandledNullAsEmpty: true,
|
||||
UnhandledUnknownAsEmpty: false,
|
||||
})
|
||||
if diag.HasError() {
|
||||
return nil, fmt.Errorf("flavor conversion error: %v", diag.Errors())
|
||||
}
|
||||
|
||||
storagePayload := &sqlserverflex.UpdateInstanceRequestPayloadGetStorageArgType{}
|
||||
if storage != nil {
|
||||
storagePayload.Size = conversion.Int64ValueToPointer(storage.Size)
|
||||
}
|
||||
|
||||
var aclElements []string
|
||||
if network != nil && !(network.ACL.IsNull() || network.ACL.IsUnknown()) {
|
||||
aclElements = make([]string, 0, len(network.ACL.Elements()))
|
||||
diags := network.ACL.ElementsAs(nil, &aclElements, false)
|
||||
if diags.HasError() {
|
||||
return nil, fmt.Errorf("creating network: %w", core.DiagsToError(diags))
|
||||
}
|
||||
}
|
||||
|
||||
// TODO - implement network.ACL as soon as it becomes available
|
||||
replCount := int32(model.Replicas.ValueInt64())
|
||||
flavorId := flavorMdl.Id.ValueString()
|
||||
return &sqlserverflex.UpdateInstancePartiallyRequestPayload{
|
||||
Acl: &aclElements,
|
||||
BackupSchedule: conversion.StringValueToPointer(model.BackupSchedule),
|
||||
FlavorId: &flavorId,
|
||||
Name: conversion.StringValueToPointer(model.Name),
|
||||
Replicas: sqlserverflex.UpdateInstancePartiallyRequestPayloadGetReplicasAttributeType(&replCount),
|
||||
RetentionDays: conversion.Int64ValueToPointer(model.RetentionDays),
|
||||
Storage: storagePayload,
|
||||
Version: sqlserverflex.UpdateInstancePartiallyRequestPayloadGetVersionAttributeType(conversion.StringValueToPointer(model.Version)),
|
||||
}, nil
|
||||
}
|
||||
|
||||
func getAllFlavors(ctx context.Context, client sqlserverflexClient, projectId, region string) ([]sqlserverflex.ListFlavors, error) {
|
||||
if projectId == "" || region == "" {
|
||||
return nil, fmt.Errorf("listing sqlserverflex flavors: projectId and region are required")
|
||||
}
|
||||
var flavorList []sqlserverflex.ListFlavors
|
||||
|
||||
page := int64(1)
|
||||
size := int64(10)
|
||||
for {
|
||||
res, err := client.GetFlavorsRequestExecute(ctx, projectId, region, &page, &size, sqlserverflex.FLAVORSORT_INDEX_ASC)
|
||||
if err != nil {
|
||||
return nil, fmt.Errorf("listing sqlserverflex flavors: %w", err)
|
||||
}
|
||||
if res.Flavors == nil {
|
||||
return nil, fmt.Errorf("finding flavors for project %s", projectId)
|
||||
}
|
||||
pagination := res.GetPagination()
|
||||
flavorList = append(flavorList, *res.Flavors...)
|
||||
|
||||
if *pagination.TotalRows == int64(len(flavorList)) {
|
||||
break
|
||||
}
|
||||
page++
|
||||
}
|
||||
return flavorList, nil
|
||||
}
|
||||
|
||||
func loadFlavorId(ctx context.Context, client sqlserverflexClient, model *Model, flavor *flavorModel, storage *storageModel) error {
|
||||
if model == nil {
|
||||
return fmt.Errorf("nil model")
|
||||
}
|
||||
if flavor == nil {
|
||||
return fmt.Errorf("nil flavor")
|
||||
}
|
||||
cpu := conversion.Int64ValueToPointer(flavor.CPU)
|
||||
if cpu == nil {
|
||||
return fmt.Errorf("nil CPU")
|
||||
}
|
||||
ram := conversion.Int64ValueToPointer(flavor.RAM)
|
||||
if ram == nil {
|
||||
return fmt.Errorf("nil RAM")
|
||||
}
|
||||
nodeType := conversion.StringValueToPointer(flavor.NodeType)
|
||||
if nodeType == nil {
|
||||
return fmt.Errorf("nil NodeType")
|
||||
}
|
||||
storageClass := conversion.StringValueToPointer(storage.Class)
|
||||
if storageClass == nil {
|
||||
return fmt.Errorf("nil StorageClass")
|
||||
}
|
||||
storageSize := conversion.Int64ValueToPointer(storage.Size)
|
||||
if storageSize == nil {
|
||||
return fmt.Errorf("nil StorageSize")
|
||||
}
|
||||
|
||||
projectId := model.ProjectId.ValueString()
|
||||
region := model.Region.ValueString()
|
||||
|
||||
flavorList, err := getAllFlavors(ctx, client, projectId, region)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
avl := ""
|
||||
foundFlavorCount := 0
|
||||
for _, f := range flavorList {
|
||||
if f.Id == nil || f.Cpu == nil || f.Memory == nil {
|
||||
continue
|
||||
}
|
||||
if strings.ToLower(*f.NodeType) != strings.ToLower(*nodeType) {
|
||||
continue
|
||||
}
|
||||
if *f.Cpu == *cpu && *f.Memory == *ram {
|
||||
var useSc *sqlserverflex.FlavorStorageClassesStorageClass
|
||||
for _, sc := range *f.StorageClasses {
|
||||
if *sc.Class != *storageClass {
|
||||
continue
|
||||
}
|
||||
if *storageSize < *f.MinGB || *storageSize > *f.MaxGB {
|
||||
return fmt.Errorf("storage size %d out of bounds (min: %d - max: %d)", *storageSize, *f.MinGB, *f.MaxGB)
|
||||
}
|
||||
useSc = &sc
|
||||
}
|
||||
if useSc == nil {
|
||||
return fmt.Errorf("no storage class found for %s", *storageClass)
|
||||
}
|
||||
|
||||
flavor.Id = types.StringValue(*f.Id)
|
||||
flavor.Description = types.StringValue(*f.Description)
|
||||
foundFlavorCount++
|
||||
}
|
||||
for _, cls := range *f.StorageClasses {
|
||||
avl = fmt.Sprintf("%s\n- %d CPU, %d GB RAM, storage %s (min: %d - max: %d)", avl, *f.Cpu, *f.Memory, *cls.Class, *f.MinGB, *f.MaxGB)
|
||||
}
|
||||
}
|
||||
if foundFlavorCount > 1 {
|
||||
return fmt.Errorf("multiple flavors found: %d flavors", foundFlavorCount)
|
||||
}
|
||||
if flavor.Id.ValueString() == "" {
|
||||
return fmt.Errorf("couldn't find flavor, available specs are:%s", avl)
|
||||
}
|
||||
|
||||
return nil
|
||||
}
|
||||
|
||||
func getFlavorModelById(ctx context.Context, client sqlserverflexClient, model *Model, flavor *flavorModel) error {
|
||||
if model == nil {
|
||||
return fmt.Errorf("nil model")
|
||||
}
|
||||
if flavor == nil {
|
||||
return fmt.Errorf("nil flavor")
|
||||
}
|
||||
id := conversion.StringValueToPointer(flavor.Id)
|
||||
if id == nil {
|
||||
return fmt.Errorf("nil flavor ID")
|
||||
}
|
||||
|
||||
flavor.Id = types.StringValue("")
|
||||
|
||||
projectId := model.ProjectId.ValueString()
|
||||
region := model.Region.ValueString()
|
||||
|
||||
flavorList, err := getAllFlavors(ctx, client, projectId, region)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
avl := ""
|
||||
for _, f := range flavorList {
|
||||
if f.Id == nil || f.Cpu == nil || f.Memory == nil {
|
||||
continue
|
||||
}
|
||||
if *f.Id == *id {
|
||||
flavor.Id = types.StringValue(*f.Id)
|
||||
flavor.Description = types.StringValue(*f.Description)
|
||||
flavor.CPU = types.Int64Value(*f.Cpu)
|
||||
flavor.RAM = types.Int64Value(*f.Memory)
|
||||
flavor.NodeType = types.StringValue(*f.NodeType)
|
||||
break
|
||||
}
|
||||
avl = fmt.Sprintf("%s\n- %d CPU, %d GB RAM", avl, *f.Cpu, *f.Memory)
|
||||
}
|
||||
if flavor.Id.ValueString() == "" {
|
||||
return fmt.Errorf("couldn't find flavor, available specs are: %s", avl)
|
||||
}
|
||||
|
||||
return nil
|
||||
}
|
||||
|
|
@ -0,0 +1,282 @@
|
|||
// Copyright (c) STACKIT
|
||||
|
||||
package sqlserverflex
|
||||
|
||||
import (
|
||||
"context"
|
||||
"reflect"
|
||||
"testing"
|
||||
|
||||
"github.com/hashicorp/terraform-plugin-framework/resource"
|
||||
"github.com/stackitcloud/terraform-provider-stackit/stackit/internal/core"
|
||||
|
||||
sqlserverflex "github.com/stackitcloud/terraform-provider-stackit/pkg/sqlserverflexalpha"
|
||||
)
|
||||
|
||||
func TestNewInstanceResource(t *testing.T) {
|
||||
tests := []struct {
|
||||
name string
|
||||
want resource.Resource
|
||||
}{
|
||||
// TODO: Add test cases.
|
||||
}
|
||||
for _, tt := range tests {
|
||||
t.Run(tt.name, func(t *testing.T) {
|
||||
if got := NewInstanceResource(); !reflect.DeepEqual(got, tt.want) {
|
||||
t.Errorf("NewInstanceResource() = %v, want %v", got, tt.want)
|
||||
}
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
func Test_instanceResource_Configure(t *testing.T) {
|
||||
type fields struct {
|
||||
client *sqlserverflex.APIClient
|
||||
providerData core.ProviderData
|
||||
}
|
||||
type args struct {
|
||||
ctx context.Context
|
||||
req resource.ConfigureRequest
|
||||
resp *resource.ConfigureResponse
|
||||
}
|
||||
tests := []struct {
|
||||
name string
|
||||
fields fields
|
||||
args args
|
||||
}{
|
||||
// TODO: Add test cases.
|
||||
}
|
||||
for _, tt := range tests {
|
||||
t.Run(tt.name, func(t *testing.T) {
|
||||
r := &instanceResource{
|
||||
client: tt.fields.client,
|
||||
providerData: tt.fields.providerData,
|
||||
}
|
||||
r.Configure(tt.args.ctx, tt.args.req, tt.args.resp)
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
func Test_instanceResource_Create(t *testing.T) {
|
||||
type fields struct {
|
||||
client *sqlserverflex.APIClient
|
||||
providerData core.ProviderData
|
||||
}
|
||||
type args struct {
|
||||
ctx context.Context
|
||||
req resource.CreateRequest
|
||||
resp *resource.CreateResponse
|
||||
}
|
||||
tests := []struct {
|
||||
name string
|
||||
fields fields
|
||||
args args
|
||||
}{
|
||||
// TODO: Add test cases.
|
||||
}
|
||||
for _, tt := range tests {
|
||||
t.Run(tt.name, func(t *testing.T) {
|
||||
r := &instanceResource{
|
||||
client: tt.fields.client,
|
||||
providerData: tt.fields.providerData,
|
||||
}
|
||||
r.Create(tt.args.ctx, tt.args.req, tt.args.resp)
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
func Test_instanceResource_Delete(t *testing.T) {
|
||||
type fields struct {
|
||||
client *sqlserverflex.APIClient
|
||||
providerData core.ProviderData
|
||||
}
|
||||
type args struct {
|
||||
ctx context.Context
|
||||
req resource.DeleteRequest
|
||||
resp *resource.DeleteResponse
|
||||
}
|
||||
tests := []struct {
|
||||
name string
|
||||
fields fields
|
||||
args args
|
||||
}{
|
||||
// TODO: Add test cases.
|
||||
}
|
||||
for _, tt := range tests {
|
||||
t.Run(tt.name, func(t *testing.T) {
|
||||
r := &instanceResource{
|
||||
client: tt.fields.client,
|
||||
providerData: tt.fields.providerData,
|
||||
}
|
||||
r.Delete(tt.args.ctx, tt.args.req, tt.args.resp)
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
func Test_instanceResource_ImportState(t *testing.T) {
|
||||
type fields struct {
|
||||
client *sqlserverflex.APIClient
|
||||
providerData core.ProviderData
|
||||
}
|
||||
type args struct {
|
||||
ctx context.Context
|
||||
req resource.ImportStateRequest
|
||||
resp *resource.ImportStateResponse
|
||||
}
|
||||
tests := []struct {
|
||||
name string
|
||||
fields fields
|
||||
args args
|
||||
}{
|
||||
// TODO: Add test cases.
|
||||
}
|
||||
for _, tt := range tests {
|
||||
t.Run(tt.name, func(t *testing.T) {
|
||||
r := &instanceResource{
|
||||
client: tt.fields.client,
|
||||
providerData: tt.fields.providerData,
|
||||
}
|
||||
r.ImportState(tt.args.ctx, tt.args.req, tt.args.resp)
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
func Test_instanceResource_Metadata(t *testing.T) {
|
||||
type fields struct {
|
||||
client *sqlserverflex.APIClient
|
||||
providerData core.ProviderData
|
||||
}
|
||||
type args struct {
|
||||
in0 context.Context
|
||||
req resource.MetadataRequest
|
||||
resp *resource.MetadataResponse
|
||||
}
|
||||
tests := []struct {
|
||||
name string
|
||||
fields fields
|
||||
args args
|
||||
}{
|
||||
// TODO: Add test cases.
|
||||
}
|
||||
for _, tt := range tests {
|
||||
t.Run(tt.name, func(t *testing.T) {
|
||||
r := &instanceResource{
|
||||
client: tt.fields.client,
|
||||
providerData: tt.fields.providerData,
|
||||
}
|
||||
r.Metadata(tt.args.in0, tt.args.req, tt.args.resp)
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
func Test_instanceResource_ModifyPlan(t *testing.T) {
|
||||
type fields struct {
|
||||
client *sqlserverflex.APIClient
|
||||
providerData core.ProviderData
|
||||
}
|
||||
type args struct {
|
||||
ctx context.Context
|
||||
req resource.ModifyPlanRequest
|
||||
resp *resource.ModifyPlanResponse
|
||||
}
|
||||
tests := []struct {
|
||||
name string
|
||||
fields fields
|
||||
args args
|
||||
}{
|
||||
// TODO: Add test cases.
|
||||
}
|
||||
for _, tt := range tests {
|
||||
t.Run(tt.name, func(t *testing.T) {
|
||||
r := &instanceResource{
|
||||
client: tt.fields.client,
|
||||
providerData: tt.fields.providerData,
|
||||
}
|
||||
r.ModifyPlan(tt.args.ctx, tt.args.req, tt.args.resp)
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
func Test_instanceResource_Read(t *testing.T) {
|
||||
type fields struct {
|
||||
client *sqlserverflex.APIClient
|
||||
providerData core.ProviderData
|
||||
}
|
||||
type args struct {
|
||||
ctx context.Context
|
||||
req resource.ReadRequest
|
||||
resp *resource.ReadResponse
|
||||
}
|
||||
tests := []struct {
|
||||
name string
|
||||
fields fields
|
||||
args args
|
||||
}{
|
||||
// TODO: Add test cases.
|
||||
}
|
||||
for _, tt := range tests {
|
||||
t.Run(tt.name, func(t *testing.T) {
|
||||
r := &instanceResource{
|
||||
client: tt.fields.client,
|
||||
providerData: tt.fields.providerData,
|
||||
}
|
||||
r.Read(tt.args.ctx, tt.args.req, tt.args.resp)
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
func Test_instanceResource_Schema(t *testing.T) {
|
||||
type fields struct {
|
||||
client *sqlserverflex.APIClient
|
||||
providerData core.ProviderData
|
||||
}
|
||||
type args struct {
|
||||
in0 context.Context
|
||||
in1 resource.SchemaRequest
|
||||
resp *resource.SchemaResponse
|
||||
}
|
||||
tests := []struct {
|
||||
name string
|
||||
fields fields
|
||||
args args
|
||||
}{
|
||||
// TODO: Add test cases.
|
||||
}
|
||||
for _, tt := range tests {
|
||||
t.Run(tt.name, func(t *testing.T) {
|
||||
r := &instanceResource{
|
||||
client: tt.fields.client,
|
||||
providerData: tt.fields.providerData,
|
||||
}
|
||||
r.Schema(tt.args.in0, tt.args.in1, tt.args.resp)
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
func Test_instanceResource_Update(t *testing.T) {
|
||||
type fields struct {
|
||||
client *sqlserverflex.APIClient
|
||||
providerData core.ProviderData
|
||||
}
|
||||
type args struct {
|
||||
ctx context.Context
|
||||
req resource.UpdateRequest
|
||||
resp *resource.UpdateResponse
|
||||
}
|
||||
tests := []struct {
|
||||
name string
|
||||
fields fields
|
||||
args args
|
||||
}{
|
||||
// TODO: Add test cases.
|
||||
}
|
||||
for _, tt := range tests {
|
||||
t.Run(tt.name, func(t *testing.T) {
|
||||
r := &instanceResource{
|
||||
client: tt.fields.client,
|
||||
providerData: tt.fields.providerData,
|
||||
}
|
||||
r.Update(tt.args.ctx, tt.args.req, tt.args.resp)
|
||||
})
|
||||
}
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue