fix: try fix errors (#71)
All checks were successful
Publish / Check GoReleaser config (push) Successful in 11s
Publish / Publish provider (push) Successful in 35m24s

## Description

<!-- **Please link some issue here describing what you are trying to achieve.**

In case there is no issue present for your PR, please consider creating one.
At least please give us some description what you are trying to achieve and why your change is needed. -->

relates to #1234

## Checklist

- [ ] Issue was linked above
- [ ] Code format was applied: `make fmt`
- [ ] Examples were added / adjusted (see `examples/` directory)
- [x] Docs are up-to-date: `make generate-docs` (will be checked by CI)
- [ ] Unit tests got implemented or updated
- [ ] Acceptance tests got implemented or updated (see e.g. [here](f5f99d1709/stackit/internal/services/dns/dns_acc_test.go))
- [x] Unit tests are passing: `make test` (will be checked by CI)
- [x] No linter issues: `make lint` (will be checked by CI)

Reviewed-on: #71
Co-authored-by: Marcel S. Henselin <marcel.henselin@stackit.cloud>
Co-committed-by: Marcel S. Henselin <marcel.henselin@stackit.cloud>
This commit is contained in:
Marcel_Henselin 2026-02-16 13:40:05 +00:00 committed by Marcel_Henselin
parent d5644ec27f
commit 7ee82366d7
Signed by: tf-provider.git.onstackit.cloud
GPG key ID: 6D7E8A1ED8955A9C
14 changed files with 140 additions and 40 deletions

View file

@ -593,7 +593,7 @@ func (r *instanceResource) ImportState(
ctx, &resp.Diagnostics,
"Error importing instance",
fmt.Sprintf(
"Expected import identifier with format: [project_id],[region],[instance_id] Got: %q",
"Expected import identifier with format [project_id],[region],[instance_id] Got: %q",
req.ID,
),
)

View file

@ -48,7 +48,7 @@ resource "stackitprivatepreview_postgresflexalpha_database" "{{ $db.Name }}" {
project_id = "{{ $db.ProjectId }}"
instance_id = stackitprivatepreview_postgresflexalpha_instance.{{ $tfName }}.instance_id
name = "{{ $db.Name }}"
owner = "{{ $db.Owner }}"
owner = stackitprivatepreview_postgresflexalpha_user.{{ $db.Owner }}.name
}
{{ end }}
{{ end }}

View file

@ -548,7 +548,7 @@ func (r *databaseResource) ImportState(
ctx, &resp.Diagnostics,
"Error importing database",
fmt.Sprintf(
"Expected import identifier with format: [project_id],[region],[instance_id],[database_name] Got: %q",
"Expected import identifier with format [project_id],[region],[instance_id],[database_name] Got: %q",
req.ID,
),
)

View file

@ -523,7 +523,7 @@ func (r *instanceResource) ImportState(
ctx, &resp.Diagnostics,
"Error importing instance",
fmt.Sprintf(
"Expected import identifier with format: [project_id],[region],[instance_id] Got: %q",
"Expected import identifier with format [project_id],[region],[instance_id] Got: %q",
req.ID,
),
)

View file

@ -63,9 +63,9 @@ func TestMapDataSourceFields(t *testing.T) {
Roles: types.List(
types.SetValueMust(
types.StringType, []attr.Value{
types.StringValue(""),
types.StringValue("role_1"),
types.StringValue("role_2"),
types.StringValue(""),
},
),
),
@ -138,7 +138,7 @@ func TestMapDataSourceFields(t *testing.T) {
t.Fatalf("Should not have failed: %v", err)
}
if tt.isValid {
diff := cmp.Diff(state, &tt.expected)
diff := cmp.Diff(&tt.expected, state)
if diff != "" {
t.Fatalf("Data does not match: %s", diff)
}
@ -183,8 +183,8 @@ func TestMapFieldsCreate(t *testing.T) {
&sqlserverflexalpha.CreateUserResponse{
Id: utils.Ptr(int64(2)),
Roles: &[]string{
"role_1",
"role_2",
"role_1",
"",
},
Username: utils.Ptr("username"),
@ -204,9 +204,9 @@ func TestMapFieldsCreate(t *testing.T) {
Roles: types.List(
types.SetValueMust(
types.StringType, []attr.Value{
types.StringValue(""),
types.StringValue("role_1"),
types.StringValue("role_2"),
types.StringValue(""),
},
),
),
@ -292,7 +292,7 @@ func TestMapFieldsCreate(t *testing.T) {
t.Fatalf("Should not have failed: %v", err)
}
if tt.isValid {
diff := cmp.Diff(state, &tt.expected)
diff := cmp.Diff(&tt.expected, state)
if diff != "" {
t.Fatalf("Data does not match: %s", diff)
}
@ -332,8 +332,8 @@ func TestMapFields(t *testing.T) {
"simple_values",
&sqlserverflexalpha.GetUserResponse{
Roles: &[]string{
"role_1",
"role_2",
"role_1",
"",
},
Username: utils.Ptr("username"),
@ -350,9 +350,9 @@ func TestMapFields(t *testing.T) {
Roles: types.List(
types.SetValueMust(
types.StringType, []attr.Value{
types.StringValue(""),
types.StringValue("role_1"),
types.StringValue("role_2"),
types.StringValue(""),
},
),
),
@ -423,7 +423,7 @@ func TestMapFields(t *testing.T) {
t.Fatalf("Should not have failed: %v", err)
}
if tt.isValid {
diff := cmp.Diff(state, &tt.expected)
diff := cmp.Diff(&tt.expected, state)
if diff != "" {
t.Fatalf("Data does not match: %s", diff)
}
@ -516,7 +516,7 @@ func TestToCreatePayload(t *testing.T) {
t.Fatalf("Should not have failed: %v", err)
}
if tt.isValid {
diff := cmp.Diff(output, tt.expected)
diff := cmp.Diff(tt.expected, output)
if diff != "" {
t.Fatalf("Data does not match: %s", diff)
}

View file

@ -548,7 +548,7 @@ func (r *databaseResource) ImportState(
ctx, &resp.Diagnostics,
"Error importing database",
fmt.Sprintf(
"Expected import identifier with format: [project_id],[region],[instance_id],[database_name] Got: %q",
"Expected import identifier with format [project_id],[region],[instance_id],[database_name] Got: %q",
req.ID,
),
)

View file

@ -293,13 +293,6 @@ func (r *instanceResource) Read(ctx context.Context, req resource.ReadRequest, r
return
}
// Read identity data
var identityData InstanceResourceIdentityModel
resp.Diagnostics.Append(req.Identity.Get(ctx, &identityData)...)
if resp.Diagnostics.HasError() {
return
}
ctx = core.InitProviderContext(ctx)
projectId := data.ProjectId.ValueString()
@ -523,7 +516,7 @@ func (r *instanceResource) ImportState(
ctx, &resp.Diagnostics,
"Error importing instance",
fmt.Sprintf(
"Expected import identifier with format: [project_id],[region],[instance_id] Got: %q",
"Expected import identifier with format [project_id],[region],[instance_id] Got: %q",
req.ID,
),
)

View file

@ -15,7 +15,7 @@ import (
"github.com/stackitcloud/stackit-sdk-go/core/config"
"tf-provider.git.onstackit.cloud/stackit-dev-tools/terraform-provider-stackitprivatepreview/internal/testutils"
sqlserverflexbeta2 "tf-provider.git.onstackit.cloud/stackit-dev-tools/terraform-provider-stackitprivatepreview/pkg_gen/sqlserverflexbeta"
sqlserverflexbetaResGen "tf-provider.git.onstackit.cloud/stackit-dev-tools/terraform-provider-stackitprivatepreview/pkg_gen/sqlserverflexbeta"
sqlserverflexbeta "tf-provider.git.onstackit.cloud/stackit-dev-tools/terraform-provider-stackitprivatepreview/stackit/internal/services/sqlserverflexbeta/instance"
// The fwresource import alias is so there is no collision
@ -36,7 +36,7 @@ func init() {
F: func(region string) error {
ctx := context.Background()
apiClientConfigOptions := []config.ConfigurationOption{}
apiClient, err := sqlserverflexbeta2.NewAPIClient(apiClientConfigOptions...)
apiClient, err := sqlserverflexbetaResGen.NewAPIClient(apiClientConfigOptions...)
if err != nil {
log.Fatalln(err)
}
@ -228,6 +228,67 @@ func TestAccInstance(t *testing.T) {
})
}
func TestAccInstanceReApply(t *testing.T) {
exData := getExample()
resource.ParallelTest(t, resource.TestCase{
PreCheck: func() {
testAccPreCheck(t)
t.Logf(" ... working on instance %s", exData.TfName)
testInstances = append(testInstances, exData.TfName)
},
ProtoV6ProviderFactories: testutils.TestAccProtoV6ProviderFactories,
Steps: []resource.TestStep{
// Create and verify
{
Config: testutils.StringFromTemplateMust(
"testdata/instance_template.gompl",
exData,
),
Check: resource.ComposeAggregateTestCheckFunc(
resource.TestCheckResourceAttr(resName("instance", exData.TfName), "name", exData.Name),
resource.TestCheckResourceAttrSet(resName("instance", exData.TfName), "id"),
// TODO: check all fields
),
},
// Create and verify
{
Config: testutils.StringFromTemplateMust(
"testdata/instance_template.gompl",
exData,
),
Check: resource.ComposeAggregateTestCheckFunc(
resource.TestCheckResourceAttr(resName("instance", exData.TfName), "name", exData.Name),
resource.TestCheckResourceAttrSet(resName("instance", exData.TfName), "id"),
// TODO: check all fields
),
},
{
RefreshState: true,
},
// Create and verify
{
Config: testutils.StringFromTemplateMust(
"testdata/instance_template.gompl",
exData,
),
Check: resource.ComposeAggregateTestCheckFunc(
resource.TestCheckResourceAttr(resName("instance", exData.TfName), "name", exData.Name),
resource.TestCheckResourceAttrSet(resName("instance", exData.TfName), "id"),
// TODO: check all fields
),
},
// Import test
{
ResourceName: resName("instance", exData.TfName),
ImportStateKind: resource.ImportBlockWithResourceIdentity,
ImportState: true,
// ImportStateVerify is not supported with plannable import blocks
// ImportStateVerify: true,
},
},
})
}
func TestAccInstanceNoEncryption(t *testing.T) {
data := getExample()

View file

@ -46,7 +46,9 @@ func mapDataSourceFields(userResp *sqlserverflexbeta.GetUserResponse, model *dat
model.Roles = types.List(types.SetNull(types.StringType))
} else {
var roles []attr.Value
for _, role := range *user.Roles {
resRoles := *user.Roles
slices.Sort(resRoles)
for _, role := range resRoles {
roles = append(roles, types.StringValue(string(role)))
}
rolesSet, diags := types.SetValue(types.StringType, roles)
@ -183,9 +185,14 @@ func toCreatePayload(
return nil, fmt.Errorf("nil model")
}
return &sqlserverflexbeta.CreateUserRequestPayload{
Username: conversion.StringValueToPointer(model.Username),
DefaultDatabase: conversion.StringValueToPointer(model.DefaultDatabase),
Roles: &roles,
}, nil
pl := sqlserverflexbeta.CreateUserRequestPayload{
Username: conversion.StringValueToPointer(model.Username),
Roles: &roles,
}
slices.Sort(roles)
if !model.DefaultDatabase.IsNull() || !model.DefaultDatabase.IsUnknown() {
pl.DefaultDatabase = conversion.StringValueToPointer(model.DefaultDatabase)
}
return &pl, nil
}

View file

@ -63,9 +63,9 @@ func TestMapDataSourceFields(t *testing.T) {
Roles: types.List(
types.SetValueMust(
types.StringType, []attr.Value{
types.StringValue(""),
types.StringValue("role_1"),
types.StringValue("role_2"),
types.StringValue(""),
},
),
),
@ -138,7 +138,7 @@ func TestMapDataSourceFields(t *testing.T) {
t.Fatalf("Should not have failed: %v", err)
}
if tt.isValid {
diff := cmp.Diff(state, &tt.expected)
diff := cmp.Diff(&tt.expected, state)
if diff != "" {
t.Fatalf("Data does not match: %s", diff)
}
@ -204,9 +204,9 @@ func TestMapFieldsCreate(t *testing.T) {
Roles: types.List(
types.SetValueMust(
types.StringType, []attr.Value{
types.StringValue(""),
types.StringValue("role_1"),
types.StringValue("role_2"),
types.StringValue(""),
},
),
),
@ -292,7 +292,7 @@ func TestMapFieldsCreate(t *testing.T) {
t.Fatalf("Should not have failed: %v", err)
}
if tt.isValid {
diff := cmp.Diff(state, &tt.expected)
diff := cmp.Diff(&tt.expected, state)
if diff != "" {
t.Fatalf("Data does not match: %s", diff)
}
@ -332,8 +332,8 @@ func TestMapFields(t *testing.T) {
"simple_values",
&sqlserverflexbeta.GetUserResponse{
Roles: &[]string{
"role_1",
"role_2",
"role_1",
"",
},
Username: utils.Ptr("username"),
@ -350,9 +350,9 @@ func TestMapFields(t *testing.T) {
Roles: types.List(
types.SetValueMust(
types.StringType, []attr.Value{
types.StringValue(""),
types.StringValue("role_1"),
types.StringValue("role_2"),
types.StringValue(""),
},
),
),
@ -423,7 +423,7 @@ func TestMapFields(t *testing.T) {
t.Fatalf("Should not have failed: %v", err)
}
if tt.isValid {
diff := cmp.Diff(state, &tt.expected)
diff := cmp.Diff(&tt.expected, state)
if diff != "" {
t.Fatalf("Data does not match: %s", diff)
}

View file

@ -2,6 +2,7 @@ fields:
- name: 'id'
modifiers:
- 'UseStateForUnknown'
- 'RequiresReplace'
- name: 'instance_id'
validators:
@ -22,6 +23,7 @@ fields:
- name: 'region'
modifiers:
- 'RequiresReplace'
- 'RequiresReplace'
- name: 'user_id'
modifiers:
@ -31,10 +33,12 @@ fields:
- name: 'username'
modifiers:
- 'UseStateForUnknown'
- 'RequiresReplace'
- name: 'roles'
modifiers:
- 'UseStateForUnknown'
- 'RequiresReplace'
- name: 'password'
modifiers:

View file

@ -11,6 +11,7 @@ import (
"strings"
"time"
"github.com/hashicorp/terraform-plugin-framework/attr"
"github.com/hashicorp/terraform-plugin-framework/path"
"github.com/hashicorp/terraform-plugin-framework/resource"
"github.com/hashicorp/terraform-plugin-framework/resource/identityschema"
@ -107,6 +108,38 @@ func (r *userResource) ModifyPlan(
return
}
// TODO: verify if this is needed - START
var configRoles []string
diags := configModel.Roles.ElementsAs(ctx, &configRoles, false)
resp.Diagnostics.Append(diags...)
if diags.HasError() {
return
}
var planRoles []string
diags = planModel.Roles.ElementsAs(ctx, &planRoles, false)
resp.Diagnostics.Append(diags...)
if diags.HasError() {
return
}
slices.Sort(configRoles)
slices.Sort(planRoles)
if !slices.Equal(configRoles, planRoles) {
var roles []attr.Value
for _, role := range configRoles {
roles = append(roles, types.StringValue(string(role)))
}
rolesSet, diags := types.SetValue(types.StringType, roles)
resp.Diagnostics.Append(diags...)
if diags.HasError() {
return
}
planModel.Roles = types.List(rolesSet)
}
// TODO: verify if this is needed - END
resp.Diagnostics.Append(resp.Plan.Set(ctx, planModel)...)
if resp.Diagnostics.HasError() {
return

View file

@ -208,7 +208,7 @@ func PartialUpdateInstanceWaitHandler(
case InstanceStateUnknown:
return false, nil, nil
case InstanceStateFailed:
return true, s, fmt.Errorf("update failed for instance with id %s", instanceId)
return true, s, fmt.Errorf("update got status FAILURE for instance with id %s", instanceId)
}
},
)

View file

@ -161,8 +161,10 @@ func CreateInstanceWaitHandler(
return false, nil, nil
}
return true, s, nil
case strings.ToLower(InstanceStateUnknown), strings.ToLower(InstanceStateFailed):
return true, nil, fmt.Errorf("create failed for instance with id %s", instanceId)
case strings.ToLower(InstanceStateUnknown):
return true, nil, fmt.Errorf("create failed for instance %s with status %s", instanceId, InstanceStateUnknown)
case strings.ToLower(InstanceStateFailed):
return true, nil, fmt.Errorf("create failed for instance %s with status %s", instanceId, InstanceStateFailed)
case strings.ToLower(InstanceStatePending), strings.ToLower(InstanceStateProcessing):
tflog.Info(
ctx, "request is being handled", map[string]interface{}{