Fix: fix imports and names (#9)

* fix: add missing entries and correct refs

* fix: add missing docs

---------

Co-authored-by: Marcel S. Henselin <marcel.henselin@stackit.cloud>
This commit is contained in:
Marcel S. Henselin 2025-12-19 12:34:16 +01:00 committed by GitHub
parent db080dc89a
commit 944a75295f
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
19 changed files with 424 additions and 235 deletions

View file

@ -720,13 +720,13 @@ func mapFields(ctx context.Context, resp *postgresflexalpha.GetInstanceResponse,
"ram": flavor.RAM,
}
} else {
// TODO
//flavorValues = map[string]attr.Value{
// TODO @mhenselin
// flavorValues = map[string]attr.Value{
// "id": types.StringValue(*instance.FlavorId),
// "description": types.StringValue(*instance.FlavorId.Description),
// "cpu": types.Int64PointerValue(instance.FlavorId.Cpu),
// "ram": types.Int64PointerValue(instance.FlavorId.Memory),
//}
// }
}
flavorObject, diags := types.ObjectValue(flavorTypes, flavorValues)
if diags.HasError() {

View file

@ -14,8 +14,9 @@ import (
"github.com/mhenselin/terraform-provider-stackitprivatepreview/stackit/internal/core"
"github.com/mhenselin/terraform-provider-stackitprivatepreview/stackit/internal/testutil"
"github.com/stackitcloud/stackit-sdk-go/core/config"
"github.com/stackitcloud/stackit-sdk-go/services/postgresflex"
"github.com/stackitcloud/stackit-sdk-go/services/postgresflex/wait"
postgresflex "github.com/mhenselin/terraform-provider-stackitprivatepreview/pkg/postgresflexalpha"
"github.com/mhenselin/terraform-provider-stackitprivatepreview/pkg/postgresflexalpha/wait"
)
// Instance resource data
@ -344,18 +345,20 @@ func testAccCheckPostgresFlexDestroy(s *terraform.State) error {
instancesToDestroy = append(instancesToDestroy, instanceId)
}
instancesResp, err := client.ListInstances(ctx, testutil.ProjectId, testutil.Region).Execute()
instancesResp, err := client.ListInstancesRequest(ctx, testutil.ProjectId, testutil.Region).Execute()
if err != nil {
return fmt.Errorf("getting instancesResp: %w", err)
}
items := *instancesResp.Items
items := *instancesResp.Instances
for i := range items {
if items[i].Id == nil {
continue
}
if utils.Contains(instancesToDestroy, *items[i].Id) {
err := client.ForceDeleteInstanceExecute(ctx, testutil.ProjectId, testutil.Region, *items[i].Id)
// TODO @mhenselin - does force still exist?
// err := client.ForceDeleteInstanceExecute(ctx, testutil.ProjectId, testutil.Region, *items[i].Id)
err := client.DeleteInstanceRequestExecute(ctx, testutil.ProjectId, testutil.Region, *items[i].Id)
if err != nil {
return fmt.Errorf("deleting instance %s during CheckDestroy: %w", *items[i].Id, err)
}

View file

@ -6,6 +6,7 @@ import (
"net/http"
"strconv"
postgresflex "github.com/mhenselin/terraform-provider-stackitprivatepreview/pkg/postgresflexalpha"
"github.com/mhenselin/terraform-provider-stackitprivatepreview/stackit/internal/conversion"
postgresflexUtils "github.com/mhenselin/terraform-provider-stackitprivatepreview/stackit/internal/services/postgresflexalpha/utils"
@ -47,7 +48,7 @@ func NewUserDataSource() datasource.DataSource {
// userDataSource is the data source implementation.
type userDataSource struct {
client *postgresflexalpha.APIClient
client *postgresflex.APIClient
providerData core.ProviderData
}
@ -72,7 +73,7 @@ func (r *userDataSource) Configure(
return
}
apiClient := postgresflexalphaUtils.ConfigureClient(ctx, &r.providerData, &resp.Diagnostics)
apiClient := postgresflexUtils.ConfigureClient(ctx, &r.providerData, &resp.Diagnostics)
if resp.Diagnostics.HasError() {
return
}
@ -219,7 +220,7 @@ func (r *userDataSource) Read(
tflog.Info(ctx, "Postgres Flex user read")
}
func mapDataSourceFields(userResp *postgresflexalpha.GetUserResponse, model *DataSourceModel, region string) error {
func mapDataSourceFields(userResp *postgresflex.GetUserResponse, model *DataSourceModel, region string) error {
if userResp == nil {
return fmt.Errorf("response is nil")
}

View file

@ -6,8 +6,8 @@ import (
"github.com/google/go-cmp/cmp"
"github.com/hashicorp/terraform-plugin-framework/attr"
"github.com/hashicorp/terraform-plugin-framework/types"
"github.com/mhenselin/terraform-provider-stackitprivatepreview/pkg/postgresflexalpha"
"github.com/stackitcloud/stackit-sdk-go/core/utils"
"github.com/stackitcloud/terraform-provider-stackit/pkg/postgresflexalpha"
)
func TestMapDataSourceFields(t *testing.T) {

View file

@ -7,8 +7,11 @@ import (
"strconv"
"strings"
"github.com/mhenselin/terraform-provider-stackitprivatepreview/pkg/postgresflexalpha/wait"
postgresflexUtils "github.com/mhenselin/terraform-provider-stackitprivatepreview/stackit/internal/services/postgresflexalpha/utils"
postgresflex "github.com/mhenselin/terraform-provider-stackitprivatepreview/pkg/postgresflexalpha"
"github.com/hashicorp/terraform-plugin-framework-validators/setvalidator"
"github.com/hashicorp/terraform-plugin-framework-validators/stringvalidator"
"github.com/hashicorp/terraform-plugin-framework/schema/validator"
@ -59,7 +62,7 @@ func NewUserResource() resource.Resource {
// userResource is the resource implementation.
type userResource struct {
client *postgresflexalpha.APIClient
client *postgresflex.APIClient
providerData core.ProviderData
}
@ -110,7 +113,7 @@ func (r *userResource) Configure(ctx context.Context, req resource.ConfigureRequ
return
}
apiClient := postgresflexalphaUtils.ConfigureClient(ctx, &r.providerData, &resp.Diagnostics)
apiClient := postgresflexUtils.ConfigureClient(ctx, &r.providerData, &resp.Diagnostics)
if resp.Diagnostics.HasError() {
return
}
@ -538,8 +541,8 @@ func (r *userResource) ImportState(
}
func mapFieldsCreate(
userResp *postgresflexalpha.CreateUserResponse,
rolesArg *[]postgresflexalpha.UserRole,
userResp *postgresflex.CreateUserResponse,
rolesArg *[]postgresflex.UserRole,
model *Model,
region string,
) error {
@ -587,7 +590,7 @@ func mapFieldsCreate(
return nil
}
func mapFields(userResp *postgresflexalpha.GetUserResponse, model *Model, region string) error {
func mapFields(userResp *postgresflex.GetUserResponse, model *Model, region string) error {
if userResp == nil {
return fmt.Errorf("response is nil")
}
@ -631,7 +634,7 @@ func mapFields(userResp *postgresflexalpha.GetUserResponse, model *Model, region
return nil
}
func toCreatePayload(model *Model, roles *[]string) (*postgresflexalpha.CreateUserRequestPayload, error) {
func toCreatePayload(model *Model, roles *[]string) (*postgresflex.CreateUserRequestPayload, error) {
if model == nil {
return nil, fmt.Errorf("nil model")
}
@ -639,22 +642,22 @@ func toCreatePayload(model *Model, roles *[]string) (*postgresflexalpha.CreateUs
return nil, fmt.Errorf("nil roles")
}
return &postgresflexalpha.CreateUserRequestPayload{
return &postgresflex.CreateUserRequestPayload{
Roles: toPayloadRoles(roles),
Name: conversion.StringValueToPointer(model.Username),
}, nil
}
func toPayloadRoles(roles *[]string) *[]postgresflexalpha.UserRole {
var userRoles = make([]postgresflexalpha.UserRole, 0, len(*roles))
func toPayloadRoles(roles *[]string) *[]postgresflex.UserRole {
var userRoles = make([]postgresflex.UserRole, 0, len(*roles))
for _, role := range *roles {
userRoles = append(userRoles, postgresflexalpha.UserRole(role))
userRoles = append(userRoles, postgresflex.UserRole(role))
}
return &userRoles
}
func toUpdatePayload(model *Model, roles *[]string) (
*postgresflexalpha.UpdateUserRequestPayload,
*postgresflex.UpdateUserRequestPayload,
error,
) {
if model == nil {
@ -664,7 +667,7 @@ func toUpdatePayload(model *Model, roles *[]string) (
return nil, fmt.Errorf("nil roles")
}
return &postgresflexalpha.UpdateUserRequestPayload{
return &postgresflex.UpdateUserRequestPayload{
Roles: toPayloadRoles(roles),
}, nil
}

View file

@ -6,8 +6,8 @@ import (
"github.com/google/go-cmp/cmp"
"github.com/hashicorp/terraform-plugin-framework/attr"
"github.com/hashicorp/terraform-plugin-framework/types"
"github.com/mhenselin/terraform-provider-stackitprivatepreview/pkg/postgresflexalpha"
"github.com/stackitcloud/stackit-sdk-go/core/utils"
"github.com/stackitcloud/terraform-provider-stackit/pkg/postgresflexalpha"
)
func TestMapFieldsCreate(t *testing.T) {

View file

@ -71,7 +71,7 @@ func (r *instanceDataSource) Schema(_ context.Context, _ datasource.SchemaReques
"backup_schedule": `The backup schedule. Should follow the cron scheduling system format (e.g. "0 0 * * *").`,
"options": "Custom parameters for the SQLServer Flex instance.",
"region": "The resource region. If not defined, the provider region is used.",
// TODO
// TODO @mhenselin
}
resp.Schema = schema.Schema{

View file

@ -216,7 +216,7 @@ func toCreatePayload(model *Model, storage *storageModel, encryption *encryption
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)
diags := network.ACL.ElementsAs(context.TODO(), &aclElements, false)
if diags.HasError() {
return nil, fmt.Errorf("creating network: %w", core.DiagsToError(diags))
}
@ -259,7 +259,7 @@ func toUpdatePayload(model *Model, storage *storageModel, network *networkModel)
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)
diags := network.ACL.ElementsAs(context.TODO(), &aclElements, false)
if diags.HasError() {
return nil, fmt.Errorf("creating network: %w", core.DiagsToError(diags))
}
@ -349,7 +349,7 @@ func loadFlavorId(ctx context.Context, client sqlserverflexClient, model *Model,
if f.Id == nil || f.Cpu == nil || f.Memory == nil {
continue
}
if strings.ToLower(*f.NodeType) != strings.ToLower(*nodeType) {
if !strings.EqualFold(*f.NodeType, *nodeType) {
continue
}
if *f.Cpu == *cpu && *f.Memory == *ram {

View file

@ -629,7 +629,6 @@ func (r *instanceResource) Create(ctx context.Context, req resource.CreateReques
if flavor.RAM.IsNull() || flavor.RAM.IsUnknown() {
core.LogAndAddError(ctx, &resp.Diagnostics, "Error creating instance", "Instance creation waiting: flavor ram is null or unknown")
}
// flavorData := getFlavorModelById(ctx, r.client, &model, flavor)
// Map response body to schema
err = mapFields(ctx, waitResp, &model, flavor, storage, encryption, network, region)

View file

@ -13,7 +13,7 @@ import (
"github.com/hashicorp/terraform-plugin-testing/config"
"github.com/hashicorp/terraform-plugin-testing/echoprovider"
"github.com/stackitcloud/terraform-provider-stackit/stackit"
"github.com/mhenselin/terraform-provider-stackitprivatepreview/stackit"
)
const (