fix: builder and sdk changes (#81)
## Description
<!-- **Please link some issue here describing what you are trying to achieve.**
In case there is no issue present for your PR, please consider creating one.
At least please give us some description what you are trying to achieve and why your change is needed. -->
relates to #1234
## Checklist
- [ ] Issue was linked above
- [ ] Code format was applied: `make fmt`
- [ ] Examples were added / adjusted (see `examples/` directory)
- [x] Docs are up-to-date: `make generate-docs` (will be checked by CI)
- [ ] Unit tests got implemented or updated
- [ ] Acceptance tests got implemented or updated (see e.g. [here](f5f99d1709/stackit/internal/services/dns/dns_acc_test.go))
- [x] Unit tests are passing: `make test` (will be checked by CI)
- [x] No linter issues: `make lint` (will be checked by CI)
Co-authored-by: Marcel S. Henselin <marcel.henselin@stackit.cloud>
Co-authored-by: marcel.henselin <marcel.henselin@stackit.cloud>
Reviewed-on: #81
This commit is contained in:
parent
635a9abf20
commit
1033d7e034
145 changed files with 5944 additions and 5298 deletions
|
|
@ -16,7 +16,8 @@ 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"
|
||||
|
||||
sqlserverflexbetaPkg "tf-provider.git.onstackit.cloud/stackit-dev-tools/terraform-provider-stackitprivatepreview/pkg_gen/sqlserverflexbeta"
|
||||
sqlserverflexbetaPkg "github.com/stackitcloud/stackit-sdk-go/services/sqlserverflex/v3beta1api"
|
||||
|
||||
sqlserverflexbetaGen "tf-provider.git.onstackit.cloud/stackit-dev-tools/terraform-provider-stackitprivatepreview/stackit/internal/services/sqlserverflexbeta/database/datasources_gen"
|
||||
)
|
||||
|
||||
|
|
@ -119,7 +120,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)
|
||||
|
|
|
|||
|
|
@ -4,8 +4,10 @@ import (
|
|||
"fmt"
|
||||
|
||||
"github.com/hashicorp/terraform-plugin-framework/types"
|
||||
utils2 "github.com/stackitcloud/stackit-sdk-go/core/utils"
|
||||
|
||||
sqlserverflexbeta "github.com/stackitcloud/stackit-sdk-go/services/sqlserverflex/v3beta1api"
|
||||
|
||||
"tf-provider.git.onstackit.cloud/stackit-dev-tools/terraform-provider-stackitprivatepreview/pkg_gen/sqlserverflexbeta"
|
||||
"tf-provider.git.onstackit.cloud/stackit-dev-tools/terraform-provider-stackitprivatepreview/stackit/internal/utils"
|
||||
)
|
||||
|
||||
|
|
@ -14,7 +16,7 @@ func mapFields(source *sqlserverflexbeta.GetDatabaseResponse, model *dataSourceM
|
|||
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 {
|
||||
|
|
@ -24,8 +26,8 @@ func mapFields(source *sqlserverflexbeta.GetDatabaseResponse, model *dataSourceM
|
|||
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")
|
||||
}
|
||||
|
|
@ -37,7 +39,7 @@ func mapFields(source *sqlserverflexbeta.GetDatabaseResponse, model *dataSourceM
|
|||
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(
|
||||
|
|
@ -55,7 +57,7 @@ func mapResourceFields(source *sqlserverflexbeta.GetDatabaseResponse, model *res
|
|||
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 {
|
||||
|
|
@ -65,8 +67,8 @@ func mapResourceFields(source *sqlserverflexbeta.GetDatabaseResponse, model *res
|
|||
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")
|
||||
}
|
||||
|
|
@ -79,8 +81,8 @@ func mapResourceFields(source *sqlserverflexbeta.GetDatabaseResponse, model *res
|
|||
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())
|
||||
|
|
@ -95,9 +97,9 @@ func toCreatePayload(model *resourceModel) (*sqlserverflexbeta.CreateDatabaseReq
|
|||
}
|
||||
|
||||
return &sqlserverflexbeta.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: utils2.Ptr(int32(model.Compatibility.ValueInt64())), //nolint:gosec // TODO
|
||||
}, nil
|
||||
}
|
||||
|
|
|
|||
|
|
@ -6,14 +6,14 @@ import (
|
|||
"github.com/google/go-cmp/cmp"
|
||||
"github.com/hashicorp/terraform-plugin-framework/types"
|
||||
"github.com/stackitcloud/stackit-sdk-go/core/utils"
|
||||
"github.com/stackitcloud/stackit-sdk-go/services/sqlserverflex/v3beta1api"
|
||||
|
||||
"tf-provider.git.onstackit.cloud/stackit-dev-tools/terraform-provider-stackitprivatepreview/pkg_gen/sqlserverflexbeta"
|
||||
datasource "tf-provider.git.onstackit.cloud/stackit-dev-tools/terraform-provider-stackitprivatepreview/stackit/internal/services/sqlserverflexbeta/database/datasources_gen"
|
||||
)
|
||||
|
||||
func TestMapFields(t *testing.T) {
|
||||
type given struct {
|
||||
source *sqlserverflexbeta.GetDatabaseResponse
|
||||
source *v3beta1api.GetDatabaseResponse
|
||||
model *dataSourceModel
|
||||
region string
|
||||
}
|
||||
|
|
@ -30,12 +30,12 @@ func TestMapFields(t *testing.T) {
|
|||
{
|
||||
name: "should map fields correctly",
|
||||
given: given{
|
||||
source: &sqlserverflexbeta.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"),
|
||||
source: &v3beta1api.GetDatabaseResponse{
|
||||
Id: int64(1),
|
||||
Name: "my-db",
|
||||
CollationName: "collation",
|
||||
CompatibilityLevel: int32(150),
|
||||
Owner: "my-owner",
|
||||
},
|
||||
model: &dataSourceModel{
|
||||
DatabaseModel: datasource.DatabaseModel{
|
||||
|
|
@ -73,7 +73,7 @@ func TestMapFields(t *testing.T) {
|
|||
{
|
||||
name: "should fail on nil source ID",
|
||||
given: given{
|
||||
source: &sqlserverflexbeta.GetDatabaseResponse{Id: nil},
|
||||
source: &v3beta1api.GetDatabaseResponse{Id: 0},
|
||||
model: &dataSourceModel{},
|
||||
},
|
||||
expected: expected{err: true},
|
||||
|
|
@ -81,7 +81,7 @@ func TestMapFields(t *testing.T) {
|
|||
{
|
||||
name: "should fail on nil model",
|
||||
given: given{
|
||||
source: &sqlserverflexbeta.GetDatabaseResponse{Id: utils.Ptr(int64(1))},
|
||||
source: &v3beta1api.GetDatabaseResponse{Id: int64(1)},
|
||||
model: nil,
|
||||
},
|
||||
expected: expected{err: true},
|
||||
|
|
@ -107,7 +107,7 @@ func TestMapFields(t *testing.T) {
|
|||
|
||||
func TestMapResourceFields(t *testing.T) {
|
||||
type given struct {
|
||||
source *sqlserverflexbeta.GetDatabaseResponse
|
||||
source *v3beta1api.GetDatabaseResponse
|
||||
model *resourceModel
|
||||
region string
|
||||
}
|
||||
|
|
@ -124,10 +124,10 @@ func TestMapResourceFields(t *testing.T) {
|
|||
{
|
||||
name: "should map fields correctly",
|
||||
given: given{
|
||||
source: &sqlserverflexbeta.GetDatabaseResponse{
|
||||
Id: utils.Ptr(int64(1)),
|
||||
Name: utils.Ptr("my-db"),
|
||||
Owner: utils.Ptr("my-owner"),
|
||||
source: &v3beta1api.GetDatabaseResponse{
|
||||
Id: (int64(1)),
|
||||
Name: ("my-db"),
|
||||
Owner: ("my-owner"),
|
||||
},
|
||||
model: &resourceModel{
|
||||
ProjectId: types.StringValue("my-project"),
|
||||
|
|
@ -183,7 +183,7 @@ func TestToCreatePayload(t *testing.T) {
|
|||
model *resourceModel
|
||||
}
|
||||
type expected struct {
|
||||
payload *sqlserverflexbeta.CreateDatabaseRequestPayload
|
||||
payload *v3beta1api.CreateDatabaseRequestPayload
|
||||
err bool
|
||||
}
|
||||
|
||||
|
|
@ -201,9 +201,10 @@ func TestToCreatePayload(t *testing.T) {
|
|||
},
|
||||
},
|
||||
expected: expected{
|
||||
payload: &sqlserverflexbeta.CreateDatabaseRequestPayload{
|
||||
Name: utils.Ptr("my-db"),
|
||||
Owner: utils.Ptr("my-owner"),
|
||||
payload: &v3beta1api.CreateDatabaseRequestPayload{
|
||||
Name: "my-db",
|
||||
Owner: "my-owner",
|
||||
Compatibility: utils.Ptr(int32(0)),
|
||||
},
|
||||
},
|
||||
},
|
||||
|
|
|
|||
|
|
@ -16,8 +16,10 @@ import (
|
|||
"github.com/hashicorp/terraform-plugin-log/tflog"
|
||||
"github.com/stackitcloud/stackit-sdk-go/core/config"
|
||||
"github.com/stackitcloud/stackit-sdk-go/core/oapierror"
|
||||
utils2 "github.com/stackitcloud/stackit-sdk-go/core/utils"
|
||||
|
||||
sqlserverflexbeta "github.com/stackitcloud/stackit-sdk-go/services/sqlserverflex/v3beta1api"
|
||||
|
||||
"tf-provider.git.onstackit.cloud/stackit-dev-tools/terraform-provider-stackitprivatepreview/pkg_gen/sqlserverflexbeta"
|
||||
"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/sqlserverflexbeta"
|
||||
|
||||
|
|
@ -176,15 +178,15 @@ func (r *databaseResource) Create(ctx context.Context, req resource.CreateReques
|
|||
}
|
||||
|
||||
if !data.Compatibility.IsNull() && !data.Compatibility.IsUnknown() {
|
||||
payLoad.Compatibility = data.Compatibility.ValueInt64Pointer()
|
||||
payLoad.Compatibility = utils2.Ptr(int32(data.Compatibility.ValueInt64())) //nolint:gosec // TODO
|
||||
}
|
||||
|
||||
payLoad.Name = data.Name.ValueStringPointer()
|
||||
payLoad.Owner = data.Owner.ValueStringPointer()
|
||||
payLoad.Name = data.Name.ValueString()
|
||||
payLoad.Owner = data.Owner.ValueString()
|
||||
|
||||
_, err := wait.WaitForUserWaitHandler(
|
||||
ctx,
|
||||
r.client,
|
||||
r.client.DefaultAPI,
|
||||
projectId,
|
||||
instanceId,
|
||||
region,
|
||||
|
|
@ -202,7 +204,7 @@ func (r *databaseResource) Create(ctx context.Context, req resource.CreateReques
|
|||
return
|
||||
}
|
||||
|
||||
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 {
|
||||
|
|
@ -215,7 +217,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,
|
||||
|
|
@ -225,7 +227,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)
|
||||
|
||||
|
|
@ -245,7 +247,7 @@ func (r *databaseResource) Create(ctx context.Context, req resource.CreateReques
|
|||
|
||||
waitResp, err := wait.CreateDatabaseWaitHandler(
|
||||
ctx,
|
||||
r.client,
|
||||
r.client.DefaultAPI,
|
||||
projectId,
|
||||
instanceId,
|
||||
region,
|
||||
|
|
@ -265,7 +267,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,
|
||||
|
|
@ -275,7 +277,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,
|
||||
|
|
@ -285,7 +287,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,
|
||||
|
|
@ -295,7 +297,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,
|
||||
|
|
@ -348,7 +350,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) {
|
||||
|
|
@ -419,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,
|
||||
|
|
@ -555,5 +557,3 @@ func (r *databaseResource) ImportState(
|
|||
|
||||
tflog.Info(ctx, "Sqlserverflexbeta database state imported")
|
||||
}
|
||||
|
||||
// extractIdentityData extracts essential identifiers from the resource model, falling back to the identity mode
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue