fix: adjust to new generator and sdk use
Some checks failed
CI Workflow / Check GoReleaser config (pull_request) Successful in 5s
CI Workflow / Test readiness for publishing provider (pull_request) Failing after 3m33s
CI Workflow / CI run tests (pull_request) Failing after 4m51s
CI Workflow / CI run build and linting (pull_request) Failing after 4m37s
CI Workflow / Code coverage report (pull_request) Has been skipped
Some checks failed
CI Workflow / Check GoReleaser config (pull_request) Successful in 5s
CI Workflow / Test readiness for publishing provider (pull_request) Failing after 3m33s
CI Workflow / CI run tests (pull_request) Failing after 4m51s
CI Workflow / CI run build and linting (pull_request) Failing after 4m37s
CI Workflow / Code coverage report (pull_request) Has been skipped
This commit is contained in:
parent
ca0f646526
commit
826bb5b36a
36 changed files with 2089 additions and 1166 deletions
|
|
@ -16,7 +16,7 @@ import (
|
|||
"tf-provider.git.onstackit.cloud/stackit-dev-tools/terraform-provider-stackitprivatepreview/stackit/internal/core"
|
||||
"tf-provider.git.onstackit.cloud/stackit-dev-tools/terraform-provider-stackitprivatepreview/stackit/internal/utils"
|
||||
|
||||
sqlserverflexalphaPkg "tf-provider.git.onstackit.cloud/stackit-dev-tools/terraform-provider-stackitprivatepreview/pkg_gen/sqlserverflexalpha"
|
||||
sqlserverflexalphaPkg "github.com/stackitcloud/stackit-sdk-go/services/sqlserverflex/v3alpha1api"
|
||||
sqlserverflexalphaGen "tf-provider.git.onstackit.cloud/stackit-dev-tools/terraform-provider-stackitprivatepreview/stackit/internal/services/sqlserverflexalpha/database/datasources_gen"
|
||||
)
|
||||
|
||||
|
|
@ -119,7 +119,7 @@ func (d *databaseDataSource) Read(ctx context.Context, req datasource.ReadReques
|
|||
|
||||
databaseName := data.DatabaseName.ValueString()
|
||||
|
||||
databaseResp, err := d.client.GetDatabaseRequest(ctx, projectId, region, instanceId, databaseName).Execute()
|
||||
databaseResp, err := d.client.DefaultAPI.GetDatabaseRequest(ctx, projectId, region, instanceId, databaseName).Execute()
|
||||
if err != nil {
|
||||
handleReadError(ctx, &resp.Diagnostics, err, projectId, instanceId)
|
||||
resp.State.RemoveResource(ctx)
|
||||
|
|
|
|||
|
|
@ -5,8 +5,9 @@ import (
|
|||
"strings"
|
||||
|
||||
"github.com/hashicorp/terraform-plugin-framework/types"
|
||||
coreUtils "github.com/stackitcloud/stackit-sdk-go/core/utils"
|
||||
|
||||
"tf-provider.git.onstackit.cloud/stackit-dev-tools/terraform-provider-stackitprivatepreview/pkg_gen/sqlserverflexalpha"
|
||||
sqlserverflexalpha "github.com/stackitcloud/stackit-sdk-go/services/sqlserverflex/v3alpha1api"
|
||||
"tf-provider.git.onstackit.cloud/stackit-dev-tools/terraform-provider-stackitprivatepreview/stackit/internal/utils"
|
||||
)
|
||||
|
||||
|
|
@ -15,7 +16,7 @@ func mapFields(source *sqlserverflexalpha.GetDatabaseResponse, model *dataSource
|
|||
if source == nil {
|
||||
return fmt.Errorf("response is nil")
|
||||
}
|
||||
if source.Id == nil || *source.Id == 0 {
|
||||
if source.Id == 0 {
|
||||
return fmt.Errorf("id not present")
|
||||
}
|
||||
if model == nil {
|
||||
|
|
@ -25,8 +26,8 @@ func mapFields(source *sqlserverflexalpha.GetDatabaseResponse, model *dataSource
|
|||
var databaseId int64
|
||||
if model.Id.ValueInt64() != 0 {
|
||||
databaseId = model.Id.ValueInt64()
|
||||
} else if source.Id != nil {
|
||||
databaseId = *source.Id
|
||||
} else if source.Id != 0 {
|
||||
databaseId = source.Id
|
||||
} else {
|
||||
return fmt.Errorf("database id not present")
|
||||
}
|
||||
|
|
@ -38,7 +39,7 @@ func mapFields(source *sqlserverflexalpha.GetDatabaseResponse, model *dataSource
|
|||
model.Region = types.StringValue(region)
|
||||
model.ProjectId = types.StringValue(model.ProjectId.ValueString())
|
||||
model.InstanceId = types.StringValue(model.InstanceId.ValueString())
|
||||
model.CompatibilityLevel = types.Int64Value(source.GetCompatibilityLevel())
|
||||
model.CompatibilityLevel = types.Int64Value(int64(source.GetCompatibilityLevel()))
|
||||
model.CollationName = types.StringValue(source.GetCollationName())
|
||||
|
||||
model.TerraformId = utils.BuildInternalTerraformId(
|
||||
|
|
@ -56,7 +57,7 @@ func mapResourceFields(source *sqlserverflexalpha.GetDatabaseResponse, model *re
|
|||
if source == nil {
|
||||
return fmt.Errorf("response is nil")
|
||||
}
|
||||
if source.Id == nil || *source.Id == 0 {
|
||||
if source.Id == 0 {
|
||||
return fmt.Errorf("id not present")
|
||||
}
|
||||
if model == nil {
|
||||
|
|
@ -66,8 +67,8 @@ func mapResourceFields(source *sqlserverflexalpha.GetDatabaseResponse, model *re
|
|||
var databaseId int64
|
||||
if model.Id.ValueInt64() != 0 {
|
||||
databaseId = model.Id.ValueInt64()
|
||||
} else if source.Id != nil {
|
||||
databaseId = *source.Id
|
||||
} else if source.Id != 0 {
|
||||
databaseId = source.Id
|
||||
} else {
|
||||
return fmt.Errorf("database id not present")
|
||||
}
|
||||
|
|
@ -80,8 +81,8 @@ func mapResourceFields(source *sqlserverflexalpha.GetDatabaseResponse, model *re
|
|||
model.ProjectId = types.StringValue(model.ProjectId.ValueString())
|
||||
model.InstanceId = types.StringValue(model.InstanceId.ValueString())
|
||||
|
||||
model.Compatibility = types.Int64Value(source.GetCompatibilityLevel())
|
||||
model.CompatibilityLevel = types.Int64Value(source.GetCompatibilityLevel())
|
||||
model.Compatibility = types.Int64Value(int64(source.GetCompatibilityLevel()))
|
||||
model.CompatibilityLevel = types.Int64Value(int64(source.GetCompatibilityLevel()))
|
||||
|
||||
model.Collation = types.StringValue(source.GetCollationName()) // it does not come back from api
|
||||
model.CollationName = types.StringValue(source.GetCollationName())
|
||||
|
|
@ -96,9 +97,9 @@ func toCreatePayload(model *resourceModel) (*sqlserverflexalpha.CreateDatabaseRe
|
|||
}
|
||||
|
||||
return &sqlserverflexalpha.CreateDatabaseRequestPayload{
|
||||
Name: model.Name.ValueStringPointer(),
|
||||
Owner: model.Owner.ValueStringPointer(),
|
||||
Name: model.Name.ValueString(),
|
||||
Owner: model.Owner.ValueString(),
|
||||
Collation: model.Collation.ValueStringPointer(),
|
||||
Compatibility: model.Compatibility.ValueInt64Pointer(),
|
||||
Compatibility: coreUtils.Ptr(int32(model.Compatibility.ValueInt64())),
|
||||
}, nil
|
||||
}
|
||||
|
|
|
|||
|
|
@ -5,9 +5,7 @@ import (
|
|||
|
||||
"github.com/google/go-cmp/cmp"
|
||||
"github.com/hashicorp/terraform-plugin-framework/types"
|
||||
"github.com/stackitcloud/stackit-sdk-go/core/utils"
|
||||
|
||||
"tf-provider.git.onstackit.cloud/stackit-dev-tools/terraform-provider-stackitprivatepreview/pkg_gen/sqlserverflexalpha"
|
||||
sqlserverflexalpha "github.com/stackitcloud/stackit-sdk-go/services/sqlserverflex/v3alpha1api"
|
||||
datasource "tf-provider.git.onstackit.cloud/stackit-dev-tools/terraform-provider-stackitprivatepreview/stackit/internal/services/sqlserverflexalpha/database/datasources_gen"
|
||||
)
|
||||
|
||||
|
|
@ -31,11 +29,11 @@ func TestMapFields(t *testing.T) {
|
|||
name: "should map fields correctly",
|
||||
given: given{
|
||||
source: &sqlserverflexalpha.GetDatabaseResponse{
|
||||
Id: utils.Ptr(int64(1)),
|
||||
Name: utils.Ptr("my-db"),
|
||||
CollationName: utils.Ptr("collation"),
|
||||
CompatibilityLevel: utils.Ptr(int64(150)),
|
||||
Owner: utils.Ptr("my-owner"),
|
||||
Id: (int64(1)),
|
||||
Name: ("my-db"),
|
||||
CollationName: ("collation"),
|
||||
CompatibilityLevel: (int32(150)),
|
||||
Owner: ("my-owner"),
|
||||
},
|
||||
model: &dataSourceModel{
|
||||
DatabaseModel: datasource.DatabaseModel{
|
||||
|
|
@ -73,7 +71,7 @@ func TestMapFields(t *testing.T) {
|
|||
{
|
||||
name: "should fail on nil source ID",
|
||||
given: given{
|
||||
source: &sqlserverflexalpha.GetDatabaseResponse{Id: nil},
|
||||
source: &sqlserverflexalpha.GetDatabaseResponse{Id: 0},
|
||||
model: &dataSourceModel{},
|
||||
},
|
||||
expected: expected{err: true},
|
||||
|
|
@ -81,7 +79,7 @@ func TestMapFields(t *testing.T) {
|
|||
{
|
||||
name: "should fail on nil model",
|
||||
given: given{
|
||||
source: &sqlserverflexalpha.GetDatabaseResponse{Id: utils.Ptr(int64(1))},
|
||||
source: &sqlserverflexalpha.GetDatabaseResponse{Id: (int64(1))},
|
||||
model: nil,
|
||||
},
|
||||
expected: expected{err: true},
|
||||
|
|
@ -125,9 +123,9 @@ func TestMapResourceFields(t *testing.T) {
|
|||
name: "should map fields correctly",
|
||||
given: given{
|
||||
source: &sqlserverflexalpha.GetDatabaseResponse{
|
||||
Id: utils.Ptr(int64(1)),
|
||||
Name: utils.Ptr("my-db"),
|
||||
Owner: utils.Ptr("my-owner"),
|
||||
Id: (int64(1)),
|
||||
Name: ("my-db"),
|
||||
Owner: ("my-owner"),
|
||||
},
|
||||
model: &resourceModel{
|
||||
ProjectId: types.StringValue("my-project"),
|
||||
|
|
@ -202,8 +200,8 @@ func TestToCreatePayload(t *testing.T) {
|
|||
},
|
||||
expected: expected{
|
||||
payload: &sqlserverflexalpha.CreateDatabaseRequestPayload{
|
||||
Name: utils.Ptr("my-db"),
|
||||
Owner: utils.Ptr("my-owner"),
|
||||
Name: ("my-db"),
|
||||
Owner: ("my-owner"),
|
||||
},
|
||||
},
|
||||
},
|
||||
|
|
|
|||
|
|
@ -16,8 +16,9 @@ import (
|
|||
"github.com/hashicorp/terraform-plugin-log/tflog"
|
||||
"github.com/stackitcloud/stackit-sdk-go/core/config"
|
||||
"github.com/stackitcloud/stackit-sdk-go/core/oapierror"
|
||||
coreUtils "github.com/stackitcloud/stackit-sdk-go/core/utils"
|
||||
|
||||
"tf-provider.git.onstackit.cloud/stackit-dev-tools/terraform-provider-stackitprivatepreview/pkg_gen/sqlserverflexalpha"
|
||||
sqlserverflexalpha "github.com/stackitcloud/stackit-sdk-go/services/sqlserverflex/v3alpha1api"
|
||||
"tf-provider.git.onstackit.cloud/stackit-dev-tools/terraform-provider-stackitprivatepreview/stackit/internal/conversion"
|
||||
wait "tf-provider.git.onstackit.cloud/stackit-dev-tools/terraform-provider-stackitprivatepreview/stackit/internal/wait/sqlserverflexalpha"
|
||||
|
||||
|
|
@ -176,13 +177,13 @@ func (r *databaseResource) Create(ctx context.Context, req resource.CreateReques
|
|||
}
|
||||
|
||||
if !data.Compatibility.IsNull() && !data.Compatibility.IsUnknown() {
|
||||
payLoad.Compatibility = data.Compatibility.ValueInt64Pointer()
|
||||
payLoad.Compatibility = coreUtils.Ptr(int32(data.Compatibility.ValueInt64()))
|
||||
}
|
||||
|
||||
payLoad.Name = data.Name.ValueStringPointer()
|
||||
payLoad.Owner = data.Owner.ValueStringPointer()
|
||||
payLoad.Name = data.Name.ValueString()
|
||||
payLoad.Owner = data.Owner.ValueString()
|
||||
|
||||
createResp, err := r.client.CreateDatabaseRequest(ctx, projectId, region, instanceId).
|
||||
createResp, err := r.client.DefaultAPI.CreateDatabaseRequest(ctx, projectId, region, instanceId).
|
||||
CreateDatabaseRequestPayload(payLoad).
|
||||
Execute()
|
||||
if err != nil {
|
||||
|
|
@ -195,7 +196,7 @@ func (r *databaseResource) Create(ctx context.Context, req resource.CreateReques
|
|||
return
|
||||
}
|
||||
|
||||
if createResp == nil || createResp.Id == nil {
|
||||
if createResp == nil || createResp.Id == 0 {
|
||||
core.LogAndAddError(
|
||||
ctx,
|
||||
&resp.Diagnostics,
|
||||
|
|
@ -205,7 +206,7 @@ func (r *databaseResource) Create(ctx context.Context, req resource.CreateReques
|
|||
return
|
||||
}
|
||||
|
||||
databaseId := *createResp.Id
|
||||
databaseId := createResp.Id
|
||||
|
||||
ctx = tflog.SetField(ctx, "database_id", databaseId)
|
||||
|
||||
|
|
@ -226,7 +227,7 @@ func (r *databaseResource) Create(ctx context.Context, req resource.CreateReques
|
|||
// TODO: is this necessary to wait for the database-> API say 200 ?
|
||||
waitResp, err := wait.CreateDatabaseWaitHandler(
|
||||
ctx,
|
||||
r.client,
|
||||
r.client.DefaultAPI,
|
||||
projectId,
|
||||
instanceId,
|
||||
region,
|
||||
|
|
@ -246,7 +247,7 @@ func (r *databaseResource) Create(ctx context.Context, req resource.CreateReques
|
|||
return
|
||||
}
|
||||
|
||||
if waitResp.Id == nil {
|
||||
if waitResp.Id == 0 {
|
||||
core.LogAndAddError(
|
||||
ctx,
|
||||
&resp.Diagnostics,
|
||||
|
|
@ -256,7 +257,7 @@ func (r *databaseResource) Create(ctx context.Context, req resource.CreateReques
|
|||
return
|
||||
}
|
||||
|
||||
if *waitResp.Id != databaseId {
|
||||
if waitResp.Id != databaseId {
|
||||
core.LogAndAddError(
|
||||
ctx,
|
||||
&resp.Diagnostics,
|
||||
|
|
@ -266,7 +267,7 @@ func (r *databaseResource) Create(ctx context.Context, req resource.CreateReques
|
|||
return
|
||||
}
|
||||
|
||||
if *waitResp.Owner != data.Owner.ValueString() {
|
||||
if waitResp.Owner != data.Owner.ValueString() {
|
||||
core.LogAndAddError(
|
||||
ctx,
|
||||
&resp.Diagnostics,
|
||||
|
|
@ -276,7 +277,7 @@ func (r *databaseResource) Create(ctx context.Context, req resource.CreateReques
|
|||
return
|
||||
}
|
||||
|
||||
if *waitResp.Name != data.Name.ValueString() {
|
||||
if waitResp.Name != data.Name.ValueString() {
|
||||
core.LogAndAddError(
|
||||
ctx,
|
||||
&resp.Diagnostics,
|
||||
|
|
@ -286,7 +287,7 @@ func (r *databaseResource) Create(ctx context.Context, req resource.CreateReques
|
|||
return
|
||||
}
|
||||
|
||||
database, err := r.client.GetDatabaseRequest(ctx, projectId, region, instanceId, databaseName).Execute()
|
||||
database, err := r.client.DefaultAPI.GetDatabaseRequest(ctx, projectId, region, instanceId, databaseName).Execute()
|
||||
if err != nil {
|
||||
core.LogAndAddError(
|
||||
ctx,
|
||||
|
|
@ -340,7 +341,7 @@ func (r *databaseResource) Read(ctx context.Context, req resource.ReadRequest, r
|
|||
ctx = tflog.SetField(ctx, "region", region)
|
||||
ctx = tflog.SetField(ctx, "database_name", databaseName)
|
||||
|
||||
databaseResp, err := r.client.GetDatabaseRequest(ctx, projectId, region, instanceId, databaseName).Execute()
|
||||
databaseResp, err := r.client.DefaultAPI.GetDatabaseRequest(ctx, projectId, region, instanceId, databaseName).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) || errors.Is(err, errDatabaseNotFound) {
|
||||
|
|
@ -420,7 +421,7 @@ func (r *databaseResource) Delete(ctx context.Context, req resource.DeleteReques
|
|||
ctx = tflog.SetField(ctx, "database_name", databaseName)
|
||||
|
||||
// Delete existing record set
|
||||
err := r.client.DeleteDatabaseRequestExecute(ctx, projectId, region, instanceId, databaseName)
|
||||
err := r.client.DefaultAPI.DeleteDatabaseRequest(ctx, projectId, region, instanceId, databaseName).Execute()
|
||||
if err != nil {
|
||||
core.LogAndAddError(
|
||||
ctx,
|
||||
|
|
|
|||
|
|
@ -16,7 +16,7 @@ import (
|
|||
"tf-provider.git.onstackit.cloud/stackit-dev-tools/terraform-provider-stackitprivatepreview/stackit/internal/core"
|
||||
"tf-provider.git.onstackit.cloud/stackit-dev-tools/terraform-provider-stackitprivatepreview/stackit/internal/utils"
|
||||
|
||||
sqlserverflexalphaPkg "tf-provider.git.onstackit.cloud/stackit-dev-tools/terraform-provider-stackitprivatepreview/pkg_gen/sqlserverflexalpha"
|
||||
sqlserverflexalphaPkg "github.com/stackitcloud/stackit-sdk-go/services/sqlserverflex/v3alpha1api"
|
||||
sqlserverflexalphaGen "tf-provider.git.onstackit.cloud/stackit-dev-tools/terraform-provider-stackitprivatepreview/stackit/internal/services/sqlserverflexalpha/flavor/datasources_gen"
|
||||
)
|
||||
|
||||
|
|
@ -273,7 +273,7 @@ func (r *flavorDataSource) Read(ctx context.Context, req datasource.ReadRequest,
|
|||
ctx = tflog.SetField(ctx, "project_id", projectId)
|
||||
ctx = tflog.SetField(ctx, "region", region)
|
||||
|
||||
flavors, err := getAllFlavors(ctx, r.client, projectId, region)
|
||||
flavors, err := getAllFlavors(ctx, r.client.DefaultAPI, projectId, region)
|
||||
if err != nil {
|
||||
core.LogAndAddError(ctx, &resp.Diagnostics, "Error reading flavors", fmt.Sprintf("getAllFlavors: %v", err))
|
||||
return
|
||||
|
|
@ -281,17 +281,17 @@ func (r *flavorDataSource) Read(ctx context.Context, req datasource.ReadRequest,
|
|||
|
||||
var foundFlavors []sqlserverflexalphaPkg.ListFlavors
|
||||
for _, flavor := range flavors {
|
||||
if model.Cpu.ValueInt64() != *flavor.Cpu {
|
||||
if model.Cpu.ValueInt64() != flavor.Cpu {
|
||||
continue
|
||||
}
|
||||
if model.Memory.ValueInt64() != *flavor.Memory {
|
||||
if model.Memory.ValueInt64() != flavor.Memory {
|
||||
continue
|
||||
}
|
||||
if model.NodeType.ValueString() != *flavor.NodeType {
|
||||
if model.NodeType.ValueString() != flavor.NodeType {
|
||||
continue
|
||||
}
|
||||
for _, sc := range *flavor.StorageClasses {
|
||||
if model.StorageClass.ValueString() != *sc.Class {
|
||||
for _, sc := range flavor.StorageClasses {
|
||||
if model.StorageClass.ValueString() != sc.Class {
|
||||
continue
|
||||
}
|
||||
foundFlavors = append(foundFlavors, flavor)
|
||||
|
|
@ -307,11 +307,11 @@ func (r *flavorDataSource) Read(ctx context.Context, req datasource.ReadRequest,
|
|||
}
|
||||
|
||||
f := foundFlavors[0]
|
||||
model.Description = types.StringValue(*f.Description)
|
||||
model.Id = utils.BuildInternalTerraformId(model.ProjectId.ValueString(), region, *f.Id)
|
||||
model.FlavorId = types.StringValue(*f.Id)
|
||||
model.MaxGb = types.Int64Value(*f.MaxGB)
|
||||
model.MinGb = types.Int64Value(*f.MinGB)
|
||||
model.Description = types.StringValue(f.Description)
|
||||
model.Id = utils.BuildInternalTerraformId(model.ProjectId.ValueString(), region, f.Id)
|
||||
model.FlavorId = types.StringValue(f.Id)
|
||||
model.MaxGb = types.Int64Value(int64(f.MaxGB))
|
||||
model.MinGb = types.Int64Value(int64(f.MinGB))
|
||||
|
||||
if f.StorageClasses == nil {
|
||||
model.StorageClasses = types.ListNull(sqlserverflexalphaGen.StorageClassesType{
|
||||
|
|
@ -321,15 +321,15 @@ func (r *flavorDataSource) Read(ctx context.Context, req datasource.ReadRequest,
|
|||
})
|
||||
} else {
|
||||
var scList []attr.Value
|
||||
for _, sc := range *f.StorageClasses {
|
||||
for _, sc := range f.StorageClasses {
|
||||
scList = append(
|
||||
scList,
|
||||
sqlserverflexalphaGen.NewStorageClassesValueMust(
|
||||
sqlserverflexalphaGen.StorageClassesValue{}.AttributeTypes(ctx),
|
||||
map[string]attr.Value{
|
||||
"class": types.StringValue(*sc.Class),
|
||||
"max_io_per_sec": types.Int64Value(*sc.MaxIoPerSec),
|
||||
"max_through_in_mb": types.Int64Value(*sc.MaxThroughInMb),
|
||||
"class": types.StringValue(sc.Class),
|
||||
"max_io_per_sec": types.Int64Value(int64(sc.MaxIoPerSec)),
|
||||
"max_through_in_mb": types.Int64Value(int64(sc.MaxThroughInMb)),
|
||||
},
|
||||
),
|
||||
)
|
||||
|
|
|
|||
|
|
@ -4,7 +4,7 @@ import (
|
|||
"context"
|
||||
"fmt"
|
||||
|
||||
"tf-provider.git.onstackit.cloud/stackit-dev-tools/terraform-provider-stackitprivatepreview/pkg_gen/sqlserverflexalpha"
|
||||
sqlserverflexalpha "github.com/stackitcloud/stackit-sdk-go/services/sqlserverflex/v3alpha1api"
|
||||
)
|
||||
|
||||
type flavorsClientReader interface {
|
||||
|
|
@ -50,11 +50,11 @@ func getFlavorsByFilter(
|
|||
}
|
||||
|
||||
// If the API returns no flavors, we have reached the end of the list.
|
||||
if res.Flavors == nil || len(*res.Flavors) == 0 {
|
||||
if res.Flavors == nil || len(res.Flavors) == 0 {
|
||||
break
|
||||
}
|
||||
|
||||
for _, flavor := range *res.Flavors {
|
||||
for _, flavor := range res.Flavors {
|
||||
if filter(flavor) {
|
||||
result = append(result, flavor)
|
||||
}
|
||||
|
|
|
|||
|
|
@ -4,81 +4,58 @@ import (
|
|||
"context"
|
||||
"testing"
|
||||
|
||||
"github.com/stackitcloud/stackit-sdk-go/core/utils"
|
||||
|
||||
"tf-provider.git.onstackit.cloud/stackit-dev-tools/terraform-provider-stackitprivatepreview/pkg_gen/sqlserverflexalpha"
|
||||
"github.com/stackitcloud/stackit-sdk-go/services/sqlserverflex/v3alpha1api"
|
||||
)
|
||||
|
||||
type mockRequest struct {
|
||||
executeFunc func() (*sqlserverflexalpha.GetFlavorsResponse, error)
|
||||
}
|
||||
|
||||
func (m *mockRequest) Page(_ int64) sqlserverflexalpha.ApiGetFlavorsRequestRequest { return m }
|
||||
func (m *mockRequest) Size(_ int64) sqlserverflexalpha.ApiGetFlavorsRequestRequest { return m }
|
||||
func (m *mockRequest) Sort(_ sqlserverflexalpha.FlavorSort) sqlserverflexalpha.ApiGetFlavorsRequestRequest {
|
||||
return m
|
||||
}
|
||||
func (m *mockRequest) Execute() (*sqlserverflexalpha.GetFlavorsResponse, error) {
|
||||
return m.executeFunc()
|
||||
}
|
||||
|
||||
type mockFlavorsClient struct {
|
||||
executeRequest func() sqlserverflexalpha.ApiGetFlavorsRequestRequest
|
||||
}
|
||||
|
||||
func (m *mockFlavorsClient) GetFlavorsRequest(_ context.Context, _, _ string) sqlserverflexalpha.ApiGetFlavorsRequestRequest {
|
||||
return m.executeRequest()
|
||||
}
|
||||
|
||||
var mockResp = func(page int64) (*sqlserverflexalpha.GetFlavorsResponse, error) {
|
||||
var mockResp = func(page int64) (*v3alpha1api.GetFlavorsResponse, error) {
|
||||
if page == 1 {
|
||||
return &sqlserverflexalpha.GetFlavorsResponse{
|
||||
Flavors: &[]sqlserverflexalpha.ListFlavors{
|
||||
{Id: utils.Ptr("flavor-1"), Description: utils.Ptr("first")},
|
||||
{Id: utils.Ptr("flavor-2"), Description: utils.Ptr("second")},
|
||||
return &v3alpha1api.GetFlavorsResponse{
|
||||
Flavors: []v3alpha1api.ListFlavors{
|
||||
{Id: "flavor-1", Description: "first"},
|
||||
{Id: "flavor-2", Description: "second"},
|
||||
},
|
||||
}, nil
|
||||
}
|
||||
if page == 2 {
|
||||
return &sqlserverflexalpha.GetFlavorsResponse{
|
||||
Flavors: &[]sqlserverflexalpha.ListFlavors{
|
||||
{Id: utils.Ptr("flavor-3"), Description: utils.Ptr("three")},
|
||||
return &v3alpha1api.GetFlavorsResponse{
|
||||
Flavors: []v3alpha1api.ListFlavors{
|
||||
{Id: "flavor-3", Description: "three"},
|
||||
},
|
||||
}, nil
|
||||
}
|
||||
|
||||
return &sqlserverflexalpha.GetFlavorsResponse{
|
||||
Flavors: &[]sqlserverflexalpha.ListFlavors{},
|
||||
return &v3alpha1api.GetFlavorsResponse{
|
||||
Flavors: []v3alpha1api.ListFlavors{},
|
||||
}, nil
|
||||
}
|
||||
|
||||
func TestGetFlavorsByFilter(t *testing.T) {
|
||||
tests := []struct {
|
||||
description string
|
||||
projectId string
|
||||
projectID string
|
||||
region string
|
||||
mockErr error
|
||||
filter func(sqlserverflexalpha.ListFlavors) bool
|
||||
filter func(v3alpha1api.ListFlavors) bool
|
||||
wantCount int
|
||||
wantErr bool
|
||||
}{
|
||||
{
|
||||
description: "Success - Get all flavors (2 pages)",
|
||||
projectId: "pid", region: "reg",
|
||||
filter: func(_ sqlserverflexalpha.ListFlavors) bool { return true },
|
||||
projectID: "pid", region: "reg",
|
||||
filter: func(_ v3alpha1api.ListFlavors) bool { return true },
|
||||
wantCount: 3,
|
||||
wantErr: false,
|
||||
},
|
||||
{
|
||||
description: "Success - Filter flavors by description",
|
||||
projectId: "pid", region: "reg",
|
||||
filter: func(f sqlserverflexalpha.ListFlavors) bool { return *f.Description == "first" },
|
||||
projectID: "pid", region: "reg",
|
||||
filter: func(f v3alpha1api.ListFlavors) bool { return f.Description == "first" },
|
||||
wantCount: 1,
|
||||
wantErr: false,
|
||||
},
|
||||
{
|
||||
description: "Error - Missing parameters",
|
||||
projectId: "", region: "reg",
|
||||
projectID: "", region: "reg",
|
||||
wantErr: true,
|
||||
},
|
||||
}
|
||||
|
|
@ -87,17 +64,15 @@ func TestGetFlavorsByFilter(t *testing.T) {
|
|||
t.Run(
|
||||
tt.description, func(t *testing.T) {
|
||||
var currentPage int64
|
||||
client := &mockFlavorsClient{
|
||||
executeRequest: func() sqlserverflexalpha.ApiGetFlavorsRequestRequest {
|
||||
return &mockRequest{
|
||||
executeFunc: func() (*sqlserverflexalpha.GetFlavorsResponse, error) {
|
||||
currentPage++
|
||||
return mockResp(currentPage)
|
||||
},
|
||||
}
|
||||
},
|
||||
getFlavorsMock := func(_ v3alpha1api.ApiGetFlavorsRequestRequest) (*v3alpha1api.GetFlavorsResponse, error) {
|
||||
currentPage++
|
||||
return mockResp(currentPage)
|
||||
}
|
||||
actual, err := getFlavorsByFilter(context.Background(), client, tt.projectId, tt.region, tt.filter)
|
||||
|
||||
client := v3alpha1api.DefaultAPIServiceMock{
|
||||
GetFlavorsRequestExecuteMock: &getFlavorsMock,
|
||||
}
|
||||
actual, err := getFlavorsByFilter(context.Background(), client, tt.projectID, tt.region, tt.filter)
|
||||
|
||||
if (err != nil) != tt.wantErr {
|
||||
t.Errorf("getFlavorsByFilter() error = %v, wantErr %v", err, tt.wantErr)
|
||||
|
|
@ -114,15 +89,14 @@ func TestGetFlavorsByFilter(t *testing.T) {
|
|||
|
||||
func TestGetAllFlavors(t *testing.T) {
|
||||
var currentPage int64
|
||||
client := &mockFlavorsClient{
|
||||
executeRequest: func() sqlserverflexalpha.ApiGetFlavorsRequestRequest {
|
||||
return &mockRequest{
|
||||
executeFunc: func() (*sqlserverflexalpha.GetFlavorsResponse, error) {
|
||||
currentPage++
|
||||
return mockResp(currentPage)
|
||||
},
|
||||
}
|
||||
},
|
||||
|
||||
getFlavorsMock := func(_ v3alpha1api.ApiGetFlavorsRequestRequest) (*v3alpha1api.GetFlavorsResponse, error) {
|
||||
currentPage++
|
||||
return mockResp(currentPage)
|
||||
}
|
||||
|
||||
client := v3alpha1api.DefaultAPIServiceMock{
|
||||
GetFlavorsRequestExecuteMock: &getFlavorsMock,
|
||||
}
|
||||
|
||||
res, err := getAllFlavors(context.Background(), client, "pid", "reg")
|
||||
|
|
|
|||
|
|
@ -15,7 +15,7 @@ import (
|
|||
"tf-provider.git.onstackit.cloud/stackit-dev-tools/terraform-provider-stackitprivatepreview/stackit/internal/core"
|
||||
"tf-provider.git.onstackit.cloud/stackit-dev-tools/terraform-provider-stackitprivatepreview/stackit/internal/utils"
|
||||
|
||||
sqlserverflexalphaPkg "tf-provider.git.onstackit.cloud/stackit-dev-tools/terraform-provider-stackitprivatepreview/pkg_gen/sqlserverflexalpha"
|
||||
sqlserverflexalphaPkg "github.com/stackitcloud/stackit-sdk-go/services/sqlserverflex/v3alpha1api"
|
||||
|
||||
sqlserverflexalphaGen "tf-provider.git.onstackit.cloud/stackit-dev-tools/terraform-provider-stackitprivatepreview/stackit/internal/services/sqlserverflexalpha/flavors/datasources_gen"
|
||||
)
|
||||
|
|
@ -121,7 +121,7 @@ func (d *flavorsDataSource) Read(ctx context.Context, req datasource.ReadRequest
|
|||
ctx = tflog.SetField(ctx, "flavors_id", flavorsId)
|
||||
|
||||
// TODO: refactor to correct implementation
|
||||
_, err := d.client.GetFlavorsRequest(ctx, projectId, region).Execute()
|
||||
_, err := d.client.DefaultAPI.GetFlavorsRequest(ctx, projectId, region).Execute()
|
||||
if err != nil {
|
||||
utils.LogError(
|
||||
ctx,
|
||||
|
|
|
|||
|
|
@ -14,7 +14,7 @@ import (
|
|||
"tf-provider.git.onstackit.cloud/stackit-dev-tools/terraform-provider-stackitprivatepreview/stackit/internal/core"
|
||||
"tf-provider.git.onstackit.cloud/stackit-dev-tools/terraform-provider-stackitprivatepreview/stackit/internal/utils"
|
||||
|
||||
sqlserverflexalphaPkg "tf-provider.git.onstackit.cloud/stackit-dev-tools/terraform-provider-stackitprivatepreview/pkg_gen/sqlserverflexalpha"
|
||||
"github.com/stackitcloud/stackit-sdk-go/services/sqlserverflex/v3alpha1api"
|
||||
|
||||
sqlserverflexalphaGen "tf-provider.git.onstackit.cloud/stackit-dev-tools/terraform-provider-stackitprivatepreview/stackit/internal/services/sqlserverflexalpha/instance/datasources_gen"
|
||||
)
|
||||
|
|
@ -34,7 +34,7 @@ type dataSourceModel struct {
|
|||
}
|
||||
|
||||
type instanceDataSource struct {
|
||||
client *sqlserverflexalphaPkg.APIClient
|
||||
client *v3alpha1api.APIClient
|
||||
providerData core.ProviderData
|
||||
}
|
||||
|
||||
|
|
@ -77,7 +77,7 @@ func (d *instanceDataSource) Configure(
|
|||
config.WithRegion(d.providerData.GetRegion()),
|
||||
)
|
||||
}
|
||||
apiClient, err := sqlserverflexalphaPkg.NewAPIClient(apiClientConfigOptions...)
|
||||
apiClient, err := v3alpha1api.NewAPIClient(apiClientConfigOptions...)
|
||||
if err != nil {
|
||||
resp.Diagnostics.AddError(
|
||||
"Error configuring API client",
|
||||
|
|
@ -112,7 +112,7 @@ func (d *instanceDataSource) Read(ctx context.Context, req datasource.ReadReques
|
|||
ctx = tflog.SetField(ctx, "region", region)
|
||||
ctx = tflog.SetField(ctx, "instance_id", instanceId)
|
||||
|
||||
instanceResp, err := d.client.GetInstanceRequest(ctx, projectId, region, instanceId).Execute()
|
||||
instanceResp, err := d.client.DefaultAPI.GetInstanceRequest(ctx, projectId, region, instanceId).Execute()
|
||||
if err != nil {
|
||||
utils.LogError(
|
||||
ctx,
|
||||
|
|
|
|||
|
|
@ -11,8 +11,8 @@ import (
|
|||
"github.com/hashicorp/terraform-plugin-framework/resource"
|
||||
"github.com/hashicorp/terraform-plugin-framework/types"
|
||||
|
||||
"tf-provider.git.onstackit.cloud/stackit-dev-tools/terraform-provider-stackitprivatepreview/pkg_gen/sqlserverflexalpha"
|
||||
"tf-provider.git.onstackit.cloud/stackit-dev-tools/terraform-provider-stackitprivatepreview/stackit/internal/conversion"
|
||||
sqlserverflexalpha "github.com/stackitcloud/stackit-sdk-go/services/sqlserverflex/v3alpha1api"
|
||||
|
||||
sqlserverflexalphaDataGen "tf-provider.git.onstackit.cloud/stackit-dev-tools/terraform-provider-stackitprivatepreview/stackit/internal/services/sqlserverflexalpha/instance/datasources_gen"
|
||||
sqlserverflexalphaResGen "tf-provider.git.onstackit.cloud/stackit-dev-tools/terraform-provider-stackitprivatepreview/stackit/internal/services/sqlserverflexalpha/instance/resources_gen"
|
||||
)
|
||||
|
|
@ -53,7 +53,7 @@ func mapResponseToModel(
|
|||
}
|
||||
m.Network = net
|
||||
m.Replicas = types.Int64Value(int64(resp.GetReplicas()))
|
||||
m.RetentionDays = types.Int64Value(resp.GetRetentionDays())
|
||||
m.RetentionDays = types.Int64Value(int64(resp.GetRetentionDays()))
|
||||
m.Status = types.StringValue(string(resp.GetStatus()))
|
||||
|
||||
stor, diags := sqlserverflexalphaResGen.NewStorageValue(
|
||||
|
|
@ -109,7 +109,7 @@ func mapDataResponseToModel(
|
|||
}
|
||||
m.Network = net
|
||||
m.Replicas = types.Int64Value(int64(resp.GetReplicas()))
|
||||
m.RetentionDays = types.Int64Value(resp.GetRetentionDays())
|
||||
m.RetentionDays = types.Int64Value(int64(resp.GetRetentionDays()))
|
||||
m.Status = types.StringValue(string(resp.GetStatus()))
|
||||
|
||||
stor, diags := sqlserverflexalphaDataGen.NewStorageValue(
|
||||
|
|
@ -135,10 +135,10 @@ func handleEncryption(
|
|||
) sqlserverflexalphaResGen.EncryptionValue {
|
||||
if !resp.HasEncryption() ||
|
||||
resp.Encryption == nil ||
|
||||
resp.Encryption.KekKeyId == nil ||
|
||||
resp.Encryption.KekKeyRingId == nil ||
|
||||
resp.Encryption.KekKeyVersion == nil ||
|
||||
resp.Encryption.ServiceAccount == nil {
|
||||
resp.Encryption.KekKeyId == "" ||
|
||||
resp.Encryption.KekKeyRingId == "" ||
|
||||
resp.Encryption.KekKeyVersion == "" ||
|
||||
resp.Encryption.ServiceAccount == "" {
|
||||
if m.Encryption.IsNull() || m.Encryption.IsUnknown() {
|
||||
return sqlserverflexalphaResGen.NewEncryptionValueNull()
|
||||
}
|
||||
|
|
@ -147,16 +147,16 @@ func handleEncryption(
|
|||
|
||||
enc := sqlserverflexalphaResGen.NewEncryptionValueNull()
|
||||
if kVal, ok := resp.Encryption.GetKekKeyIdOk(); ok {
|
||||
enc.KekKeyId = types.StringValue(kVal)
|
||||
enc.KekKeyId = types.StringValue(*kVal)
|
||||
}
|
||||
if kkVal, ok := resp.Encryption.GetKekKeyRingIdOk(); ok {
|
||||
enc.KekKeyRingId = types.StringValue(kkVal)
|
||||
enc.KekKeyRingId = types.StringValue(*kkVal)
|
||||
}
|
||||
if kkvVal, ok := resp.Encryption.GetKekKeyVersionOk(); ok {
|
||||
enc.KekKeyVersion = types.StringValue(kkvVal)
|
||||
enc.KekKeyVersion = types.StringValue(*kkvVal)
|
||||
}
|
||||
if sa, ok := resp.Encryption.GetServiceAccountOk(); ok {
|
||||
enc.ServiceAccount = types.StringValue(sa)
|
||||
enc.ServiceAccount = types.StringValue(*sa)
|
||||
}
|
||||
return enc
|
||||
}
|
||||
|
|
@ -167,10 +167,10 @@ func handleDSEncryption(
|
|||
) sqlserverflexalphaDataGen.EncryptionValue {
|
||||
if !resp.HasEncryption() ||
|
||||
resp.Encryption == nil ||
|
||||
resp.Encryption.KekKeyId == nil ||
|
||||
resp.Encryption.KekKeyRingId == nil ||
|
||||
resp.Encryption.KekKeyVersion == nil ||
|
||||
resp.Encryption.ServiceAccount == nil {
|
||||
resp.Encryption.KekKeyId == "" ||
|
||||
resp.Encryption.KekKeyRingId == "" ||
|
||||
resp.Encryption.KekKeyVersion == "" ||
|
||||
resp.Encryption.ServiceAccount == "" {
|
||||
if m.Encryption.IsNull() || m.Encryption.IsUnknown() {
|
||||
return sqlserverflexalphaDataGen.NewEncryptionValueNull()
|
||||
}
|
||||
|
|
@ -179,16 +179,16 @@ func handleDSEncryption(
|
|||
|
||||
enc := sqlserverflexalphaDataGen.NewEncryptionValueNull()
|
||||
if kVal, ok := resp.Encryption.GetKekKeyIdOk(); ok {
|
||||
enc.KekKeyId = types.StringValue(kVal)
|
||||
enc.KekKeyId = types.StringValue(*kVal)
|
||||
}
|
||||
if kkVal, ok := resp.Encryption.GetKekKeyRingIdOk(); ok {
|
||||
enc.KekKeyRingId = types.StringValue(kkVal)
|
||||
enc.KekKeyRingId = types.StringValue(*kkVal)
|
||||
}
|
||||
if kkvVal, ok := resp.Encryption.GetKekKeyVersionOk(); ok {
|
||||
enc.KekKeyVersion = types.StringValue(kkvVal)
|
||||
enc.KekKeyVersion = types.StringValue(*kkvVal)
|
||||
}
|
||||
if sa, ok := resp.Encryption.GetServiceAccountOk(); ok {
|
||||
enc.ServiceAccount = types.StringValue(sa)
|
||||
enc.ServiceAccount = types.StringValue(*sa)
|
||||
}
|
||||
return enc
|
||||
}
|
||||
|
|
@ -201,51 +201,47 @@ func toCreatePayload(
|
|||
return nil, fmt.Errorf("nil model")
|
||||
}
|
||||
|
||||
storagePayload := &sqlserverflexalpha.CreateInstanceRequestPayloadGetStorageArgType{}
|
||||
storagePayload := sqlserverflexalpha.StorageCreate{}
|
||||
if !model.Storage.IsNull() && !model.Storage.IsUnknown() {
|
||||
storagePayload.Class = model.Storage.Class.ValueStringPointer()
|
||||
storagePayload.Size = model.Storage.Size.ValueInt64Pointer()
|
||||
storagePayload.Class = model.Storage.Class.ValueString()
|
||||
storagePayload.Size = model.Storage.Size.ValueInt64()
|
||||
}
|
||||
|
||||
var encryptionPayload *sqlserverflexalpha.CreateInstanceRequestPayloadGetEncryptionArgType = nil
|
||||
var encryptionPayload *sqlserverflexalpha.InstanceEncryption = nil
|
||||
if !model.Encryption.IsNull() && !model.Encryption.IsUnknown() &&
|
||||
!model.Encryption.KekKeyId.IsNull() && model.Encryption.KekKeyId.IsUnknown() && model.Encryption.KekKeyId.ValueString() != "" &&
|
||||
!model.Encryption.KekKeyRingId.IsNull() && !model.Encryption.KekKeyRingId.IsUnknown() && model.Encryption.KekKeyRingId.ValueString() != "" &&
|
||||
!model.Encryption.KekKeyVersion.IsNull() && !model.Encryption.KekKeyVersion.IsUnknown() && model.Encryption.KekKeyVersion.ValueString() != "" &&
|
||||
!model.Encryption.ServiceAccount.IsNull() && !model.Encryption.ServiceAccount.IsUnknown() && model.Encryption.ServiceAccount.ValueString() != "" {
|
||||
encryptionPayload = &sqlserverflexalpha.CreateInstanceRequestPayloadGetEncryptionArgType{
|
||||
KekKeyId: model.Encryption.KekKeyId.ValueStringPointer(),
|
||||
KekKeyRingId: model.Encryption.KekKeyVersion.ValueStringPointer(),
|
||||
KekKeyVersion: model.Encryption.KekKeyRingId.ValueStringPointer(),
|
||||
ServiceAccount: model.Encryption.ServiceAccount.ValueStringPointer(),
|
||||
encryptionPayload = &sqlserverflexalpha.InstanceEncryption{
|
||||
KekKeyId: model.Encryption.KekKeyId.ValueString(),
|
||||
KekKeyRingId: model.Encryption.KekKeyVersion.ValueString(),
|
||||
KekKeyVersion: model.Encryption.KekKeyRingId.ValueString(),
|
||||
ServiceAccount: model.Encryption.ServiceAccount.ValueString(),
|
||||
}
|
||||
}
|
||||
|
||||
networkPayload := &sqlserverflexalpha.CreateInstanceRequestPayloadGetNetworkArgType{}
|
||||
networkPayload := sqlserverflexalpha.CreateInstanceRequestPayloadNetwork{}
|
||||
if !model.Network.IsNull() && !model.Network.IsUnknown() {
|
||||
networkPayload.AccessScope = sqlserverflexalpha.CreateInstanceRequestPayloadNetworkGetAccessScopeAttributeType(
|
||||
model.Network.AccessScope.ValueStringPointer(),
|
||||
)
|
||||
networkPayload.AccessScope = (*sqlserverflexalpha.InstanceNetworkAccessScope)(model.Network.AccessScope.ValueStringPointer())
|
||||
|
||||
var resList []string
|
||||
diags := model.Network.Acl.ElementsAs(ctx, &resList, false)
|
||||
if diags.HasError() {
|
||||
return nil, fmt.Errorf("error converting network acl list")
|
||||
}
|
||||
networkPayload.Acl = &resList
|
||||
networkPayload.Acl = resList
|
||||
}
|
||||
|
||||
return &sqlserverflexalpha.CreateInstanceRequestPayload{
|
||||
BackupSchedule: conversion.StringValueToPointer(model.BackupSchedule),
|
||||
BackupSchedule: model.BackupSchedule.ValueString(),
|
||||
Encryption: encryptionPayload,
|
||||
FlavorId: conversion.StringValueToPointer(model.FlavorId),
|
||||
Name: conversion.StringValueToPointer(model.Name),
|
||||
FlavorId: model.FlavorId.ValueString(),
|
||||
Name: model.Name.ValueString(),
|
||||
Network: networkPayload,
|
||||
RetentionDays: conversion.Int64ValueToPointer(model.RetentionDays),
|
||||
RetentionDays: int32(model.RetentionDays.ValueInt64()),
|
||||
Storage: storagePayload,
|
||||
Version: sqlserverflexalpha.CreateInstanceRequestPayloadGetVersionAttributeType(
|
||||
conversion.StringValueToPointer(model.Version),
|
||||
),
|
||||
Version: sqlserverflexalpha.InstanceVersion(model.Version.ValueString()),
|
||||
}, nil
|
||||
}
|
||||
|
||||
|
|
@ -269,15 +265,13 @@ func toUpdatePayload(
|
|||
return nil, fmt.Errorf("error converting model network acl value")
|
||||
}
|
||||
return &sqlserverflexalpha.UpdateInstanceRequestPayload{
|
||||
BackupSchedule: m.BackupSchedule.ValueStringPointer(),
|
||||
FlavorId: m.FlavorId.ValueStringPointer(),
|
||||
Name: m.Name.ValueStringPointer(),
|
||||
Network: sqlserverflexalpha.NewUpdateInstanceRequestPayloadNetwork(netAcl),
|
||||
Replicas: &replVal,
|
||||
RetentionDays: m.RetentionDays.ValueInt64Pointer(),
|
||||
Storage: &sqlserverflexalpha.StorageUpdate{Size: m.Storage.Size.ValueInt64Pointer()},
|
||||
Version: sqlserverflexalpha.UpdateInstanceRequestPayloadGetVersionAttributeType(
|
||||
m.Version.ValueStringPointer(),
|
||||
),
|
||||
BackupSchedule: m.BackupSchedule.ValueString(),
|
||||
FlavorId: m.FlavorId.ValueString(),
|
||||
Name: m.Name.ValueString(),
|
||||
Network: sqlserverflexalpha.UpdateInstanceRequestPayloadNetwork{Acl: netAcl},
|
||||
Replicas: replVal,
|
||||
RetentionDays: int32(m.RetentionDays.ValueInt64()),
|
||||
Storage: sqlserverflexalpha.StorageUpdate{Size: m.Storage.Size.ValueInt64Pointer()},
|
||||
Version: sqlserverflexalpha.InstanceVersion(m.Version.ValueString()),
|
||||
}, nil
|
||||
}
|
||||
|
|
|
|||
|
|
@ -19,7 +19,7 @@ import (
|
|||
"tf-provider.git.onstackit.cloud/stackit-dev-tools/terraform-provider-stackitprivatepreview/stackit/internal/conversion"
|
||||
wait "tf-provider.git.onstackit.cloud/stackit-dev-tools/terraform-provider-stackitprivatepreview/stackit/internal/wait/sqlserverflexalpha"
|
||||
|
||||
"tf-provider.git.onstackit.cloud/stackit-dev-tools/terraform-provider-stackitprivatepreview/pkg_gen/sqlserverflexalpha"
|
||||
sqlserverflexalpha "github.com/stackitcloud/stackit-sdk-go/services/sqlserverflex/v3alpha1api"
|
||||
|
||||
"tf-provider.git.onstackit.cloud/stackit-dev-tools/terraform-provider-stackitprivatepreview/stackit/internal/core"
|
||||
"tf-provider.git.onstackit.cloud/stackit-dev-tools/terraform-provider-stackitprivatepreview/stackit/internal/utils"
|
||||
|
|
@ -207,7 +207,7 @@ func (r *instanceResource) Create(ctx context.Context, req resource.CreateReques
|
|||
return
|
||||
}
|
||||
// Create new Instance
|
||||
createResp, err := r.client.CreateInstanceRequest(
|
||||
createResp, err := r.client.DefaultAPI.CreateInstanceRequest(
|
||||
ctx,
|
||||
projectId,
|
||||
region,
|
||||
|
|
@ -219,7 +219,7 @@ func (r *instanceResource) Create(ctx context.Context, req resource.CreateReques
|
|||
|
||||
ctx = core.LogResponse(ctx)
|
||||
|
||||
InstanceId := *createResp.Id
|
||||
instanceId := createResp.Id
|
||||
|
||||
// Example data value setting
|
||||
data.InstanceId = types.StringValue("id-from-response")
|
||||
|
|
@ -227,7 +227,7 @@ func (r *instanceResource) Create(ctx context.Context, req resource.CreateReques
|
|||
identity := InstanceResourceIdentityModel{
|
||||
ProjectID: types.StringValue(projectId),
|
||||
Region: types.StringValue(region),
|
||||
InstanceID: types.StringValue(InstanceId),
|
||||
InstanceID: types.StringValue(instanceId),
|
||||
}
|
||||
resp.Diagnostics.Append(resp.Identity.Set(ctx, identity)...)
|
||||
if resp.Diagnostics.HasError() {
|
||||
|
|
@ -236,9 +236,9 @@ func (r *instanceResource) Create(ctx context.Context, req resource.CreateReques
|
|||
|
||||
waitResp, err := wait.CreateInstanceWaitHandler(
|
||||
ctx,
|
||||
r.client,
|
||||
r.client.DefaultAPI,
|
||||
projectId,
|
||||
InstanceId,
|
||||
instanceId,
|
||||
region,
|
||||
).SetSleepBeforeWait(
|
||||
10 * time.Second,
|
||||
|
|
@ -255,7 +255,7 @@ func (r *instanceResource) Create(ctx context.Context, req resource.CreateReques
|
|||
return
|
||||
}
|
||||
|
||||
if waitResp.Id == nil {
|
||||
if waitResp.Id == "" {
|
||||
core.LogAndAddError(
|
||||
ctx,
|
||||
&resp.Diagnostics,
|
||||
|
|
@ -309,7 +309,7 @@ func (r *instanceResource) Read(ctx context.Context, req resource.ReadRequest, r
|
|||
instanceId := data.InstanceId.ValueString()
|
||||
ctx = tflog.SetField(ctx, "instance_id", instanceId)
|
||||
|
||||
instanceResp, err := r.client.GetInstanceRequest(ctx, projectId, region, instanceId).Execute()
|
||||
instanceResp, err := r.client.DefaultAPI.GetInstanceRequest(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 {
|
||||
|
|
@ -385,7 +385,7 @@ func (r *instanceResource) Update(ctx context.Context, req resource.UpdateReques
|
|||
return
|
||||
}
|
||||
// Update existing instance
|
||||
err = r.client.UpdateInstanceRequest(
|
||||
err = r.client.DefaultAPI.UpdateInstanceRequest(
|
||||
ctx,
|
||||
projectId,
|
||||
region,
|
||||
|
|
@ -399,7 +399,7 @@ func (r *instanceResource) Update(ctx context.Context, req resource.UpdateReques
|
|||
ctx = core.LogResponse(ctx)
|
||||
|
||||
waitResp, err := wait.
|
||||
UpdateInstanceWaitHandler(ctx, r.client, projectId, instanceId, region).
|
||||
UpdateInstanceWaitHandler(ctx, r.client.DefaultAPI, projectId, instanceId, region).
|
||||
SetSleepBeforeWait(15 * time.Second).
|
||||
SetTimeout(45 * time.Minute).
|
||||
WaitWithContext(ctx)
|
||||
|
|
@ -471,7 +471,7 @@ func (r *instanceResource) Delete(ctx context.Context, req resource.DeleteReques
|
|||
ctx = tflog.SetField(ctx, "instance_id", instanceId)
|
||||
|
||||
// Delete existing instance
|
||||
err := r.client.DeleteInstanceRequest(ctx, projectId, region, instanceId).Execute()
|
||||
err := r.client.DefaultAPI.DeleteInstanceRequest(ctx, projectId, region, instanceId).Execute()
|
||||
if err != nil {
|
||||
core.LogAndAddError(ctx, &resp.Diagnostics, "Error deleting instance", fmt.Sprintf("Calling API: %v", err))
|
||||
return
|
||||
|
|
@ -479,7 +479,7 @@ func (r *instanceResource) Delete(ctx context.Context, req resource.DeleteReques
|
|||
|
||||
ctx = core.LogResponse(ctx)
|
||||
|
||||
delResp, err := wait.DeleteInstanceWaitHandler(ctx, r.client, projectId, instanceId, region).WaitWithContext(ctx)
|
||||
delResp, err := wait.DeleteInstanceWaitHandler(ctx, r.client.DefaultAPI, projectId, instanceId, region).WaitWithContext(ctx)
|
||||
if err != nil {
|
||||
core.LogAndAddError(
|
||||
ctx,
|
||||
|
|
|
|||
|
|
@ -4,18 +4,13 @@ import (
|
|||
"context"
|
||||
_ "embed"
|
||||
"fmt"
|
||||
"log"
|
||||
"os"
|
||||
"strconv"
|
||||
"strings"
|
||||
"testing"
|
||||
|
||||
"github.com/hashicorp/terraform-plugin-testing/helper/acctest"
|
||||
"github.com/hashicorp/terraform-plugin-testing/helper/resource"
|
||||
"github.com/stackitcloud/stackit-sdk-go/core/config"
|
||||
|
||||
"tf-provider.git.onstackit.cloud/stackit-dev-tools/terraform-provider-stackitprivatepreview/internal/testutils"
|
||||
sqlserverflexalphaPkgGen "tf-provider.git.onstackit.cloud/stackit-dev-tools/terraform-provider-stackitprivatepreview/pkg_gen/sqlserverflexalpha"
|
||||
sqlserverflexalpha "tf-provider.git.onstackit.cloud/stackit-dev-tools/terraform-provider-stackitprivatepreview/stackit/internal/services/sqlserverflexalpha/instance"
|
||||
|
||||
// The fwresource import alias is so there is no collision
|
||||
|
|
@ -28,44 +23,6 @@ const providerPrefix = "stackitprivatepreview_sqlserverflexalpha"
|
|||
|
||||
var testInstances []string
|
||||
|
||||
func init() {
|
||||
sweeperName := fmt.Sprintf("%s_%s", providerPrefix, "sweeper")
|
||||
|
||||
resource.AddTestSweepers(sweeperName, &resource.Sweeper{
|
||||
Name: sweeperName,
|
||||
F: func(region string) error {
|
||||
ctx := context.Background()
|
||||
apiClientConfigOptions := []config.ConfigurationOption{}
|
||||
apiClient, err := sqlserverflexalphaPkgGen.NewAPIClient(apiClientConfigOptions...)
|
||||
if err != nil {
|
||||
log.Fatalln(err)
|
||||
}
|
||||
|
||||
instances, err := apiClient.ListInstancesRequest(ctx, testutils.ProjectId, region).
|
||||
Size(100).
|
||||
Execute()
|
||||
if err != nil {
|
||||
log.Fatalln(err)
|
||||
}
|
||||
|
||||
for _, inst := range instances.GetInstances() {
|
||||
if strings.HasPrefix(inst.GetName(), "tf-acc-") {
|
||||
for _, item := range testInstances {
|
||||
if inst.GetName() == item {
|
||||
delErr := apiClient.DeleteInstanceRequestExecute(ctx, testutils.ProjectId, region, inst.GetId())
|
||||
if delErr != nil {
|
||||
// TODO: maybe just warn?
|
||||
log.Fatalln(delErr)
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
return nil
|
||||
},
|
||||
})
|
||||
}
|
||||
|
||||
func TestInstanceResourceSchema(t *testing.T) {
|
||||
t.Parallel()
|
||||
|
||||
|
|
|
|||
|
|
@ -14,7 +14,7 @@ import (
|
|||
sqlserverflexUtils "tf-provider.git.onstackit.cloud/stackit-dev-tools/terraform-provider-stackitprivatepreview/stackit/internal/services/sqlserverflexalpha/utils"
|
||||
"tf-provider.git.onstackit.cloud/stackit-dev-tools/terraform-provider-stackitprivatepreview/stackit/internal/utils"
|
||||
|
||||
sqlserverflexalphaPkg "tf-provider.git.onstackit.cloud/stackit-dev-tools/terraform-provider-stackitprivatepreview/pkg_gen/sqlserverflexalpha"
|
||||
sqlserverflexalphaPkg "github.com/stackitcloud/stackit-sdk-go/services/sqlserverflex/v3alpha1api"
|
||||
sqlserverflexalphaGen "tf-provider.git.onstackit.cloud/stackit-dev-tools/terraform-provider-stackitprivatepreview/stackit/internal/services/sqlserverflexalpha/user/datasources_gen"
|
||||
)
|
||||
|
||||
|
|
@ -94,7 +94,7 @@ func (d *userDataSource) Read(ctx context.Context, req datasource.ReadRequest, r
|
|||
ctx = tflog.SetField(ctx, "user_id", userId)
|
||||
ctx = tflog.SetField(ctx, "region", region)
|
||||
|
||||
recordSetResp, err := d.client.GetUserRequest(ctx, projectId, region, instanceId, userId).Execute()
|
||||
recordSetResp, err := d.client.DefaultAPI.GetUserRequest(ctx, projectId, region, instanceId, userId).Execute()
|
||||
if err != nil {
|
||||
utils.LogError(
|
||||
ctx,
|
||||
|
|
|
|||
|
|
@ -8,14 +8,13 @@ import (
|
|||
"github.com/hashicorp/terraform-plugin-framework/attr"
|
||||
"github.com/hashicorp/terraform-plugin-framework/types"
|
||||
|
||||
"tf-provider.git.onstackit.cloud/stackit-dev-tools/terraform-provider-stackitprivatepreview/pkg_gen/sqlserverflexalpha"
|
||||
"tf-provider.git.onstackit.cloud/stackit-dev-tools/terraform-provider-stackitprivatepreview/stackit/internal/conversion"
|
||||
"github.com/stackitcloud/stackit-sdk-go/services/sqlserverflex/v3alpha1api"
|
||||
"tf-provider.git.onstackit.cloud/stackit-dev-tools/terraform-provider-stackitprivatepreview/stackit/internal/core"
|
||||
"tf-provider.git.onstackit.cloud/stackit-dev-tools/terraform-provider-stackitprivatepreview/stackit/internal/utils"
|
||||
)
|
||||
|
||||
// mapDataSourceFields maps the API response to a dataSourceModel.
|
||||
func mapDataSourceFields(userResp *sqlserverflexalpha.GetUserResponse, model *dataSourceModel, region string) error {
|
||||
func mapDataSourceFields(userResp *v3alpha1api.GetUserResponse, model *dataSourceModel, region string) error {
|
||||
if userResp == nil {
|
||||
return fmt.Errorf("response is nil")
|
||||
}
|
||||
|
|
@ -28,8 +27,8 @@ func mapDataSourceFields(userResp *sqlserverflexalpha.GetUserResponse, model *da
|
|||
var userId int64
|
||||
if model.UserId.ValueInt64() != 0 {
|
||||
userId = model.UserId.ValueInt64()
|
||||
} else if user.Id != nil {
|
||||
userId = *user.Id
|
||||
} else if user.Id != 0 {
|
||||
userId = user.Id
|
||||
} else {
|
||||
return fmt.Errorf("user id not present")
|
||||
}
|
||||
|
|
@ -39,13 +38,13 @@ func mapDataSourceFields(userResp *sqlserverflexalpha.GetUserResponse, model *da
|
|||
model.ProjectId.ValueString(), region, model.InstanceId.ValueString(), strconv.FormatInt(userId, 10),
|
||||
)
|
||||
model.UserId = types.Int64Value(userId)
|
||||
model.Username = types.StringPointerValue(user.Username)
|
||||
model.Username = types.StringValue(user.Username)
|
||||
|
||||
// Map roles
|
||||
if user.Roles == nil {
|
||||
model.Roles = types.List(types.SetNull(types.StringType))
|
||||
} else {
|
||||
resRoles := *user.Roles
|
||||
resRoles := user.Roles
|
||||
slices.Sort(resRoles)
|
||||
|
||||
var roles []attr.Value
|
||||
|
|
@ -60,17 +59,17 @@ func mapDataSourceFields(userResp *sqlserverflexalpha.GetUserResponse, model *da
|
|||
}
|
||||
|
||||
// Set remaining attributes
|
||||
model.Host = types.StringPointerValue(user.Host)
|
||||
model.Port = types.Int64PointerValue(user.Port)
|
||||
model.Host = types.StringValue(user.Host)
|
||||
model.Port = types.Int64Value(int64(user.Port))
|
||||
model.Region = types.StringValue(region)
|
||||
model.Status = types.StringPointerValue(user.Status)
|
||||
model.DefaultDatabase = types.StringPointerValue(user.DefaultDatabase)
|
||||
model.Status = types.StringValue(user.Status)
|
||||
model.DefaultDatabase = types.StringValue(user.DefaultDatabase)
|
||||
|
||||
return nil
|
||||
}
|
||||
|
||||
// mapFields maps the API response to a resourceModel.
|
||||
func mapFields(userResp *sqlserverflexalpha.GetUserResponse, model *resourceModel, region string) error {
|
||||
func mapFields(userResp *v3alpha1api.GetUserResponse, model *resourceModel, region string) error {
|
||||
if userResp == nil {
|
||||
return fmt.Errorf("response is nil")
|
||||
}
|
||||
|
|
@ -83,8 +82,8 @@ func mapFields(userResp *sqlserverflexalpha.GetUserResponse, model *resourceMode
|
|||
var userId int64
|
||||
if model.UserId.ValueInt64() != 0 {
|
||||
userId = model.UserId.ValueInt64()
|
||||
} else if user.Id != nil {
|
||||
userId = *user.Id
|
||||
} else if user.Id != 0 {
|
||||
userId = user.Id
|
||||
} else {
|
||||
return fmt.Errorf("user id not present")
|
||||
}
|
||||
|
|
@ -92,11 +91,11 @@ func mapFields(userResp *sqlserverflexalpha.GetUserResponse, model *resourceMode
|
|||
// Set main attributes
|
||||
model.Id = types.Int64Value(userId)
|
||||
model.UserId = types.Int64Value(userId)
|
||||
model.Username = types.StringPointerValue(user.Username)
|
||||
model.Username = types.StringValue(user.Username)
|
||||
|
||||
// Map roles
|
||||
if user.Roles != nil {
|
||||
resRoles := *user.Roles
|
||||
resRoles := user.Roles
|
||||
slices.Sort(resRoles)
|
||||
|
||||
var roles []attr.Value
|
||||
|
|
@ -116,14 +115,14 @@ func mapFields(userResp *sqlserverflexalpha.GetUserResponse, model *resourceMode
|
|||
}
|
||||
|
||||
// Set connection details
|
||||
model.Host = types.StringPointerValue(user.Host)
|
||||
model.Port = types.Int64PointerValue(user.Port)
|
||||
model.Host = types.StringValue(user.Host)
|
||||
model.Port = types.Int64Value(int64(user.Port))
|
||||
model.Region = types.StringValue(region)
|
||||
return nil
|
||||
}
|
||||
|
||||
// mapFieldsCreate maps the API response from creating a user to a resourceModel.
|
||||
func mapFieldsCreate(userResp *sqlserverflexalpha.CreateUserResponse, model *resourceModel, region string) error {
|
||||
func mapFieldsCreate(userResp *v3alpha1api.CreateUserResponse, model *resourceModel, region string) error {
|
||||
if userResp == nil {
|
||||
return fmt.Errorf("response is nil")
|
||||
}
|
||||
|
|
@ -132,21 +131,21 @@ func mapFieldsCreate(userResp *sqlserverflexalpha.CreateUserResponse, model *res
|
|||
}
|
||||
user := userResp
|
||||
|
||||
if user.Id == nil {
|
||||
if user.Id == 0 {
|
||||
return fmt.Errorf("user id not present")
|
||||
}
|
||||
userId := *user.Id
|
||||
userId := user.Id
|
||||
model.Id = types.Int64Value(userId)
|
||||
model.UserId = types.Int64Value(userId)
|
||||
model.Username = types.StringPointerValue(user.Username)
|
||||
model.Username = types.StringValue(user.Username)
|
||||
|
||||
if user.Password == nil {
|
||||
if user.Password == "" {
|
||||
return fmt.Errorf("user password not present")
|
||||
}
|
||||
model.Password = types.StringValue(*user.Password)
|
||||
model.Password = types.StringValue(user.Password)
|
||||
|
||||
if user.Roles != nil {
|
||||
resRoles := *user.Roles
|
||||
if len(user.Roles) > 0 {
|
||||
resRoles := user.Roles
|
||||
slices.Sort(resRoles)
|
||||
|
||||
var roles []attr.Value
|
||||
|
|
@ -164,14 +163,14 @@ func mapFieldsCreate(userResp *sqlserverflexalpha.CreateUserResponse, model *res
|
|||
model.Roles = types.List(types.SetNull(types.StringType))
|
||||
}
|
||||
|
||||
model.Password = types.StringPointerValue(user.Password)
|
||||
model.Uri = types.StringPointerValue(user.Uri)
|
||||
model.Password = types.StringValue(user.Password)
|
||||
model.Uri = types.StringValue(user.Uri)
|
||||
|
||||
model.Host = types.StringPointerValue(user.Host)
|
||||
model.Port = types.Int64PointerValue(user.Port)
|
||||
model.Host = types.StringValue(user.Host)
|
||||
model.Port = types.Int64Value(int64(user.Port))
|
||||
model.Region = types.StringValue(region)
|
||||
model.Status = types.StringPointerValue(user.Status)
|
||||
model.DefaultDatabase = types.StringPointerValue(user.DefaultDatabase)
|
||||
model.Status = types.StringValue(user.Status)
|
||||
model.DefaultDatabase = types.StringValue(user.DefaultDatabase)
|
||||
|
||||
return nil
|
||||
}
|
||||
|
|
@ -180,14 +179,14 @@ func mapFieldsCreate(userResp *sqlserverflexalpha.CreateUserResponse, model *res
|
|||
func toCreatePayload(
|
||||
model *resourceModel,
|
||||
roles []string,
|
||||
) (*sqlserverflexalpha.CreateUserRequestPayload, error) {
|
||||
) (*v3alpha1api.CreateUserRequestPayload, error) {
|
||||
if model == nil {
|
||||
return nil, fmt.Errorf("nil model")
|
||||
}
|
||||
|
||||
return &sqlserverflexalpha.CreateUserRequestPayload{
|
||||
Username: conversion.StringValueToPointer(model.Username),
|
||||
DefaultDatabase: conversion.StringValueToPointer(model.DefaultDatabase),
|
||||
Roles: &roles,
|
||||
return &v3alpha1api.CreateUserRequestPayload{
|
||||
Username: model.Username.ValueString(),
|
||||
DefaultDatabase: model.DefaultDatabase.ValueStringPointer(),
|
||||
Roles: roles,
|
||||
}, nil
|
||||
}
|
||||
|
|
|
|||
|
|
@ -6,23 +6,22 @@ import (
|
|||
"github.com/google/go-cmp/cmp"
|
||||
"github.com/hashicorp/terraform-plugin-framework/attr"
|
||||
"github.com/hashicorp/terraform-plugin-framework/types"
|
||||
"github.com/stackitcloud/stackit-sdk-go/core/utils"
|
||||
|
||||
"tf-provider.git.onstackit.cloud/stackit-dev-tools/terraform-provider-stackitprivatepreview/pkg_gen/sqlserverflexalpha"
|
||||
"github.com/stackitcloud/stackit-sdk-go/services/sqlserverflex/v3alpha1api"
|
||||
)
|
||||
|
||||
func TestMapDataSourceFields(t *testing.T) {
|
||||
const testRegion = "region"
|
||||
tests := []struct {
|
||||
description string
|
||||
input *sqlserverflexalpha.GetUserResponse
|
||||
input *v3alpha1api.GetUserResponse
|
||||
region string
|
||||
expected dataSourceModel
|
||||
isValid bool
|
||||
}{
|
||||
{
|
||||
"default_values",
|
||||
&sqlserverflexalpha.GetUserResponse{},
|
||||
&v3alpha1api.GetUserResponse{},
|
||||
testRegion,
|
||||
dataSourceModel{
|
||||
Id: types.StringValue("pid,region,iid,1"),
|
||||
|
|
@ -41,8 +40,8 @@ func TestMapDataSourceFields(t *testing.T) {
|
|||
},
|
||||
{
|
||||
"simple_values",
|
||||
&sqlserverflexalpha.GetUserResponse{
|
||||
Roles: &[]string{
|
||||
&v3alpha1api.GetUserResponse{
|
||||
Roles: []string{
|
||||
"##STACKIT_SQLAgentUser##",
|
||||
"##STACKIT_DatabaseManager##",
|
||||
"##STACKIT_LoginManager##",
|
||||
|
|
@ -50,11 +49,11 @@ func TestMapDataSourceFields(t *testing.T) {
|
|||
"##STACKIT_ProcessManager##",
|
||||
"##STACKIT_ServerManager##",
|
||||
},
|
||||
Username: utils.Ptr("username"),
|
||||
Host: utils.Ptr("host"),
|
||||
Port: utils.Ptr(int64(1234)),
|
||||
Status: utils.Ptr("active"),
|
||||
DefaultDatabase: utils.Ptr("default_db"),
|
||||
Username: "username",
|
||||
Host: "host",
|
||||
Port: int32(1234),
|
||||
Status: "active",
|
||||
DefaultDatabase: "default_db",
|
||||
},
|
||||
testRegion,
|
||||
dataSourceModel{
|
||||
|
|
@ -85,12 +84,12 @@ func TestMapDataSourceFields(t *testing.T) {
|
|||
},
|
||||
{
|
||||
"null_fields_and_int_conversions",
|
||||
&sqlserverflexalpha.GetUserResponse{
|
||||
Id: utils.Ptr(int64(1)),
|
||||
Roles: &[]string{},
|
||||
Username: nil,
|
||||
Host: nil,
|
||||
Port: utils.Ptr(int64(2123456789)),
|
||||
&v3alpha1api.GetUserResponse{
|
||||
Id: int64(1),
|
||||
Roles: []string{},
|
||||
Username: "",
|
||||
Host: "",
|
||||
Port: int32(2123456789),
|
||||
},
|
||||
testRegion,
|
||||
dataSourceModel{
|
||||
|
|
@ -115,14 +114,14 @@ func TestMapDataSourceFields(t *testing.T) {
|
|||
},
|
||||
{
|
||||
"nil_response_2",
|
||||
&sqlserverflexalpha.GetUserResponse{},
|
||||
&v3alpha1api.GetUserResponse{},
|
||||
testRegion,
|
||||
dataSourceModel{},
|
||||
false,
|
||||
},
|
||||
{
|
||||
"no_resource_id",
|
||||
&sqlserverflexalpha.GetUserResponse{},
|
||||
&v3alpha1api.GetUserResponse{},
|
||||
testRegion,
|
||||
dataSourceModel{},
|
||||
false,
|
||||
|
|
@ -158,16 +157,16 @@ func TestMapFieldsCreate(t *testing.T) {
|
|||
const testRegion = "region"
|
||||
tests := []struct {
|
||||
description string
|
||||
input *sqlserverflexalpha.CreateUserResponse
|
||||
input *v3alpha1api.CreateUserResponse
|
||||
region string
|
||||
expected resourceModel
|
||||
isValid bool
|
||||
}{
|
||||
{
|
||||
"default_values",
|
||||
&sqlserverflexalpha.CreateUserResponse{
|
||||
Id: utils.Ptr(int64(1)),
|
||||
Password: utils.Ptr(""),
|
||||
&v3alpha1api.CreateUserResponse{
|
||||
Id: (int64(1)),
|
||||
Password: (""),
|
||||
},
|
||||
testRegion,
|
||||
resourceModel{
|
||||
|
|
@ -186,19 +185,19 @@ func TestMapFieldsCreate(t *testing.T) {
|
|||
},
|
||||
{
|
||||
"simple_values",
|
||||
&sqlserverflexalpha.CreateUserResponse{
|
||||
Id: utils.Ptr(int64(2)),
|
||||
Roles: &[]string{
|
||||
&v3alpha1api.CreateUserResponse{
|
||||
Id: (int64(2)),
|
||||
Roles: []string{
|
||||
"role_2",
|
||||
"role_1",
|
||||
"",
|
||||
},
|
||||
Username: utils.Ptr("username"),
|
||||
Password: utils.Ptr("password"),
|
||||
Host: utils.Ptr("host"),
|
||||
Port: utils.Ptr(int64(1234)),
|
||||
Status: utils.Ptr("status"),
|
||||
DefaultDatabase: utils.Ptr("default_db"),
|
||||
Username: "username",
|
||||
Password: "password",
|
||||
Host: "host",
|
||||
Port: int32(1234),
|
||||
Status: "status",
|
||||
DefaultDatabase: "default_db",
|
||||
},
|
||||
testRegion,
|
||||
resourceModel{
|
||||
|
|
@ -227,13 +226,13 @@ func TestMapFieldsCreate(t *testing.T) {
|
|||
},
|
||||
{
|
||||
"null_fields_and_int_conversions",
|
||||
&sqlserverflexalpha.CreateUserResponse{
|
||||
Id: utils.Ptr(int64(3)),
|
||||
Roles: &[]string{},
|
||||
Username: nil,
|
||||
Password: utils.Ptr(""),
|
||||
Host: nil,
|
||||
Port: utils.Ptr(int64(2123456789)),
|
||||
&v3alpha1api.CreateUserResponse{
|
||||
Id: int64(3),
|
||||
Roles: []string{},
|
||||
Username: "",
|
||||
Password: "",
|
||||
Host: "",
|
||||
Port: int32(256789),
|
||||
},
|
||||
testRegion,
|
||||
resourceModel{
|
||||
|
|
@ -261,22 +260,22 @@ func TestMapFieldsCreate(t *testing.T) {
|
|||
},
|
||||
{
|
||||
"nil_response_2",
|
||||
&sqlserverflexalpha.CreateUserResponse{},
|
||||
&v3alpha1api.CreateUserResponse{},
|
||||
testRegion,
|
||||
resourceModel{},
|
||||
false,
|
||||
},
|
||||
{
|
||||
"no_resource_id",
|
||||
&sqlserverflexalpha.CreateUserResponse{},
|
||||
&v3alpha1api.CreateUserResponse{},
|
||||
testRegion,
|
||||
resourceModel{},
|
||||
false,
|
||||
},
|
||||
{
|
||||
"no_password",
|
||||
&sqlserverflexalpha.CreateUserResponse{
|
||||
Id: utils.Ptr(int64(1)),
|
||||
&v3alpha1api.CreateUserResponse{
|
||||
Id: int64(1),
|
||||
},
|
||||
testRegion,
|
||||
resourceModel{},
|
||||
|
|
@ -312,14 +311,14 @@ func TestMapFields(t *testing.T) {
|
|||
const testRegion = "region"
|
||||
tests := []struct {
|
||||
description string
|
||||
input *sqlserverflexalpha.GetUserResponse
|
||||
input *v3alpha1api.GetUserResponse
|
||||
region string
|
||||
expected resourceModel
|
||||
isValid bool
|
||||
}{
|
||||
{
|
||||
"default_values",
|
||||
&sqlserverflexalpha.GetUserResponse{},
|
||||
&v3alpha1api.GetUserResponse{},
|
||||
testRegion,
|
||||
resourceModel{
|
||||
Id: types.Int64Value(1),
|
||||
|
|
@ -336,15 +335,15 @@ func TestMapFields(t *testing.T) {
|
|||
},
|
||||
{
|
||||
"simple_values",
|
||||
&sqlserverflexalpha.GetUserResponse{
|
||||
Roles: &[]string{
|
||||
&v3alpha1api.GetUserResponse{
|
||||
Roles: []string{
|
||||
"role_2",
|
||||
"role_1",
|
||||
"",
|
||||
},
|
||||
Username: utils.Ptr("username"),
|
||||
Host: utils.Ptr("host"),
|
||||
Port: utils.Ptr(int64(1234)),
|
||||
Username: ("username"),
|
||||
Host: ("host"),
|
||||
Port: (int32(1234)),
|
||||
},
|
||||
testRegion,
|
||||
resourceModel{
|
||||
|
|
@ -370,12 +369,12 @@ func TestMapFields(t *testing.T) {
|
|||
},
|
||||
{
|
||||
"null_fields_and_int_conversions",
|
||||
&sqlserverflexalpha.GetUserResponse{
|
||||
Id: utils.Ptr(int64(1)),
|
||||
Roles: &[]string{},
|
||||
Username: nil,
|
||||
Host: nil,
|
||||
Port: utils.Ptr(int64(2123456789)),
|
||||
&v3alpha1api.GetUserResponse{
|
||||
Id: int64(1),
|
||||
Roles: []string{},
|
||||
Username: "",
|
||||
Host: "",
|
||||
Port: int32(2123456789),
|
||||
},
|
||||
testRegion,
|
||||
resourceModel{
|
||||
|
|
@ -400,14 +399,14 @@ func TestMapFields(t *testing.T) {
|
|||
},
|
||||
{
|
||||
"nil_response_2",
|
||||
&sqlserverflexalpha.GetUserResponse{},
|
||||
&v3alpha1api.GetUserResponse{},
|
||||
testRegion,
|
||||
resourceModel{},
|
||||
false,
|
||||
},
|
||||
{
|
||||
"no_resource_id",
|
||||
&sqlserverflexalpha.GetUserResponse{},
|
||||
&v3alpha1api.GetUserResponse{},
|
||||
testRegion,
|
||||
resourceModel{},
|
||||
false,
|
||||
|
|
@ -444,16 +443,16 @@ func TestToCreatePayload(t *testing.T) {
|
|||
description string
|
||||
input *resourceModel
|
||||
inputRoles []string
|
||||
expected *sqlserverflexalpha.CreateUserRequestPayload
|
||||
expected *v3alpha1api.CreateUserRequestPayload
|
||||
isValid bool
|
||||
}{
|
||||
{
|
||||
"default_values",
|
||||
&resourceModel{},
|
||||
[]string{},
|
||||
&sqlserverflexalpha.CreateUserRequestPayload{
|
||||
Roles: &[]string{},
|
||||
Username: nil,
|
||||
&v3alpha1api.CreateUserRequestPayload{
|
||||
Roles: []string{},
|
||||
Username: "",
|
||||
},
|
||||
true,
|
||||
},
|
||||
|
|
@ -466,12 +465,12 @@ func TestToCreatePayload(t *testing.T) {
|
|||
"role_1",
|
||||
"role_2",
|
||||
},
|
||||
&sqlserverflexalpha.CreateUserRequestPayload{
|
||||
Roles: &[]string{
|
||||
&v3alpha1api.CreateUserRequestPayload{
|
||||
Roles: []string{
|
||||
"role_1",
|
||||
"role_2",
|
||||
},
|
||||
Username: utils.Ptr("username"),
|
||||
Username: "username",
|
||||
},
|
||||
true,
|
||||
},
|
||||
|
|
@ -483,11 +482,11 @@ func TestToCreatePayload(t *testing.T) {
|
|||
[]string{
|
||||
"",
|
||||
},
|
||||
&sqlserverflexalpha.CreateUserRequestPayload{
|
||||
Roles: &[]string{
|
||||
&v3alpha1api.CreateUserRequestPayload{
|
||||
Roles: []string{
|
||||
"",
|
||||
},
|
||||
Username: nil,
|
||||
Username: "",
|
||||
},
|
||||
true,
|
||||
},
|
||||
|
|
@ -504,9 +503,9 @@ func TestToCreatePayload(t *testing.T) {
|
|||
Username: types.StringValue("username"),
|
||||
},
|
||||
[]string{},
|
||||
&sqlserverflexalpha.CreateUserRequestPayload{
|
||||
Roles: &[]string{},
|
||||
Username: utils.Ptr("username"),
|
||||
&v3alpha1api.CreateUserRequestPayload{
|
||||
Roles: []string{},
|
||||
Username: "username",
|
||||
},
|
||||
true,
|
||||
},
|
||||
|
|
|
|||
|
|
@ -18,7 +18,7 @@ import (
|
|||
"github.com/hashicorp/terraform-plugin-log/tflog"
|
||||
"github.com/stackitcloud/stackit-sdk-go/core/oapierror"
|
||||
|
||||
"tf-provider.git.onstackit.cloud/stackit-dev-tools/terraform-provider-stackitprivatepreview/pkg_gen/sqlserverflexalpha"
|
||||
sqlserverflexalpha "github.com/stackitcloud/stackit-sdk-go/services/sqlserverflex/v3alpha1api"
|
||||
"tf-provider.git.onstackit.cloud/stackit-dev-tools/terraform-provider-stackitprivatepreview/stackit/internal/conversion"
|
||||
sqlserverflexalphaUtils "tf-provider.git.onstackit.cloud/stackit-dev-tools/terraform-provider-stackitprivatepreview/stackit/internal/services/sqlserverflexalpha/utils"
|
||||
sqlserverflexalphaWait "tf-provider.git.onstackit.cloud/stackit-dev-tools/terraform-provider-stackitprivatepreview/stackit/internal/wait/sqlserverflexalpha"
|
||||
|
|
@ -231,7 +231,7 @@ func (r *userResource) Create(
|
|||
return
|
||||
}
|
||||
// Create new user
|
||||
userResp, err := r.client.CreateUserRequest(
|
||||
userResp, err := r.client.DefaultAPI.CreateUserRequest(
|
||||
ctx,
|
||||
projectId,
|
||||
region,
|
||||
|
|
@ -244,7 +244,7 @@ func (r *userResource) Create(
|
|||
|
||||
ctx = core.LogResponse(ctx)
|
||||
|
||||
if userResp == nil || userResp.Id == nil || *userResp.Id == 0 {
|
||||
if userResp == nil || userResp.Id == 0 {
|
||||
core.LogAndAddError(
|
||||
ctx,
|
||||
&resp.Diagnostics,
|
||||
|
|
@ -254,7 +254,7 @@ func (r *userResource) Create(
|
|||
return
|
||||
}
|
||||
|
||||
userId := *userResp.Id
|
||||
userId := userResp.Id
|
||||
ctx = tflog.SetField(ctx, "user_id", userId)
|
||||
|
||||
// Set data returned by API in identity
|
||||
|
|
@ -282,7 +282,7 @@ func (r *userResource) Create(
|
|||
|
||||
waitResp, err := sqlserverflexalphaWait.CreateUserWaitHandler(
|
||||
ctx,
|
||||
r.client,
|
||||
r.client.DefaultAPI,
|
||||
projectId,
|
||||
instanceId,
|
||||
region,
|
||||
|
|
@ -303,7 +303,7 @@ func (r *userResource) Create(
|
|||
return
|
||||
}
|
||||
|
||||
if waitResp.Id == nil {
|
||||
if waitResp.Id == 0 {
|
||||
core.LogAndAddError(
|
||||
ctx,
|
||||
&resp.Diagnostics,
|
||||
|
|
@ -357,7 +357,7 @@ func (r *userResource) Read(
|
|||
ctx = tflog.SetField(ctx, "user_id", userId)
|
||||
ctx = tflog.SetField(ctx, "region", region)
|
||||
|
||||
recordSetResp, err := r.client.GetUserRequest(ctx, projectId, region, instanceId, userId).Execute()
|
||||
recordSetResp, err := r.client.DefaultAPI.GetUserRequest(ctx, projectId, region, instanceId, userId).Execute()
|
||||
if err != nil {
|
||||
var oapiErr *oapierror.GenericOpenAPIError
|
||||
ok := errors.As(
|
||||
|
|
@ -445,7 +445,7 @@ func (r *userResource) Delete(
|
|||
|
||||
// Delete existing record set
|
||||
// err := r.client.DeleteUserRequest(ctx, projectId, region, instanceId, userId).Execute()
|
||||
err := r.client.DeleteUserRequestExecute(ctx, projectId, region, instanceId, userId)
|
||||
err := r.client.DefaultAPI.DeleteUserRequest(ctx, projectId, region, instanceId, userId).Execute()
|
||||
if err != nil {
|
||||
var oapiErr *oapierror.GenericOpenAPIError
|
||||
ok := errors.As(err, &oapiErr)
|
||||
|
|
@ -467,7 +467,7 @@ func (r *userResource) Delete(
|
|||
}
|
||||
}
|
||||
// Delete existing record set
|
||||
_, err = sqlserverflexalphaWait.DeleteUserWaitHandler(ctx, r.client, projectId, region, instanceId, userId).
|
||||
_, err = sqlserverflexalphaWait.DeleteUserWaitHandler(ctx, r.client.DefaultAPI, projectId, region, instanceId, userId).
|
||||
WaitWithContext(ctx)
|
||||
if err != nil {
|
||||
core.LogAndAddError(ctx, &resp.Diagnostics, "User Delete Error", fmt.Sprintf("Calling API: %v", err))
|
||||
|
|
|
|||
|
|
@ -4,7 +4,7 @@ import (
|
|||
"context"
|
||||
"fmt"
|
||||
|
||||
sqlserverflex "tf-provider.git.onstackit.cloud/stackit-dev-tools/terraform-provider-stackitprivatepreview/pkg_gen/sqlserverflexalpha"
|
||||
sqlserverflex "github.com/stackitcloud/stackit-sdk-go/services/sqlserverflex/v3alpha1api"
|
||||
|
||||
"github.com/hashicorp/terraform-plugin-framework/diag"
|
||||
"github.com/stackitcloud/stackit-sdk-go/core/config"
|
||||
|
|
|
|||
|
|
@ -10,7 +10,7 @@ import (
|
|||
sdkClients "github.com/stackitcloud/stackit-sdk-go/core/clients"
|
||||
"github.com/stackitcloud/stackit-sdk-go/core/config"
|
||||
|
||||
sqlserverflex "tf-provider.git.onstackit.cloud/stackit-dev-tools/terraform-provider-stackitprivatepreview/pkg_gen/sqlserverflexalpha"
|
||||
sqlserverflex "github.com/stackitcloud/stackit-sdk-go/services/sqlserverflex/v3alpha1api"
|
||||
|
||||
"tf-provider.git.onstackit.cloud/stackit-dev-tools/terraform-provider-stackitprivatepreview/stackit/internal/core"
|
||||
"tf-provider.git.onstackit.cloud/stackit-dev-tools/terraform-provider-stackitprivatepreview/stackit/internal/utils"
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue