feat: auto generated files and new structure (#4)
## Description
<!-- **Please link some issue here describing what you are trying to achieve.**
In case there is no issue present for your PR, please consider creating one.
At least please give us some description what you are trying to achieve and why your change is needed. -->
relates to #1234
## Checklist
- [ ] Issue was linked above
- [ ] Code format was applied: `make fmt`
- [ ] Examples were added / adjusted (see `examples/` directory)
- [x] Docs are up-to-date: `make generate-docs` (will be checked by CI)
- [ ] Unit tests got implemented or updated
- [ ] Acceptance tests got implemented or updated (see e.g. [here](f5f99d1709/stackit/internal/services/dns/dns_acc_test.go))
- [x] Unit tests are passing: `make test` (will be checked by CI)
- [x] No linter issues: `make lint` (will be checked by CI)
Reviewed-on: #4
Reviewed-by: Andre_Harms <andre.harms@stackit.cloud>
Co-authored-by: Marcel S. Henselin <marcel.henselin@stackit.cloud>
Co-committed-by: Marcel S. Henselin <marcel.henselin@stackit.cloud>
This commit is contained in:
parent
979220be66
commit
9f41c4da7f
1283 changed files with 273211 additions and 4614 deletions
File diff suppressed because it is too large
Load diff
|
|
@ -501,10 +501,7 @@ func addFile(w *multipart.Writer, fieldName, path string) error {
|
|||
if err != nil {
|
||||
return err
|
||||
}
|
||||
err = file.Close()
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
defer file.Close()
|
||||
|
||||
part, err := w.CreateFormFile(fieldName, filepath.Base(path))
|
||||
if err != nil {
|
||||
|
|
|
|||
|
|
@ -17,26 +17,6 @@ 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
|
||||
*/
|
||||
|
|
@ -223,7 +203,6 @@ 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"`
|
||||
|
|
|
|||
|
|
@ -38,6 +38,46 @@ func setGetInstanceResponseGetBackupScheduleAttributeType(arg *GetInstanceRespon
|
|||
type GetInstanceResponseGetBackupScheduleArgType = string
|
||||
type GetInstanceResponseGetBackupScheduleRetType = string
|
||||
|
||||
/*
|
||||
types and functions for connectionInfo
|
||||
*/
|
||||
|
||||
// isModel
|
||||
type GetInstanceResponseGetConnectionInfoAttributeType = *InstanceConnectionInfo
|
||||
type GetInstanceResponseGetConnectionInfoArgType = InstanceConnectionInfo
|
||||
type GetInstanceResponseGetConnectionInfoRetType = InstanceConnectionInfo
|
||||
|
||||
func getGetInstanceResponseGetConnectionInfoAttributeTypeOk(arg GetInstanceResponseGetConnectionInfoAttributeType) (ret GetInstanceResponseGetConnectionInfoRetType, ok bool) {
|
||||
if arg == nil {
|
||||
return ret, false
|
||||
}
|
||||
return *arg, true
|
||||
}
|
||||
|
||||
func setGetInstanceResponseGetConnectionInfoAttributeType(arg *GetInstanceResponseGetConnectionInfoAttributeType, val GetInstanceResponseGetConnectionInfoRetType) {
|
||||
*arg = &val
|
||||
}
|
||||
|
||||
/*
|
||||
types and functions for encryption
|
||||
*/
|
||||
|
||||
// isModel
|
||||
type GetInstanceResponseGetEncryptionAttributeType = *InstanceEncryption
|
||||
type GetInstanceResponseGetEncryptionArgType = InstanceEncryption
|
||||
type GetInstanceResponseGetEncryptionRetType = InstanceEncryption
|
||||
|
||||
func getGetInstanceResponseGetEncryptionAttributeTypeOk(arg GetInstanceResponseGetEncryptionAttributeType) (ret GetInstanceResponseGetEncryptionRetType, ok bool) {
|
||||
if arg == nil {
|
||||
return ret, false
|
||||
}
|
||||
return *arg, true
|
||||
}
|
||||
|
||||
func setGetInstanceResponseGetEncryptionAttributeType(arg *GetInstanceResponseGetEncryptionAttributeType, val GetInstanceResponseGetEncryptionRetType) {
|
||||
*arg = &val
|
||||
}
|
||||
|
||||
/*
|
||||
types and functions for flavorId
|
||||
*/
|
||||
|
|
@ -221,26 +261,6 @@ func setGetInstanceResponseGetStorageAttributeType(arg *GetInstanceResponseGetSt
|
|||
*arg = &val
|
||||
}
|
||||
|
||||
/*
|
||||
types and functions for encryption
|
||||
*/
|
||||
|
||||
// isModel
|
||||
type GetInstanceResponseGetEncryptionAttributeType = *InstanceEncryption
|
||||
type GetInstanceResponseGetEncryptionArgType = InstanceEncryption
|
||||
type GetInstanceResponseGetEncryptionRetType = InstanceEncryption
|
||||
|
||||
func getGetInstanceResponseGetEncryptionAttributeTypeOk(arg GetInstanceResponseGetEncryptionAttributeType) (ret GetInstanceResponseGetEncryptionRetType, ok bool) {
|
||||
if arg == nil {
|
||||
return ret, false
|
||||
}
|
||||
return *arg, true
|
||||
}
|
||||
|
||||
func setGetInstanceResponseGetEncryptionAttributeType(arg *GetInstanceResponseGetEncryptionAttributeType, val GetInstanceResponseGetEncryptionRetType) {
|
||||
*arg = &val
|
||||
}
|
||||
|
||||
/*
|
||||
types and functions for version
|
||||
*/
|
||||
|
|
@ -267,6 +287,9 @@ type GetInstanceResponse struct {
|
|||
// 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 GetInstanceResponseGetBackupScheduleAttributeType `json:"backupSchedule" required:"true"`
|
||||
// REQUIRED
|
||||
ConnectionInfo GetInstanceResponseGetConnectionInfoAttributeType `json:"connectionInfo" required:"true"`
|
||||
Encryption GetInstanceResponseGetEncryptionAttributeType `json:"encryption,omitempty"`
|
||||
// The id of the instance flavor.
|
||||
// REQUIRED
|
||||
FlavorId GetInstanceResponseGetFlavorIdAttributeType `json:"flavorId" required:"true"`
|
||||
|
|
@ -276,7 +299,6 @@ type GetInstanceResponse struct {
|
|||
// Whether the instance can be deleted or not.
|
||||
// REQUIRED
|
||||
IsDeletable GetInstanceResponsegetIsDeletableAttributeType `json:"isDeletable" required:"true"`
|
||||
Encryption GetInstanceResponseGetEncryptionAttributeType `json:"encryption,omitempty"`
|
||||
// The name of the instance.
|
||||
// REQUIRED
|
||||
Name GetInstanceResponseGetNameAttributeType `json:"name" required:"true"`
|
||||
|
|
@ -303,9 +325,10 @@ type _GetInstanceResponse GetInstanceResponse
|
|||
// This constructor will assign default values to properties that have it defined,
|
||||
// and makes sure properties required by API are set, but the set of arguments
|
||||
// will change when the set of required properties is changed
|
||||
func NewGetInstanceResponse(backupSchedule GetInstanceResponseGetBackupScheduleArgType, flavorId GetInstanceResponseGetFlavorIdArgType, id GetInstanceResponseGetIdArgType, isDeletable GetInstanceResponsegetIsDeletableArgType, name GetInstanceResponseGetNameArgType, network GetInstanceResponseGetNetworkArgType, replicas GetInstanceResponseGetReplicasArgType, retentionDays GetInstanceResponseGetRetentionDaysArgType, status GetInstanceResponseGetStatusArgType, storage GetInstanceResponseGetStorageArgType, version GetInstanceResponseGetVersionArgType) *GetInstanceResponse {
|
||||
func NewGetInstanceResponse(backupSchedule GetInstanceResponseGetBackupScheduleArgType, connectionInfo GetInstanceResponseGetConnectionInfoArgType, flavorId GetInstanceResponseGetFlavorIdArgType, id GetInstanceResponseGetIdArgType, isDeletable GetInstanceResponsegetIsDeletableArgType, name GetInstanceResponseGetNameArgType, network GetInstanceResponseGetNetworkArgType, replicas GetInstanceResponseGetReplicasArgType, retentionDays GetInstanceResponseGetRetentionDaysArgType, status GetInstanceResponseGetStatusArgType, storage GetInstanceResponseGetStorageArgType, version GetInstanceResponseGetVersionArgType) *GetInstanceResponse {
|
||||
this := GetInstanceResponse{}
|
||||
setGetInstanceResponseGetBackupScheduleAttributeType(&this.BackupSchedule, backupSchedule)
|
||||
setGetInstanceResponseGetConnectionInfoAttributeType(&this.ConnectionInfo, connectionInfo)
|
||||
setGetInstanceResponseGetFlavorIdAttributeType(&this.FlavorId, flavorId)
|
||||
setGetInstanceResponseGetIdAttributeType(&this.Id, id)
|
||||
setGetInstanceResponsegetIsDeletableAttributeType(&this.IsDeletable, isDeletable)
|
||||
|
|
@ -344,6 +367,46 @@ func (o *GetInstanceResponse) SetBackupSchedule(v GetInstanceResponseGetBackupSc
|
|||
setGetInstanceResponseGetBackupScheduleAttributeType(&o.BackupSchedule, v)
|
||||
}
|
||||
|
||||
// GetConnectionInfo returns the ConnectionInfo field value
|
||||
func (o *GetInstanceResponse) GetConnectionInfo() (ret GetInstanceResponseGetConnectionInfoRetType) {
|
||||
ret, _ = o.GetConnectionInfoOk()
|
||||
return ret
|
||||
}
|
||||
|
||||
// GetConnectionInfoOk returns a tuple with the ConnectionInfo field value
|
||||
// and a boolean to check if the value has been set.
|
||||
func (o *GetInstanceResponse) GetConnectionInfoOk() (ret GetInstanceResponseGetConnectionInfoRetType, ok bool) {
|
||||
return getGetInstanceResponseGetConnectionInfoAttributeTypeOk(o.ConnectionInfo)
|
||||
}
|
||||
|
||||
// SetConnectionInfo sets field value
|
||||
func (o *GetInstanceResponse) SetConnectionInfo(v GetInstanceResponseGetConnectionInfoRetType) {
|
||||
setGetInstanceResponseGetConnectionInfoAttributeType(&o.ConnectionInfo, v)
|
||||
}
|
||||
|
||||
// GetEncryption returns the Encryption field value if set, zero value otherwise.
|
||||
func (o *GetInstanceResponse) GetEncryption() (res GetInstanceResponseGetEncryptionRetType) {
|
||||
res, _ = o.GetEncryptionOk()
|
||||
return
|
||||
}
|
||||
|
||||
// GetEncryptionOk returns a tuple with the Encryption field value if set, nil otherwise
|
||||
// and a boolean to check if the value has been set.
|
||||
func (o *GetInstanceResponse) GetEncryptionOk() (ret GetInstanceResponseGetEncryptionRetType, ok bool) {
|
||||
return getGetInstanceResponseGetEncryptionAttributeTypeOk(o.Encryption)
|
||||
}
|
||||
|
||||
// HasEncryption returns a boolean if a field has been set.
|
||||
func (o *GetInstanceResponse) HasEncryption() bool {
|
||||
_, ok := o.GetEncryptionOk()
|
||||
return ok
|
||||
}
|
||||
|
||||
// SetEncryption gets a reference to the given InstanceEncryption and assigns it to the Encryption field.
|
||||
func (o *GetInstanceResponse) SetEncryption(v GetInstanceResponseGetEncryptionRetType) {
|
||||
setGetInstanceResponseGetEncryptionAttributeType(&o.Encryption, v)
|
||||
}
|
||||
|
||||
// GetFlavorId returns the FlavorId field value
|
||||
func (o *GetInstanceResponse) GetFlavorId() (ret GetInstanceResponseGetFlavorIdRetType) {
|
||||
ret, _ = o.GetFlavorIdOk()
|
||||
|
|
@ -519,6 +582,12 @@ func (o GetInstanceResponse) ToMap() (map[string]interface{}, error) {
|
|||
if val, ok := getGetInstanceResponseGetBackupScheduleAttributeTypeOk(o.BackupSchedule); ok {
|
||||
toSerialize["BackupSchedule"] = val
|
||||
}
|
||||
if val, ok := getGetInstanceResponseGetConnectionInfoAttributeTypeOk(o.ConnectionInfo); ok {
|
||||
toSerialize["ConnectionInfo"] = val
|
||||
}
|
||||
if val, ok := getGetInstanceResponseGetEncryptionAttributeTypeOk(o.Encryption); ok {
|
||||
toSerialize["Encryption"] = val
|
||||
}
|
||||
if val, ok := getGetInstanceResponseGetFlavorIdAttributeTypeOk(o.FlavorId); ok {
|
||||
toSerialize["FlavorId"] = val
|
||||
}
|
||||
|
|
|
|||
171
pkg/postgresflexalpha/model_instance_connection_info.go
Normal file
171
pkg/postgresflexalpha/model_instance_connection_info.go
Normal file
|
|
@ -0,0 +1,171 @@
|
|||
/*
|
||||
PostgreSQL Flex API
|
||||
|
||||
This is the documentation for the STACKIT Postgres Flex service
|
||||
|
||||
API version: 3alpha1
|
||||
*/
|
||||
|
||||
// Code generated by OpenAPI Generator (https://openapi-generator.tech); DO NOT EDIT.
|
||||
|
||||
package postgresflexalpha
|
||||
|
||||
import (
|
||||
"encoding/json"
|
||||
)
|
||||
|
||||
// checks if the InstanceConnectionInfo type satisfies the MappedNullable interface at compile time
|
||||
var _ MappedNullable = &InstanceConnectionInfo{}
|
||||
|
||||
/*
|
||||
types and functions for host
|
||||
*/
|
||||
|
||||
// isNotNullableString
|
||||
type InstanceConnectionInfoGetHostAttributeType = *string
|
||||
|
||||
func getInstanceConnectionInfoGetHostAttributeTypeOk(arg InstanceConnectionInfoGetHostAttributeType) (ret InstanceConnectionInfoGetHostRetType, ok bool) {
|
||||
if arg == nil {
|
||||
return ret, false
|
||||
}
|
||||
return *arg, true
|
||||
}
|
||||
|
||||
func setInstanceConnectionInfoGetHostAttributeType(arg *InstanceConnectionInfoGetHostAttributeType, val InstanceConnectionInfoGetHostRetType) {
|
||||
*arg = &val
|
||||
}
|
||||
|
||||
type InstanceConnectionInfoGetHostArgType = string
|
||||
type InstanceConnectionInfoGetHostRetType = string
|
||||
|
||||
/*
|
||||
types and functions for port
|
||||
*/
|
||||
|
||||
// isInteger
|
||||
type InstanceConnectionInfoGetPortAttributeType = *int64
|
||||
type InstanceConnectionInfoGetPortArgType = int64
|
||||
type InstanceConnectionInfoGetPortRetType = int64
|
||||
|
||||
func getInstanceConnectionInfoGetPortAttributeTypeOk(arg InstanceConnectionInfoGetPortAttributeType) (ret InstanceConnectionInfoGetPortRetType, ok bool) {
|
||||
if arg == nil {
|
||||
return ret, false
|
||||
}
|
||||
return *arg, true
|
||||
}
|
||||
|
||||
func setInstanceConnectionInfoGetPortAttributeType(arg *InstanceConnectionInfoGetPortAttributeType, val InstanceConnectionInfoGetPortRetType) {
|
||||
*arg = &val
|
||||
}
|
||||
|
||||
// InstanceConnectionInfo The DNS name and port in the instance overview
|
||||
type InstanceConnectionInfo struct {
|
||||
// The host of the instance.
|
||||
// REQUIRED
|
||||
Host InstanceConnectionInfoGetHostAttributeType `json:"host" required:"true"`
|
||||
// The port of the instance.
|
||||
// REQUIRED
|
||||
Port InstanceConnectionInfoGetPortAttributeType `json:"port" required:"true"`
|
||||
}
|
||||
|
||||
type _InstanceConnectionInfo InstanceConnectionInfo
|
||||
|
||||
// NewInstanceConnectionInfo instantiates a new InstanceConnectionInfo object
|
||||
// This constructor will assign default values to properties that have it defined,
|
||||
// and makes sure properties required by API are set, but the set of arguments
|
||||
// will change when the set of required properties is changed
|
||||
func NewInstanceConnectionInfo(host InstanceConnectionInfoGetHostArgType, port InstanceConnectionInfoGetPortArgType) *InstanceConnectionInfo {
|
||||
this := InstanceConnectionInfo{}
|
||||
setInstanceConnectionInfoGetHostAttributeType(&this.Host, host)
|
||||
setInstanceConnectionInfoGetPortAttributeType(&this.Port, port)
|
||||
return &this
|
||||
}
|
||||
|
||||
// NewInstanceConnectionInfoWithDefaults instantiates a new InstanceConnectionInfo object
|
||||
// This constructor will only assign default values to properties that have it defined,
|
||||
// but it doesn't guarantee that properties required by API are set
|
||||
func NewInstanceConnectionInfoWithDefaults() *InstanceConnectionInfo {
|
||||
this := InstanceConnectionInfo{}
|
||||
return &this
|
||||
}
|
||||
|
||||
// GetHost returns the Host field value
|
||||
func (o *InstanceConnectionInfo) GetHost() (ret InstanceConnectionInfoGetHostRetType) {
|
||||
ret, _ = o.GetHostOk()
|
||||
return ret
|
||||
}
|
||||
|
||||
// GetHostOk returns a tuple with the Host field value
|
||||
// and a boolean to check if the value has been set.
|
||||
func (o *InstanceConnectionInfo) GetHostOk() (ret InstanceConnectionInfoGetHostRetType, ok bool) {
|
||||
return getInstanceConnectionInfoGetHostAttributeTypeOk(o.Host)
|
||||
}
|
||||
|
||||
// SetHost sets field value
|
||||
func (o *InstanceConnectionInfo) SetHost(v InstanceConnectionInfoGetHostRetType) {
|
||||
setInstanceConnectionInfoGetHostAttributeType(&o.Host, v)
|
||||
}
|
||||
|
||||
// GetPort returns the Port field value
|
||||
func (o *InstanceConnectionInfo) GetPort() (ret InstanceConnectionInfoGetPortRetType) {
|
||||
ret, _ = o.GetPortOk()
|
||||
return ret
|
||||
}
|
||||
|
||||
// GetPortOk returns a tuple with the Port field value
|
||||
// and a boolean to check if the value has been set.
|
||||
func (o *InstanceConnectionInfo) GetPortOk() (ret InstanceConnectionInfoGetPortRetType, ok bool) {
|
||||
return getInstanceConnectionInfoGetPortAttributeTypeOk(o.Port)
|
||||
}
|
||||
|
||||
// SetPort sets field value
|
||||
func (o *InstanceConnectionInfo) SetPort(v InstanceConnectionInfoGetPortRetType) {
|
||||
setInstanceConnectionInfoGetPortAttributeType(&o.Port, v)
|
||||
}
|
||||
|
||||
func (o InstanceConnectionInfo) ToMap() (map[string]interface{}, error) {
|
||||
toSerialize := map[string]interface{}{}
|
||||
if val, ok := getInstanceConnectionInfoGetHostAttributeTypeOk(o.Host); ok {
|
||||
toSerialize["Host"] = val
|
||||
}
|
||||
if val, ok := getInstanceConnectionInfoGetPortAttributeTypeOk(o.Port); ok {
|
||||
toSerialize["Port"] = val
|
||||
}
|
||||
return toSerialize, nil
|
||||
}
|
||||
|
||||
type NullableInstanceConnectionInfo struct {
|
||||
value *InstanceConnectionInfo
|
||||
isSet bool
|
||||
}
|
||||
|
||||
func (v NullableInstanceConnectionInfo) Get() *InstanceConnectionInfo {
|
||||
return v.value
|
||||
}
|
||||
|
||||
func (v *NullableInstanceConnectionInfo) Set(val *InstanceConnectionInfo) {
|
||||
v.value = val
|
||||
v.isSet = true
|
||||
}
|
||||
|
||||
func (v NullableInstanceConnectionInfo) IsSet() bool {
|
||||
return v.isSet
|
||||
}
|
||||
|
||||
func (v *NullableInstanceConnectionInfo) Unset() {
|
||||
v.value = nil
|
||||
v.isSet = false
|
||||
}
|
||||
|
||||
func NewNullableInstanceConnectionInfo(val *InstanceConnectionInfo) *NullableInstanceConnectionInfo {
|
||||
return &NullableInstanceConnectionInfo{value: val, isSet: true}
|
||||
}
|
||||
|
||||
func (v NullableInstanceConnectionInfo) MarshalJSON() ([]byte, error) {
|
||||
return json.Marshal(v.value)
|
||||
}
|
||||
|
||||
func (v *NullableInstanceConnectionInfo) UnmarshalJSON(src []byte) error {
|
||||
v.isSet = true
|
||||
return json.Unmarshal(src, &v.value)
|
||||
}
|
||||
11
pkg/postgresflexalpha/model_instance_connection_info_test.go
Normal file
11
pkg/postgresflexalpha/model_instance_connection_info_test.go
Normal file
|
|
@ -0,0 +1,11 @@
|
|||
/*
|
||||
PostgreSQL Flex API
|
||||
|
||||
This is the documentation for the STACKIT Postgres Flex service
|
||||
|
||||
API version: 3alpha1
|
||||
*/
|
||||
|
||||
// Code generated by OpenAPI Generator (https://openapi-generator.tech); DO NOT EDIT.
|
||||
|
||||
package postgresflexalpha
|
||||
|
|
@ -1,158 +0,0 @@
|
|||
package wait
|
||||
|
||||
import (
|
||||
"context"
|
||||
"fmt"
|
||||
"time"
|
||||
|
||||
"github.com/hashicorp/terraform-plugin-log/tflog"
|
||||
postgresflex "github.com/mhenselin/terraform-provider-stackitprivatepreview/pkg/postgresflexalpha"
|
||||
|
||||
"github.com/stackitcloud/stackit-sdk-go/core/oapierror"
|
||||
"github.com/stackitcloud/stackit-sdk-go/core/wait"
|
||||
)
|
||||
|
||||
// "READY" "PENDING" "PROGRESSING" "FAILURE" "UNKNOWN" "TERMINATING"
|
||||
const (
|
||||
InstanceStateEmpty = ""
|
||||
InstanceStateProgressing = "PROGRESSING"
|
||||
InstanceStateSuccess = "READY"
|
||||
InstanceStateFailed = "FAILURE"
|
||||
InstanceStateTerminating = "TERMINATING"
|
||||
InstanceStateUnknown = "UNKNOWN"
|
||||
InstanceStatePending = "PENDING"
|
||||
)
|
||||
|
||||
// APIClientInstanceInterface Interface needed for tests
|
||||
type APIClientInstanceInterface interface {
|
||||
GetInstanceRequestExecute(ctx context.Context, projectId, region, instanceId string) (
|
||||
*postgresflex.GetInstanceResponse,
|
||||
error,
|
||||
)
|
||||
|
||||
ListUsersRequestExecute(
|
||||
ctx context.Context,
|
||||
projectId string,
|
||||
region string,
|
||||
instanceId string,
|
||||
) (*postgresflex.ListUserResponse, error)
|
||||
}
|
||||
|
||||
// APIClientUserInterface Interface needed for tests
|
||||
type APIClientUserInterface interface {
|
||||
GetUserRequestExecute(ctx context.Context, projectId, region, instanceId string, userId int64) (
|
||||
*postgresflex.GetUserResponse,
|
||||
error,
|
||||
)
|
||||
}
|
||||
|
||||
// CreateInstanceWaitHandler will wait for instance creation
|
||||
func CreateInstanceWaitHandler(
|
||||
ctx context.Context, a APIClientInstanceInterface, projectId, region,
|
||||
instanceId string,
|
||||
) *wait.AsyncActionHandler[postgresflex.GetInstanceResponse] {
|
||||
instanceCreated := false
|
||||
var instanceGetResponse *postgresflex.GetInstanceResponse
|
||||
|
||||
handler := wait.New(
|
||||
func() (waitFinished bool, response *postgresflex.GetInstanceResponse, err error) {
|
||||
if !instanceCreated {
|
||||
s, err := a.GetInstanceRequestExecute(ctx, projectId, region, instanceId)
|
||||
if err != nil {
|
||||
return false, nil, err
|
||||
}
|
||||
if s == nil || s.Id == nil || *s.Id != instanceId || s.Status == nil {
|
||||
return false, nil, nil
|
||||
}
|
||||
switch *s.Status {
|
||||
default:
|
||||
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:
|
||||
if s.Network == nil || s.Network.InstanceAddress == nil {
|
||||
tflog.Info(ctx, "Waiting for instance_address")
|
||||
return false, nil, nil
|
||||
}
|
||||
if s.Network.RouterAddress == nil {
|
||||
tflog.Info(ctx, "Waiting for router_address")
|
||||
return false, nil, nil
|
||||
}
|
||||
instanceCreated = true
|
||||
instanceGetResponse = s
|
||||
case InstanceStateFailed:
|
||||
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)
|
||||
}
|
||||
}
|
||||
|
||||
tflog.Info(ctx, "Waiting for instance (calling list users")
|
||||
// // User operations aren't available right after an instance is deemed successful
|
||||
// // To check if they are, perform a users request
|
||||
_, err = a.ListUsersRequestExecute(ctx, projectId, region, instanceId)
|
||||
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
|
||||
if !ok {
|
||||
return false, nil, err
|
||||
}
|
||||
if oapiErr.StatusCode < 500 {
|
||||
return true, instanceGetResponse, fmt.Errorf(
|
||||
"users request after instance creation returned %d status code",
|
||||
oapiErr.StatusCode,
|
||||
)
|
||||
}
|
||||
return false, nil, nil
|
||||
},
|
||||
)
|
||||
// Sleep before wait is set because sometimes API returns 404 right after creation request
|
||||
handler.SetTimeout(90 * time.Minute).SetSleepBeforeWait(30 * time.Second)
|
||||
return handler
|
||||
}
|
||||
|
||||
// PartialUpdateInstanceWaitHandler will wait for instance update
|
||||
func PartialUpdateInstanceWaitHandler(
|
||||
ctx context.Context, a APIClientInstanceInterface, projectId, region,
|
||||
instanceId string,
|
||||
) *wait.AsyncActionHandler[postgresflex.GetInstanceResponse] {
|
||||
handler := wait.New(
|
||||
func() (waitFinished bool, response *postgresflex.GetInstanceResponse, err error) {
|
||||
s, err := a.GetInstanceRequestExecute(ctx, projectId, region, instanceId)
|
||||
if err != nil {
|
||||
return false, nil, err
|
||||
}
|
||||
if s == nil || s.Id == nil || *s.Id != instanceId || s.Status == nil {
|
||||
return false, nil, nil
|
||||
}
|
||||
switch *s.Status {
|
||||
default:
|
||||
return true, s, fmt.Errorf("instance with id %s has unexpected status %s", instanceId, *s.Status)
|
||||
case InstanceStateEmpty:
|
||||
return false, nil, nil
|
||||
case InstanceStateUnknown:
|
||||
return false, nil, nil
|
||||
case InstanceStateProgressing:
|
||||
return false, nil, nil
|
||||
case InstanceStatePending:
|
||||
return false, nil, nil
|
||||
case InstanceStateTerminating:
|
||||
return false, nil, nil
|
||||
case InstanceStateSuccess:
|
||||
return true, s, nil
|
||||
case InstanceStateFailed:
|
||||
return true, s, fmt.Errorf("update failed for instance with id %s", instanceId)
|
||||
}
|
||||
},
|
||||
)
|
||||
handler.SetTimeout(45 * time.Minute)
|
||||
return handler
|
||||
}
|
||||
|
|
@ -1,335 +0,0 @@
|
|||
// Copyright (c) STACKIT
|
||||
|
||||
package wait
|
||||
|
||||
import (
|
||||
"context"
|
||||
"testing"
|
||||
"time"
|
||||
|
||||
"github.com/google/go-cmp/cmp"
|
||||
postgresflex "github.com/mhenselin/terraform-provider-stackitprivatepreview/pkg/postgresflexalpha"
|
||||
"github.com/stackitcloud/stackit-sdk-go/core/oapierror"
|
||||
"github.com/stackitcloud/stackit-sdk-go/core/utils"
|
||||
)
|
||||
|
||||
// Used for testing instance operations
|
||||
type apiClientInstanceMocked struct {
|
||||
instanceId string
|
||||
instanceState string
|
||||
instanceNetwork postgresflex.InstanceNetwork
|
||||
instanceIsForceDeleted bool
|
||||
instanceGetFails bool
|
||||
usersGetErrorStatus int
|
||||
}
|
||||
|
||||
func (a *apiClientInstanceMocked) GetInstanceRequestExecute(
|
||||
_ context.Context,
|
||||
_, _, _ string,
|
||||
) (*postgresflex.GetInstanceResponse, error) {
|
||||
if a.instanceGetFails {
|
||||
return nil, &oapierror.GenericOpenAPIError{
|
||||
StatusCode: 500,
|
||||
}
|
||||
}
|
||||
|
||||
if a.instanceIsForceDeleted {
|
||||
return nil, &oapierror.GenericOpenAPIError{
|
||||
StatusCode: 404,
|
||||
}
|
||||
}
|
||||
|
||||
return &postgresflex.GetInstanceResponse{
|
||||
Id: &a.instanceId,
|
||||
Status: postgresflex.GetInstanceResponseGetStatusAttributeType(&a.instanceState),
|
||||
Network: postgresflex.GetInstanceResponseGetNetworkAttributeType(&a.instanceNetwork),
|
||||
}, nil
|
||||
}
|
||||
|
||||
func (a *apiClientInstanceMocked) ListUsersRequestExecute(
|
||||
_ context.Context,
|
||||
_, _, _ string,
|
||||
) (*postgresflex.ListUserResponse, error) {
|
||||
if a.usersGetErrorStatus != 0 {
|
||||
return nil, &oapierror.GenericOpenAPIError{
|
||||
StatusCode: a.usersGetErrorStatus,
|
||||
}
|
||||
}
|
||||
|
||||
aux := int64(0)
|
||||
return &postgresflex.ListUserResponse{
|
||||
Pagination: &postgresflex.Pagination{
|
||||
TotalRows: &aux,
|
||||
},
|
||||
Users: &[]postgresflex.ListUser{},
|
||||
}, nil
|
||||
}
|
||||
|
||||
func TestCreateInstanceWaitHandler(t *testing.T) {
|
||||
tests := []struct {
|
||||
desc string
|
||||
instanceGetFails bool
|
||||
instanceState string
|
||||
instanceNetwork postgresflex.InstanceNetwork
|
||||
usersGetErrorStatus int
|
||||
wantErr bool
|
||||
wantRes *postgresflex.GetInstanceResponse
|
||||
}{
|
||||
{
|
||||
desc: "create_succeeded",
|
||||
instanceGetFails: false,
|
||||
instanceState: InstanceStateSuccess,
|
||||
instanceNetwork: postgresflex.InstanceNetwork{
|
||||
AccessScope: nil,
|
||||
Acl: nil,
|
||||
InstanceAddress: utils.Ptr("10.0.0.1"),
|
||||
RouterAddress: utils.Ptr("10.0.0.1"),
|
||||
},
|
||||
wantErr: false,
|
||||
wantRes: &postgresflex.GetInstanceResponse{
|
||||
Id: utils.Ptr("foo-bar"),
|
||||
Status: postgresflex.GetInstanceResponseGetStatusAttributeType(utils.Ptr(InstanceStateSuccess)),
|
||||
Network: &postgresflex.InstanceNetwork{
|
||||
AccessScope: nil,
|
||||
Acl: nil,
|
||||
InstanceAddress: utils.Ptr("10.0.0.1"),
|
||||
RouterAddress: utils.Ptr("10.0.0.1"),
|
||||
},
|
||||
},
|
||||
},
|
||||
{
|
||||
desc: "create_failed",
|
||||
instanceGetFails: false,
|
||||
instanceState: InstanceStateFailed,
|
||||
instanceNetwork: postgresflex.InstanceNetwork{
|
||||
AccessScope: nil,
|
||||
Acl: nil,
|
||||
InstanceAddress: utils.Ptr("10.0.0.1"),
|
||||
RouterAddress: utils.Ptr("10.0.0.1"),
|
||||
},
|
||||
wantErr: true,
|
||||
wantRes: nil,
|
||||
},
|
||||
{
|
||||
desc: "create_failed_2",
|
||||
instanceGetFails: false,
|
||||
instanceState: InstanceStateEmpty,
|
||||
instanceNetwork: postgresflex.InstanceNetwork{
|
||||
AccessScope: nil,
|
||||
Acl: nil,
|
||||
InstanceAddress: utils.Ptr("10.0.0.1"),
|
||||
RouterAddress: utils.Ptr("10.0.0.1"),
|
||||
},
|
||||
wantErr: true,
|
||||
wantRes: nil,
|
||||
},
|
||||
{
|
||||
desc: "instance_get_fails",
|
||||
instanceGetFails: true,
|
||||
wantErr: true,
|
||||
wantRes: nil,
|
||||
},
|
||||
{
|
||||
desc: "users_get_fails",
|
||||
instanceGetFails: false,
|
||||
instanceState: InstanceStateSuccess,
|
||||
instanceNetwork: postgresflex.InstanceNetwork{
|
||||
AccessScope: nil,
|
||||
Acl: nil,
|
||||
InstanceAddress: utils.Ptr("10.0.0.1"),
|
||||
RouterAddress: utils.Ptr("10.0.0.1"),
|
||||
},
|
||||
usersGetErrorStatus: 500,
|
||||
wantErr: true,
|
||||
wantRes: nil,
|
||||
},
|
||||
{
|
||||
desc: "users_get_fails_2",
|
||||
instanceGetFails: false,
|
||||
instanceState: InstanceStateSuccess,
|
||||
instanceNetwork: postgresflex.InstanceNetwork{
|
||||
AccessScope: nil,
|
||||
Acl: nil,
|
||||
InstanceAddress: utils.Ptr("10.0.0.1"),
|
||||
RouterAddress: utils.Ptr("10.0.0.1"),
|
||||
},
|
||||
usersGetErrorStatus: 400,
|
||||
wantErr: true,
|
||||
wantRes: &postgresflex.GetInstanceResponse{
|
||||
Id: utils.Ptr("foo-bar"),
|
||||
Status: postgresflex.GetInstanceResponseGetStatusAttributeType(utils.Ptr(InstanceStateSuccess)),
|
||||
Network: &postgresflex.InstanceNetwork{
|
||||
AccessScope: nil,
|
||||
Acl: nil,
|
||||
InstanceAddress: utils.Ptr("10.0.0.1"),
|
||||
RouterAddress: utils.Ptr("10.0.0.1"),
|
||||
},
|
||||
},
|
||||
},
|
||||
{
|
||||
desc: "fail when response has no instance address",
|
||||
instanceGetFails: false,
|
||||
instanceState: InstanceStateSuccess,
|
||||
instanceNetwork: postgresflex.InstanceNetwork{
|
||||
AccessScope: postgresflex.InstanceNetworkGetAccessScopeAttributeType(utils.Ptr("SNA")),
|
||||
Acl: nil,
|
||||
InstanceAddress: nil,
|
||||
RouterAddress: utils.Ptr("10.0.0.1"),
|
||||
},
|
||||
wantErr: true,
|
||||
wantRes: nil,
|
||||
},
|
||||
{
|
||||
desc: "timeout",
|
||||
instanceGetFails: false,
|
||||
instanceState: InstanceStateProgressing,
|
||||
instanceNetwork: postgresflex.InstanceNetwork{
|
||||
AccessScope: postgresflex.InstanceNetworkGetAccessScopeAttributeType(utils.Ptr("SNA")),
|
||||
Acl: nil,
|
||||
InstanceAddress: utils.Ptr("10.0.0.1"),
|
||||
RouterAddress: utils.Ptr("10.0.0.1"),
|
||||
},
|
||||
wantErr: true,
|
||||
wantRes: nil,
|
||||
},
|
||||
}
|
||||
for _, tt := range tests {
|
||||
t.Run(
|
||||
tt.desc, func(t *testing.T) {
|
||||
instanceId := "foo-bar"
|
||||
|
||||
apiClient := &apiClientInstanceMocked{
|
||||
instanceId: instanceId,
|
||||
instanceState: tt.instanceState,
|
||||
instanceNetwork: tt.instanceNetwork,
|
||||
instanceGetFails: tt.instanceGetFails,
|
||||
usersGetErrorStatus: tt.usersGetErrorStatus,
|
||||
}
|
||||
|
||||
handler := CreateInstanceWaitHandler(context.Background(), apiClient, "", "", instanceId)
|
||||
|
||||
gotRes, err := handler.SetTimeout(10 * time.Millisecond).SetSleepBeforeWait(1 * time.Millisecond).WaitWithContext(context.Background())
|
||||
if (err != nil) != tt.wantErr {
|
||||
t.Fatalf("handler error = %v, wantErr %v", err, tt.wantErr)
|
||||
}
|
||||
|
||||
if !cmp.Equal(gotRes, tt.wantRes) {
|
||||
t.Fatalf("handler gotRes = %v, want %v", gotRes, tt.wantRes)
|
||||
}
|
||||
},
|
||||
)
|
||||
}
|
||||
}
|
||||
|
||||
func TestUpdateInstanceWaitHandler(t *testing.T) {
|
||||
tests := []struct {
|
||||
desc string
|
||||
instanceGetFails bool
|
||||
instanceState string
|
||||
instanceNetwork postgresflex.InstanceNetwork
|
||||
wantErr bool
|
||||
wantRes *postgresflex.GetInstanceResponse
|
||||
}{
|
||||
{
|
||||
desc: "update_succeeded",
|
||||
instanceGetFails: false,
|
||||
instanceState: InstanceStateSuccess,
|
||||
instanceNetwork: postgresflex.InstanceNetwork{
|
||||
AccessScope: nil,
|
||||
Acl: nil,
|
||||
InstanceAddress: utils.Ptr("10.0.0.1"),
|
||||
RouterAddress: utils.Ptr("10.0.0.1"),
|
||||
},
|
||||
wantErr: false,
|
||||
wantRes: &postgresflex.GetInstanceResponse{
|
||||
Id: utils.Ptr("foo-bar"),
|
||||
Status: postgresflex.GetInstanceResponseGetStatusAttributeType(utils.Ptr(InstanceStateSuccess)),
|
||||
Network: &postgresflex.InstanceNetwork{
|
||||
AccessScope: nil,
|
||||
Acl: nil,
|
||||
InstanceAddress: utils.Ptr("10.0.0.1"),
|
||||
RouterAddress: utils.Ptr("10.0.0.1"),
|
||||
},
|
||||
},
|
||||
},
|
||||
{
|
||||
desc: "update_failed",
|
||||
instanceGetFails: false,
|
||||
instanceState: InstanceStateFailed,
|
||||
instanceNetwork: postgresflex.InstanceNetwork{
|
||||
AccessScope: nil,
|
||||
Acl: nil,
|
||||
InstanceAddress: utils.Ptr("10.0.0.1"),
|
||||
RouterAddress: utils.Ptr("10.0.0.1"),
|
||||
},
|
||||
wantErr: true,
|
||||
wantRes: &postgresflex.GetInstanceResponse{
|
||||
Id: utils.Ptr("foo-bar"),
|
||||
Status: postgresflex.GetInstanceResponseGetStatusAttributeType(utils.Ptr(InstanceStateFailed)),
|
||||
Network: &postgresflex.InstanceNetwork{
|
||||
AccessScope: nil,
|
||||
Acl: nil,
|
||||
InstanceAddress: utils.Ptr("10.0.0.1"),
|
||||
RouterAddress: utils.Ptr("10.0.0.1"),
|
||||
},
|
||||
},
|
||||
},
|
||||
{
|
||||
desc: "update_failed_2",
|
||||
instanceGetFails: false,
|
||||
instanceState: InstanceStateEmpty,
|
||||
instanceNetwork: postgresflex.InstanceNetwork{
|
||||
AccessScope: nil,
|
||||
Acl: nil,
|
||||
InstanceAddress: utils.Ptr("10.0.0.1"),
|
||||
RouterAddress: utils.Ptr("10.0.0.1"),
|
||||
},
|
||||
wantErr: true,
|
||||
wantRes: nil,
|
||||
},
|
||||
{
|
||||
desc: "get_fails",
|
||||
instanceGetFails: true,
|
||||
wantErr: true,
|
||||
wantRes: nil,
|
||||
},
|
||||
{
|
||||
desc: "timeout",
|
||||
instanceGetFails: false,
|
||||
instanceState: InstanceStateProgressing,
|
||||
instanceNetwork: postgresflex.InstanceNetwork{
|
||||
AccessScope: nil,
|
||||
Acl: nil,
|
||||
InstanceAddress: utils.Ptr("10.0.0.1"),
|
||||
RouterAddress: utils.Ptr("10.0.0.1"),
|
||||
},
|
||||
wantErr: true,
|
||||
wantRes: nil,
|
||||
},
|
||||
}
|
||||
for _, tt := range tests {
|
||||
t.Run(
|
||||
tt.desc, func(t *testing.T) {
|
||||
instanceId := "foo-bar"
|
||||
|
||||
apiClient := &apiClientInstanceMocked{
|
||||
instanceId: instanceId,
|
||||
instanceState: tt.instanceState,
|
||||
instanceNetwork: tt.instanceNetwork,
|
||||
instanceGetFails: tt.instanceGetFails,
|
||||
}
|
||||
|
||||
handler := PartialUpdateInstanceWaitHandler(context.Background(), apiClient, "", "", instanceId)
|
||||
|
||||
gotRes, err := handler.SetTimeout(10 * time.Millisecond).WaitWithContext(context.Background())
|
||||
if (err != nil) != tt.wantErr {
|
||||
t.Fatalf("handler error = %v, wantErr %v", err, tt.wantErr)
|
||||
}
|
||||
|
||||
if !cmp.Equal(gotRes, tt.wantRes) {
|
||||
t.Fatalf("handler gotRes = %v, want %v", gotRes, tt.wantRes)
|
||||
}
|
||||
},
|
||||
)
|
||||
}
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue