Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ require (
github.com/stackitcloud/stackit-sdk-go/services/alb v0.12.1
github.com/stackitcloud/stackit-sdk-go/services/cdn v1.13.0
github.com/stackitcloud/stackit-sdk-go/services/dns v0.19.1
github.com/stackitcloud/stackit-sdk-go/services/edge v0.8.0
github.com/stackitcloud/stackit-sdk-go/services/edge v0.8.1
github.com/stackitcloud/stackit-sdk-go/services/git v0.11.0
github.com/stackitcloud/stackit-sdk-go/services/iaas v1.3.5
github.com/stackitcloud/stackit-sdk-go/services/kms v1.6.0
Expand All @@ -29,7 +29,7 @@ require (
github.com/stackitcloud/stackit-sdk-go/services/objectstorage v1.7.0
github.com/stackitcloud/stackit-sdk-go/services/observability v0.17.0
github.com/stackitcloud/stackit-sdk-go/services/opensearch v0.26.1
github.com/stackitcloud/stackit-sdk-go/services/postgresflex v1.3.5
github.com/stackitcloud/stackit-sdk-go/services/postgresflex v1.6.2
github.com/stackitcloud/stackit-sdk-go/services/rabbitmq v0.26.0
github.com/stackitcloud/stackit-sdk-go/services/redis v0.25.6
github.com/stackitcloud/stackit-sdk-go/services/resourcemanager v0.20.0
Expand Down
4 changes: 4 additions & 0 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -165,6 +165,8 @@ github.com/stackitcloud/stackit-sdk-go/services/dns v0.19.1 h1:VfszhFq/Snsd0Lnfl
github.com/stackitcloud/stackit-sdk-go/services/dns v0.19.1/go.mod h1:gBv6YkB3Xf3c0ZXg2GwtWY8zExwGPF/Ag114XiiERxg=
github.com/stackitcloud/stackit-sdk-go/services/edge v0.8.0 h1:lsOTEvItzrUerCzUodyyOy6pZ4QiSzwID7U20ZvZvHw=
github.com/stackitcloud/stackit-sdk-go/services/edge v0.8.0/go.mod h1:CfqSEGCW0b5JlijCwtUT1kfjThmQ5jXX47TWrdD5rTU=
github.com/stackitcloud/stackit-sdk-go/services/edge v0.8.1 h1:G21hx6vztR1Np+K+MXsK1td/CKbKHdLK89zvtH6OoKk=
github.com/stackitcloud/stackit-sdk-go/services/edge v0.8.1/go.mod h1:qHuMB/qt7w1u5Xk3qzP3pJFXjTqPrtpM2bMhKpIvM3I=
github.com/stackitcloud/stackit-sdk-go/services/git v0.11.0 h1:siKBCYl7BwR5S25Y4SwUAX6eFTXSCkQ+8JIQEqyKIXo=
github.com/stackitcloud/stackit-sdk-go/services/git v0.11.0/go.mod h1:QKy74hhLVZKXItw3y+elF8s9QezFqpEsAUmaqvNDzYs=
github.com/stackitcloud/stackit-sdk-go/services/iaas v1.3.5 h1:W57+XRa8wTLsi5CV9Tqa7mGgt/PvlRM//RurXSmvII8=
Expand All @@ -191,6 +193,8 @@ github.com/stackitcloud/stackit-sdk-go/services/opensearch v0.26.1 h1:AO5Np67/w0
github.com/stackitcloud/stackit-sdk-go/services/opensearch v0.26.1/go.mod h1:Reo2Nk3yiA686quUMrk0eKwzpzaAZ7KwmzHzScNdG8Q=
github.com/stackitcloud/stackit-sdk-go/services/postgresflex v1.3.5 h1:H67e3KnHQx954yI8fuQmxXwRf/myqAdLg2KvxImp00g=
github.com/stackitcloud/stackit-sdk-go/services/postgresflex v1.3.5/go.mod h1:xmAWk9eom8wznvLuLfm0F4xyeiBX8LaggXsKFmos+dw=
github.com/stackitcloud/stackit-sdk-go/services/postgresflex v1.6.2 h1:5Op07pEs6dcJxfi2UjT1645k1uMf1xMbY8/D3A797aA=
github.com/stackitcloud/stackit-sdk-go/services/postgresflex v1.6.2/go.mod h1:AqFWa9kddt2Wqe8k1Kw5FB1mlHG30K1FGsJx8dw/r1c=
github.com/stackitcloud/stackit-sdk-go/services/rabbitmq v0.26.0 h1:/8lmviszgrB+0Cz7HdhFELyTiTeqIs7LfnI6sNX4rW8=
github.com/stackitcloud/stackit-sdk-go/services/rabbitmq v0.26.0/go.mod h1:hnhvlLX1Y71R8KIQqLBeoSZqkU5ZJOG0J4wz0LeUdaw=
github.com/stackitcloud/stackit-sdk-go/services/redis v0.25.6 h1:CXM9cZ9WeTyJd+Aw/hnJnDsKRVAQi4qgtd0RJ3zoPwo=
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ import (
"github.com/stackitcloud/terraform-provider-stackit/stackit/internal/validate"

"github.com/hashicorp/terraform-plugin-framework/datasource/schema"
"github.com/stackitcloud/stackit-sdk-go/services/postgresflex"
postgresflex "github.com/stackitcloud/stackit-sdk-go/services/postgresflex/v2api"
)

// Ensure the implementation satisfies the expected interfaces.
Expand Down
12 changes: 6 additions & 6 deletions stackit/internal/services/postgresflex/database/resource.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ import (
"github.com/hashicorp/terraform-plugin-framework/resource/schema/stringplanmodifier"
"github.com/hashicorp/terraform-plugin-framework/types"
"github.com/stackitcloud/stackit-sdk-go/core/oapierror"
"github.com/stackitcloud/stackit-sdk-go/services/postgresflex"
postgresflex "github.com/stackitcloud/stackit-sdk-go/services/postgresflex/v2api"
)

// Ensure the implementation satisfies the expected interfaces.
Expand Down Expand Up @@ -214,7 +214,7 @@ func (r *databaseResource) Create(ctx context.Context, req resource.CreateReques
return
}
// Create new database
databaseResp, err := r.client.CreateDatabase(ctx, projectId, region, instanceId).CreateDatabasePayload(*payload).Execute()
databaseResp, err := r.client.DefaultAPI.CreateDatabase(ctx, projectId, region, instanceId).CreateDatabasePayload(*payload).Execute()
if err != nil {
core.LogAndAddError(ctx, &resp.Diagnostics, "Error creating database", fmt.Sprintf("Calling API: %v", err))
return
Expand Down Expand Up @@ -327,7 +327,7 @@ func (r *databaseResource) Delete(ctx context.Context, req resource.DeleteReques
ctx = tflog.SetField(ctx, "region", region)

// Delete existing record set
err := r.client.DeleteDatabase(ctx, projectId, region, instanceId, databaseId).Execute()
err := r.client.DefaultAPI.DeleteDatabase(ctx, projectId, region, instanceId, databaseId).Execute()
if err != nil {
core.LogAndAddError(ctx, &resp.Diagnostics, "Error deleting database", fmt.Sprintf("Calling API: %v", err))
}
Expand Down Expand Up @@ -389,7 +389,7 @@ func mapFields(databaseResp *postgresflex.InstanceDatabase, model *Model, region
model.Region = types.StringValue(region)

if databaseResp.Options != nil {
owner, ok := (*databaseResp.Options)["owner"]
owner, ok := (databaseResp.Options)["owner"]
if ok {
ownerStr, ok := owner.(string)
if !ok {
Expand Down Expand Up @@ -422,14 +422,14 @@ var errDatabaseNotFound = errors.New("database not found")

// The API does not have a GetDatabase endpoint, only ListDatabases
func getDatabase(ctx context.Context, client *postgresflex.APIClient, projectId, region, instanceId, databaseId string) (*postgresflex.InstanceDatabase, error) {
resp, err := client.ListDatabases(ctx, projectId, region, instanceId).Execute()
resp, err := client.DefaultAPI.ListDatabases(ctx, projectId, region, instanceId).Execute()
if err != nil {
return nil, err
}
if resp == nil || resp.Databases == nil {
return nil, fmt.Errorf("response is nil")
}
for _, database := range *resp.Databases {
for _, database := range resp.Databases {
if database.Id != nil && *database.Id == databaseId {
return &database, nil
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import (

"github.com/google/go-cmp/cmp"
"github.com/hashicorp/terraform-plugin-framework/types"
"github.com/stackitcloud/stackit-sdk-go/services/postgresflex"
postgresflex "github.com/stackitcloud/stackit-sdk-go/services/postgresflex/v2api"
)

func TestMapFields(t *testing.T) {
Expand Down Expand Up @@ -39,7 +39,7 @@ func TestMapFields(t *testing.T) {
&postgresflex.InstanceDatabase{
Id: new("uid"),
Name: new("dbname"),
Options: &map[string]any{
Options: map[string]any{
"owner": "username",
},
},
Expand All @@ -60,7 +60,7 @@ func TestMapFields(t *testing.T) {
&postgresflex.InstanceDatabase{
Id: new("uid"),
Name: new(""),
Options: &map[string]any{
Options: map[string]any{
"owner": "",
},
},
Expand Down Expand Up @@ -95,7 +95,7 @@ func TestMapFields(t *testing.T) {
&postgresflex.InstanceDatabase{
Id: new(""),
Name: new("dbname"),
Options: &map[string]any{
Options: map[string]any{
"owner": "username",
},
},
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,8 +18,8 @@ import (

"github.com/hashicorp/terraform-plugin-framework/datasource/schema"
"github.com/hashicorp/terraform-plugin-framework/types"
"github.com/stackitcloud/stackit-sdk-go/services/postgresflex"
"github.com/stackitcloud/stackit-sdk-go/services/postgresflex/wait"
postgresflex "github.com/stackitcloud/stackit-sdk-go/services/postgresflex/v2api"
"github.com/stackitcloud/stackit-sdk-go/services/postgresflex/v2api/wait"
)

// Ensure the implementation satisfies the expected interfaces.
Expand Down Expand Up @@ -123,7 +123,7 @@ func (r *instanceDataSource) Schema(_ context.Context, _ datasource.SchemaReques
},
},
},
"replicas": schema.Int64Attribute{
"replicas": schema.Int32Attribute{
Computed: true,
},
"storage": schema.SingleNestedAttribute{
Expand Down Expand Up @@ -166,7 +166,7 @@ func (r *instanceDataSource) Read(ctx context.Context, req datasource.ReadReques
ctx = tflog.SetField(ctx, "project_id", projectId)
ctx = tflog.SetField(ctx, "instance_id", instanceId)
ctx = tflog.SetField(ctx, "region", region)
instanceResp, err := r.client.GetInstance(ctx, projectId, region, instanceId).Execute()
instanceResp, err := r.client.DefaultAPI.GetInstance(ctx, projectId, region, instanceId).Execute()
if err != nil {
utils.LogError(
ctx,
Expand Down
58 changes: 30 additions & 28 deletions stackit/internal/services/postgresflex/instance/resource.go
Original file line number Diff line number Diff line change
Expand Up @@ -28,8 +28,8 @@ import (
"github.com/hashicorp/terraform-plugin-framework/resource/schema/stringplanmodifier"
"github.com/hashicorp/terraform-plugin-framework/types"
"github.com/stackitcloud/stackit-sdk-go/core/oapierror"
"github.com/stackitcloud/stackit-sdk-go/services/postgresflex"
"github.com/stackitcloud/stackit-sdk-go/services/postgresflex/wait"
postgresflex "github.com/stackitcloud/stackit-sdk-go/services/postgresflex/v2api"
"github.com/stackitcloud/stackit-sdk-go/services/postgresflex/v2api/wait"
)

// Ensure the implementation satisfies the expected interfaces.
Expand All @@ -48,7 +48,7 @@ type Model struct {
ACL types.List `tfsdk:"acl"`
BackupSchedule types.String `tfsdk:"backup_schedule"`
Flavor types.Object `tfsdk:"flavor"`
Replicas types.Int64 `tfsdk:"replicas"`
Replicas types.Int32 `tfsdk:"replicas"`
Storage types.Object `tfsdk:"storage"`
Version types.String `tfsdk:"version"`
Region types.String `tfsdk:"region"`
Expand Down Expand Up @@ -237,7 +237,7 @@ func (r *instanceResource) Schema(_ context.Context, req resource.SchemaRequest,
},
},
},
"replicas": schema.Int64Attribute{
"replicas": schema.Int32Attribute{
Description: descriptions["replicas"],
Required: true,
},
Expand Down Expand Up @@ -303,7 +303,7 @@ func (r *instanceResource) Create(ctx context.Context, req resource.CreateReques
if resp.Diagnostics.HasError() {
return
}
err := loadFlavorId(ctx, r.client, &model, flavor)
err := loadFlavorId(ctx, r.client.DefaultAPI, &model, flavor)
if err != nil {
core.LogAndAddError(ctx, &resp.Diagnostics, "Error creating instance", fmt.Sprintf("Loading flavor ID: %v", err))
return
Expand All @@ -325,7 +325,7 @@ func (r *instanceResource) Create(ctx context.Context, req resource.CreateReques
return
}
// Create new instance
createResp, err := r.client.CreateInstance(ctx, projectId, region).CreateInstancePayload(*payload).Execute()
createResp, err := r.client.DefaultAPI.CreateInstance(ctx, projectId, region).CreateInstancePayload(*payload).Execute()
if err != nil {
core.LogAndAddError(ctx, &resp.Diagnostics, "Error creating instance", fmt.Sprintf("Calling API: %v", err))
return
Expand All @@ -348,7 +348,7 @@ func (r *instanceResource) Create(ctx context.Context, req resource.CreateReques
return
}

waitResp, err := wait.CreateInstanceWaitHandler(ctx, r.client, projectId, region, instanceId).WaitWithContext(ctx)
waitResp, err := wait.CreateInstanceWaitHandler(ctx, r.client.DefaultAPI, projectId, region, instanceId).WaitWithContext(ctx)
if err != nil {
core.LogAndAddError(ctx, &resp.Diagnostics, "Error creating instance", fmt.Sprintf("Instance creation waiting: %v", err))
return
Expand Down Expand Up @@ -404,7 +404,7 @@ func (r *instanceResource) Read(ctx context.Context, req resource.ReadRequest, r
}
}

instanceResp, err := r.client.GetInstance(ctx, projectId, region, instanceId).Execute()
instanceResp, err := r.client.DefaultAPI.GetInstance(ctx, projectId, region, instanceId).Execute()
if err != 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 && oapiErr.StatusCode == http.StatusNotFound {
Expand Down Expand Up @@ -471,7 +471,7 @@ func (r *instanceResource) Update(ctx context.Context, req resource.UpdateReques
if resp.Diagnostics.HasError() {
return
}
err := loadFlavorId(ctx, r.client, &model, flavor)
err := loadFlavorId(ctx, r.client.DefaultAPI, &model, flavor)
if err != nil {
core.LogAndAddError(ctx, &resp.Diagnostics, "Error updating instance", fmt.Sprintf("Loading flavor ID: %v", err))
return
Expand All @@ -493,15 +493,15 @@ func (r *instanceResource) Update(ctx context.Context, req resource.UpdateReques
return
}
// Update existing instance
_, err = r.client.PartialUpdateInstance(ctx, projectId, region, instanceId).PartialUpdateInstancePayload(*payload).Execute()
_, err = r.client.DefaultAPI.PartialUpdateInstance(ctx, projectId, region, instanceId).PartialUpdateInstancePayload(*payload).Execute()
if err != nil {
core.LogAndAddError(ctx, &resp.Diagnostics, "Error updating instance", err.Error())
return
}

ctx = core.LogResponse(ctx)

waitResp, err := wait.PartialUpdateInstanceWaitHandler(ctx, r.client, projectId, region, instanceId).WaitWithContext(ctx)
waitResp, err := wait.PartialUpdateInstanceWaitHandler(ctx, r.client.DefaultAPI, projectId, region, instanceId).WaitWithContext(ctx)
if err != nil {
core.LogAndAddError(ctx, &resp.Diagnostics, "Error updating instance", fmt.Sprintf("Instance update waiting: %v", err))
return
Expand Down Expand Up @@ -541,15 +541,15 @@ func (r *instanceResource) Delete(ctx context.Context, req resource.DeleteReques
ctx = tflog.SetField(ctx, "region", region)

// Delete existing instance
err := r.client.DeleteInstance(ctx, projectId, region, instanceId).Execute()
err := r.client.DefaultAPI.DeleteInstance(ctx, projectId, region, instanceId).Execute()
if err != nil {
core.LogAndAddError(ctx, &resp.Diagnostics, "Error deleting instance", fmt.Sprintf("Calling API: %v", err))
return
}

ctx = core.LogResponse(ctx)

_, err = wait.DeleteInstanceWaitHandler(ctx, r.client, projectId, region, instanceId).SetTimeout(45 * time.Minute).WaitWithContext(ctx)
_, err = wait.DeleteInstanceWaitHandler(ctx, r.client.DefaultAPI, projectId, region, instanceId).SetTimeout(45 * time.Minute).WaitWithContext(ctx)
if err != nil {
core.LogAndAddError(ctx, &resp.Diagnostics, "Error deleting instance", fmt.Sprintf("Instance deletion waiting: %v", err))
return
Expand Down Expand Up @@ -604,7 +604,7 @@ func mapFields(ctx context.Context, resp *postgresflex.InstanceResponse, model *
if instance.Acl == nil || instance.Acl.Items == nil {
aclList = types.ListNull(types.StringType)
} else {
respACL := *instance.Acl.Items
respACL := instance.Acl.Items
modelACL, err := utils.ListValuetoStringSlice(model.ACL)
if err != nil {
return err
Expand Down Expand Up @@ -669,7 +669,7 @@ func mapFields(ctx context.Context, resp *postgresflex.InstanceResponse, model *
model.Name = types.StringPointerValue(instance.Name)
model.ACL = aclList
model.Flavor = flavorObject
model.Replicas = types.Int64PointerValue(instance.Replicas)
model.Replicas = types.Int32PointerValue(instance.Replicas)
model.Storage = storageObject
model.Version = types.StringPointerValue(instance.Version)
model.Region = types.StringValue(region)
Expand All @@ -691,18 +691,18 @@ func toCreatePayload(model *Model, acl []string, flavor *flavorModel, storage *s
}

return &postgresflex.CreateInstancePayload{
Acl: &postgresflex.ACL{
Items: &acl,
Acl: postgresflex.ACL{
Items: acl,
},
BackupSchedule: conversion.StringValueToPointer(model.BackupSchedule),
FlavorId: conversion.StringValueToPointer(flavor.Id),
Name: conversion.StringValueToPointer(model.Name),
Replicas: conversion.Int64ValueToPointer(model.Replicas),
Storage: &postgresflex.Storage{
BackupSchedule: model.BackupSchedule.ValueString(),
FlavorId: flavor.Id.ValueString(),
Name: model.Name.ValueString(),
Replicas: model.Replicas.ValueInt32(),
Storage: postgresflex.Storage{
Class: conversion.StringValueToPointer(storage.Class),
Size: conversion.Int64ValueToPointer(storage.Size),
},
Version: conversion.StringValueToPointer(model.Version),
Version: model.Version.ValueString(),
}, nil
}

Expand All @@ -722,18 +722,19 @@ func toUpdatePayload(model *Model, acl []string, flavor *flavorModel, storage *s

return &postgresflex.PartialUpdateInstancePayload{
Acl: &postgresflex.ACL{
Items: &acl,
Items: acl,
},
BackupSchedule: conversion.StringValueToPointer(model.BackupSchedule),
FlavorId: conversion.StringValueToPointer(flavor.Id),
Name: conversion.StringValueToPointer(model.Name),
Replicas: conversion.Int64ValueToPointer(model.Replicas),
Replicas: conversion.Int32ValueToPointer(model.Replicas),
Version: conversion.StringValueToPointer(model.Version),
}, nil
}

type postgresFlexClient interface {
ListFlavorsExecute(ctx context.Context, projectId string, region string) (*postgresflex.ListFlavorsResponse, error)
ListFlavors(ctx context.Context, projectId, region string) postgresflex.ApiListFlavorsRequest
ListFlavorsExecute(r postgresflex.ApiListFlavorsRequest) (*postgresflex.ListFlavorsResponse, error)
}

func loadFlavorId(ctx context.Context, client postgresFlexClient, model *Model, flavor *flavorModel) error {
Expand All @@ -754,7 +755,8 @@ func loadFlavorId(ctx context.Context, client postgresFlexClient, model *Model,

projectId := model.ProjectId.ValueString()
region := model.Region.ValueString()
res, err := client.ListFlavorsExecute(ctx, projectId, region)
req := client.ListFlavors(ctx, projectId, region)
res, err := client.ListFlavorsExecute(req)
if err != nil {
return fmt.Errorf("listing postgresflex flavors: %w", err)
}
Expand All @@ -763,7 +765,7 @@ func loadFlavorId(ctx context.Context, client postgresFlexClient, model *Model,
if res.Flavors == nil {
return fmt.Errorf("finding flavors for project %s", projectId)
}
for _, f := range *res.Flavors {
for _, f := range res.Flavors {
if f.Id == nil || f.Cpu == nil || f.Memory == nil {
continue
}
Expand Down
Loading
Loading