fix: some more fix tests (#72)
## 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: #72
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:
parent
7ee82366d7
commit
f05e90c35a
10 changed files with 137 additions and 243 deletions
|
|
@ -281,24 +281,12 @@ func (r *databaseResource) Read(
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
// Read identity data
|
|
||||||
var identityData DatabaseResourceIdentityModel
|
|
||||||
resp.Diagnostics.Append(req.Identity.Get(ctx, &identityData)...)
|
|
||||||
if resp.Diagnostics.HasError() {
|
|
||||||
return
|
|
||||||
}
|
|
||||||
|
|
||||||
ctx = core.InitProviderContext(ctx)
|
ctx = core.InitProviderContext(ctx)
|
||||||
|
|
||||||
projectId, region, instanceId, databaseId, errExt := r.extractIdentityData(model, identityData)
|
projectId := model.ProjectId.ValueString()
|
||||||
if errExt != nil {
|
instanceId := model.InstanceId.ValueString()
|
||||||
core.LogAndAddError(
|
region := model.Region.ValueString()
|
||||||
ctx,
|
databaseId := model.DatabaseId.ValueInt64()
|
||||||
&resp.Diagnostics,
|
|
||||||
extractErrorSummary,
|
|
||||||
fmt.Sprintf(extractErrorMessage, errExt),
|
|
||||||
)
|
|
||||||
}
|
|
||||||
|
|
||||||
ctx = tflog.SetField(ctx, "project_id", projectId)
|
ctx = tflog.SetField(ctx, "project_id", projectId)
|
||||||
ctx = tflog.SetField(ctx, "instance_id", instanceId)
|
ctx = tflog.SetField(ctx, "instance_id", instanceId)
|
||||||
|
|
|
||||||
|
|
@ -164,16 +164,16 @@ func TestMapFieldsCreate(t *testing.T) {
|
||||||
},
|
},
|
||||||
testRegion,
|
testRegion,
|
||||||
resourceModel{
|
resourceModel{
|
||||||
Id: types.Int64Value(1),
|
Id: types.Int64Value(1),
|
||||||
UserId: types.Int64Value(1),
|
UserId: types.Int64Value(1),
|
||||||
InstanceId: types.StringValue("iid"),
|
InstanceId: types.StringValue("iid"),
|
||||||
ProjectId: types.StringValue("pid"),
|
ProjectId: types.StringValue("pid"),
|
||||||
Name: types.StringNull(),
|
Name: types.StringNull(),
|
||||||
Roles: types.List(types.SetNull(types.StringType)),
|
Roles: types.List(types.SetNull(types.StringType)),
|
||||||
Password: types.StringNull(),
|
Password: types.StringNull(),
|
||||||
Region: types.StringValue(testRegion),
|
Region: types.StringValue(testRegion),
|
||||||
Status: types.StringNull(),
|
Status: types.StringNull(),
|
||||||
ConnectionString: types.StringNull(),
|
//ConnectionString: types.StringNull(),
|
||||||
},
|
},
|
||||||
true,
|
true,
|
||||||
},
|
},
|
||||||
|
|
@ -186,16 +186,16 @@ func TestMapFieldsCreate(t *testing.T) {
|
||||||
},
|
},
|
||||||
testRegion,
|
testRegion,
|
||||||
resourceModel{
|
resourceModel{
|
||||||
Id: types.Int64Value(1),
|
Id: types.Int64Value(1),
|
||||||
UserId: types.Int64Value(1),
|
UserId: types.Int64Value(1),
|
||||||
InstanceId: types.StringValue("iid"),
|
InstanceId: types.StringValue("iid"),
|
||||||
ProjectId: types.StringValue("pid"),
|
ProjectId: types.StringValue("pid"),
|
||||||
Name: types.StringValue("username"),
|
Name: types.StringValue("username"),
|
||||||
Roles: types.List(types.SetNull(types.StringType)),
|
Roles: types.List(types.SetNull(types.StringType)),
|
||||||
Password: types.StringNull(),
|
Password: types.StringNull(),
|
||||||
Region: types.StringValue(testRegion),
|
Region: types.StringValue(testRegion),
|
||||||
Status: types.StringValue("status"),
|
Status: types.StringValue("status"),
|
||||||
ConnectionString: types.StringNull(),
|
//ConnectionString: types.StringNull(),
|
||||||
},
|
},
|
||||||
true,
|
true,
|
||||||
},
|
},
|
||||||
|
|
@ -208,16 +208,16 @@ func TestMapFieldsCreate(t *testing.T) {
|
||||||
},
|
},
|
||||||
testRegion,
|
testRegion,
|
||||||
resourceModel{
|
resourceModel{
|
||||||
Id: types.Int64Value(1),
|
Id: types.Int64Value(1),
|
||||||
UserId: types.Int64Value(1),
|
UserId: types.Int64Value(1),
|
||||||
InstanceId: types.StringValue("iid"),
|
InstanceId: types.StringValue("iid"),
|
||||||
ProjectId: types.StringValue("pid"),
|
ProjectId: types.StringValue("pid"),
|
||||||
Name: types.StringNull(),
|
Name: types.StringNull(),
|
||||||
Roles: types.List(types.SetNull(types.StringType)),
|
Roles: types.List(types.SetNull(types.StringType)),
|
||||||
Password: types.StringNull(),
|
Password: types.StringNull(),
|
||||||
Region: types.StringValue(testRegion),
|
Region: types.StringValue(testRegion),
|
||||||
Status: types.StringNull(),
|
Status: types.StringNull(),
|
||||||
ConnectionString: types.StringNull(),
|
//ConnectionString: types.StringNull(),
|
||||||
},
|
},
|
||||||
true,
|
true,
|
||||||
},
|
},
|
||||||
|
|
@ -285,15 +285,15 @@ func TestMapFields(t *testing.T) {
|
||||||
},
|
},
|
||||||
testRegion,
|
testRegion,
|
||||||
resourceModel{
|
resourceModel{
|
||||||
Id: types.Int64Value(1),
|
Id: types.Int64Value(1),
|
||||||
UserId: types.Int64Value(int64(1)),
|
UserId: types.Int64Value(int64(1)),
|
||||||
InstanceId: types.StringValue("iid"),
|
InstanceId: types.StringValue("iid"),
|
||||||
ProjectId: types.StringValue("pid"),
|
ProjectId: types.StringValue("pid"),
|
||||||
Name: types.StringNull(),
|
Name: types.StringNull(),
|
||||||
Roles: types.List(types.SetNull(types.StringType)),
|
Roles: types.List(types.SetNull(types.StringType)),
|
||||||
Region: types.StringValue(testRegion),
|
Region: types.StringValue(testRegion),
|
||||||
Status: types.StringNull(),
|
Status: types.StringNull(),
|
||||||
ConnectionString: types.StringNull(),
|
//ConnectionString: types.StringNull(),
|
||||||
},
|
},
|
||||||
true,
|
true,
|
||||||
},
|
},
|
||||||
|
|
@ -324,9 +324,9 @@ func TestMapFields(t *testing.T) {
|
||||||
},
|
},
|
||||||
),
|
),
|
||||||
),
|
),
|
||||||
Region: types.StringValue(testRegion),
|
Region: types.StringValue(testRegion),
|
||||||
Status: types.StringNull(),
|
Status: types.StringNull(),
|
||||||
ConnectionString: types.StringNull(),
|
//ConnectionString: types.StringNull(),
|
||||||
},
|
},
|
||||||
true,
|
true,
|
||||||
},
|
},
|
||||||
|
|
@ -338,15 +338,15 @@ func TestMapFields(t *testing.T) {
|
||||||
},
|
},
|
||||||
testRegion,
|
testRegion,
|
||||||
resourceModel{
|
resourceModel{
|
||||||
Id: types.Int64Value(1),
|
Id: types.Int64Value(1),
|
||||||
UserId: types.Int64Value(1),
|
UserId: types.Int64Value(1),
|
||||||
InstanceId: types.StringValue("iid"),
|
InstanceId: types.StringValue("iid"),
|
||||||
ProjectId: types.StringValue("pid"),
|
ProjectId: types.StringValue("pid"),
|
||||||
Name: types.StringNull(),
|
Name: types.StringNull(),
|
||||||
Roles: types.List(types.SetNull(types.StringType)),
|
Roles: types.List(types.SetNull(types.StringType)),
|
||||||
Region: types.StringValue(testRegion),
|
Region: types.StringValue(testRegion),
|
||||||
Status: types.StringNull(),
|
Status: types.StringNull(),
|
||||||
ConnectionString: types.StringNull(),
|
//ConnectionString: types.StringNull(),
|
||||||
},
|
},
|
||||||
true,
|
true,
|
||||||
},
|
},
|
||||||
|
|
|
||||||
|
|
@ -186,25 +186,25 @@ func (r *databaseResource) Create(ctx context.Context, req resource.CreateReques
|
||||||
payLoad.Name = data.Name.ValueStringPointer()
|
payLoad.Name = data.Name.ValueStringPointer()
|
||||||
payLoad.Owner = data.Owner.ValueStringPointer()
|
payLoad.Owner = data.Owner.ValueStringPointer()
|
||||||
|
|
||||||
_, err := wait.WaitForUserWaitHandler(
|
//_, err := wait.WaitForUserWaitHandler(
|
||||||
ctx,
|
// ctx,
|
||||||
r.client,
|
// r.client,
|
||||||
projectId,
|
// projectId,
|
||||||
instanceId,
|
// instanceId,
|
||||||
region,
|
// region,
|
||||||
data.Owner.ValueString(),
|
// data.Owner.ValueString(),
|
||||||
).
|
//).
|
||||||
SetSleepBeforeWait(10 * time.Second).
|
// SetSleepBeforeWait(10 * time.Second).
|
||||||
WaitWithContext(ctx)
|
// WaitWithContext(ctx)
|
||||||
if err != nil {
|
//if err != nil {
|
||||||
core.LogAndAddError(
|
// core.LogAndAddError(
|
||||||
ctx,
|
// ctx,
|
||||||
&resp.Diagnostics,
|
// &resp.Diagnostics,
|
||||||
createErr,
|
// createErr,
|
||||||
fmt.Sprintf("Calling API: %v", err),
|
// fmt.Sprintf("Calling API: %v", err),
|
||||||
)
|
// )
|
||||||
return
|
// return
|
||||||
}
|
//}
|
||||||
|
|
||||||
createResp, err := r.client.CreateDatabaseRequest(ctx, projectId, region, instanceId).
|
createResp, err := r.client.CreateDatabaseRequest(ctx, projectId, region, instanceId).
|
||||||
CreateDatabaseRequestPayload(payLoad).
|
CreateDatabaseRequestPayload(payLoad).
|
||||||
|
|
@ -361,15 +361,10 @@ func (r *databaseResource) Read(ctx context.Context, req resource.ReadRequest, r
|
||||||
|
|
||||||
ctx = core.InitProviderContext(ctx)
|
ctx = core.InitProviderContext(ctx)
|
||||||
|
|
||||||
projectId, region, instanceId, databaseName, errExt := r.extractIdentityData(model, identityData)
|
projectId := model.ProjectId.ValueString()
|
||||||
if errExt != nil {
|
region := model.Region.ValueString()
|
||||||
core.LogAndAddError(
|
instanceId := model.InstanceId.ValueString()
|
||||||
ctx,
|
databaseName := model.DatabaseName.ValueString()
|
||||||
&resp.Diagnostics,
|
|
||||||
extractErrorSummary,
|
|
||||||
fmt.Sprintf(extractErrorMessage, errExt),
|
|
||||||
)
|
|
||||||
}
|
|
||||||
|
|
||||||
ctx = tflog.SetField(ctx, "project_id", projectId)
|
ctx = tflog.SetField(ctx, "project_id", projectId)
|
||||||
ctx = tflog.SetField(ctx, "instance_id", instanceId)
|
ctx = tflog.SetField(ctx, "instance_id", instanceId)
|
||||||
|
|
@ -445,15 +440,10 @@ func (r *databaseResource) Delete(ctx context.Context, req resource.DeleteReques
|
||||||
|
|
||||||
ctx = core.InitProviderContext(ctx)
|
ctx = core.InitProviderContext(ctx)
|
||||||
|
|
||||||
projectId, region, instanceId, databaseName, errExt := r.extractIdentityData(model, identityData)
|
projectId := model.ProjectId.ValueString()
|
||||||
if errExt != nil {
|
region := model.Region.ValueString()
|
||||||
core.LogAndAddError(
|
instanceId := model.InstanceId.ValueString()
|
||||||
ctx,
|
databaseName := model.DatabaseName.ValueString()
|
||||||
&resp.Diagnostics,
|
|
||||||
extractErrorSummary,
|
|
||||||
fmt.Sprintf(extractErrorMessage, errExt),
|
|
||||||
)
|
|
||||||
}
|
|
||||||
|
|
||||||
ctx = tflog.SetField(ctx, "project_id", projectId)
|
ctx = tflog.SetField(ctx, "project_id", projectId)
|
||||||
ctx = tflog.SetField(ctx, "instance_id", instanceId)
|
ctx = tflog.SetField(ctx, "instance_id", instanceId)
|
||||||
|
|
@ -508,23 +498,6 @@ func (r *databaseResource) ModifyPlan(
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
var identityModel DatabaseResourceIdentityModel
|
|
||||||
identityModel.ProjectID = planModel.ProjectId
|
|
||||||
identityModel.Region = planModel.Region
|
|
||||||
|
|
||||||
if !planModel.InstanceId.IsNull() && !planModel.InstanceId.IsUnknown() {
|
|
||||||
identityModel.InstanceID = planModel.InstanceId
|
|
||||||
}
|
|
||||||
|
|
||||||
if !planModel.Name.IsNull() && !planModel.Name.IsUnknown() {
|
|
||||||
identityModel.DatabaseName = planModel.Name
|
|
||||||
}
|
|
||||||
|
|
||||||
resp.Diagnostics.Append(resp.Identity.Set(ctx, identityModel)...)
|
|
||||||
if resp.Diagnostics.HasError() {
|
|
||||||
return
|
|
||||||
}
|
|
||||||
|
|
||||||
resp.Diagnostics.Append(resp.Plan.Set(ctx, planModel)...)
|
resp.Diagnostics.Append(resp.Plan.Set(ctx, planModel)...)
|
||||||
if resp.Diagnostics.HasError() {
|
if resp.Diagnostics.HasError() {
|
||||||
return
|
return
|
||||||
|
|
@ -594,46 +567,3 @@ func (r *databaseResource) ImportState(
|
||||||
|
|
||||||
tflog.Info(ctx, "sqlserverflexalpha database state imported")
|
tflog.Info(ctx, "sqlserverflexalpha database state imported")
|
||||||
}
|
}
|
||||||
|
|
||||||
// extractIdentityData extracts essential identifiers from the resource model, falling back to the identity model.
|
|
||||||
func (r *databaseResource) extractIdentityData(
|
|
||||||
model resourceModel,
|
|
||||||
identity DatabaseResourceIdentityModel,
|
|
||||||
) (projectId, region, instanceId, databaseName string, err error) {
|
|
||||||
if !model.Name.IsNull() && !model.Name.IsUnknown() {
|
|
||||||
databaseName = model.Name.ValueString()
|
|
||||||
} else {
|
|
||||||
if identity.DatabaseName.IsNull() || identity.DatabaseName.IsUnknown() {
|
|
||||||
return "", "", "", "", fmt.Errorf("database_name not found in config")
|
|
||||||
}
|
|
||||||
databaseName = identity.DatabaseName.ValueString()
|
|
||||||
}
|
|
||||||
|
|
||||||
if !model.ProjectId.IsNull() && !model.ProjectId.IsUnknown() {
|
|
||||||
projectId = model.ProjectId.ValueString()
|
|
||||||
} else {
|
|
||||||
if identity.ProjectID.IsNull() || identity.ProjectID.IsUnknown() {
|
|
||||||
return "", "", "", "", fmt.Errorf("project_id not found in config")
|
|
||||||
}
|
|
||||||
projectId = identity.ProjectID.ValueString()
|
|
||||||
}
|
|
||||||
|
|
||||||
if !model.Region.IsNull() && !model.Region.IsUnknown() {
|
|
||||||
region = r.providerData.GetRegionWithOverride(model.Region)
|
|
||||||
} else {
|
|
||||||
if identity.Region.IsNull() || identity.Region.IsUnknown() {
|
|
||||||
return "", "", "", "", fmt.Errorf("region not found in config")
|
|
||||||
}
|
|
||||||
region = r.providerData.GetRegionWithOverride(identity.Region)
|
|
||||||
}
|
|
||||||
|
|
||||||
if !model.InstanceId.IsNull() && !model.InstanceId.IsUnknown() {
|
|
||||||
instanceId = model.InstanceId.ValueString()
|
|
||||||
} else {
|
|
||||||
if identity.InstanceID.IsNull() || identity.InstanceID.IsUnknown() {
|
|
||||||
return "", "", "", "", fmt.Errorf("instance_id not found in config")
|
|
||||||
}
|
|
||||||
instanceId = identity.InstanceID.ValueString()
|
|
||||||
}
|
|
||||||
return projectId, region, instanceId, databaseName, nil
|
|
||||||
}
|
|
||||||
|
|
|
||||||
|
|
@ -43,9 +43,12 @@ func TestMapDataSourceFields(t *testing.T) {
|
||||||
"simple_values",
|
"simple_values",
|
||||||
&sqlserverflexalpha.GetUserResponse{
|
&sqlserverflexalpha.GetUserResponse{
|
||||||
Roles: &[]string{
|
Roles: &[]string{
|
||||||
"role_1",
|
"##STACKIT_SQLAgentUser##",
|
||||||
"role_2",
|
"##STACKIT_DatabaseManager##",
|
||||||
"",
|
"##STACKIT_LoginManager##",
|
||||||
|
"##STACKIT_SQLAgentManager##",
|
||||||
|
"##STACKIT_ProcessManager##",
|
||||||
|
"##STACKIT_ServerManager##",
|
||||||
},
|
},
|
||||||
Username: utils.Ptr("username"),
|
Username: utils.Ptr("username"),
|
||||||
Host: utils.Ptr("host"),
|
Host: utils.Ptr("host"),
|
||||||
|
|
@ -63,9 +66,12 @@ func TestMapDataSourceFields(t *testing.T) {
|
||||||
Roles: types.List(
|
Roles: types.List(
|
||||||
types.SetValueMust(
|
types.SetValueMust(
|
||||||
types.StringType, []attr.Value{
|
types.StringType, []attr.Value{
|
||||||
types.StringValue(""),
|
types.StringValue("##STACKIT_DatabaseManager##"),
|
||||||
types.StringValue("role_1"),
|
types.StringValue("##STACKIT_LoginManager##"),
|
||||||
types.StringValue("role_2"),
|
types.StringValue("##STACKIT_ProcessManager##"),
|
||||||
|
types.StringValue("##STACKIT_SQLAgentManager##"),
|
||||||
|
types.StringValue("##STACKIT_SQLAgentUser##"),
|
||||||
|
types.StringValue("##STACKIT_ServerManager##"),
|
||||||
},
|
},
|
||||||
),
|
),
|
||||||
),
|
),
|
||||||
|
|
|
||||||
|
|
@ -2,7 +2,6 @@ package sqlserverflexbeta
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"fmt"
|
"fmt"
|
||||||
"strings"
|
|
||||||
|
|
||||||
"github.com/hashicorp/terraform-plugin-framework/types"
|
"github.com/hashicorp/terraform-plugin-framework/types"
|
||||||
|
|
||||||
|
|
@ -34,7 +33,7 @@ func mapFields(source *sqlserverflexbeta.GetDatabaseResponse, model *dataSourceM
|
||||||
model.Id = types.Int64Value(databaseId)
|
model.Id = types.Int64Value(databaseId)
|
||||||
model.DatabaseName = types.StringValue(source.GetName())
|
model.DatabaseName = types.StringValue(source.GetName())
|
||||||
model.Name = types.StringValue(source.GetName())
|
model.Name = types.StringValue(source.GetName())
|
||||||
model.Owner = types.StringValue(strings.Trim(source.GetOwner(), "\""))
|
model.Owner = types.StringValue(source.GetOwner())
|
||||||
model.Region = types.StringValue(region)
|
model.Region = types.StringValue(region)
|
||||||
model.ProjectId = types.StringValue(model.ProjectId.ValueString())
|
model.ProjectId = types.StringValue(model.ProjectId.ValueString())
|
||||||
model.InstanceId = types.StringValue(model.InstanceId.ValueString())
|
model.InstanceId = types.StringValue(model.InstanceId.ValueString())
|
||||||
|
|
@ -75,7 +74,7 @@ func mapResourceFields(source *sqlserverflexbeta.GetDatabaseResponse, model *res
|
||||||
model.Id = types.Int64Value(databaseId)
|
model.Id = types.Int64Value(databaseId)
|
||||||
model.DatabaseName = types.StringValue(source.GetName())
|
model.DatabaseName = types.StringValue(source.GetName())
|
||||||
model.Name = types.StringValue(source.GetName())
|
model.Name = types.StringValue(source.GetName())
|
||||||
model.Owner = types.StringValue(strings.Trim(source.GetOwner(), "\""))
|
model.Owner = types.StringValue(source.GetOwner())
|
||||||
model.Region = types.StringValue(region)
|
model.Region = types.StringValue(region)
|
||||||
model.ProjectId = types.StringValue(model.ProjectId.ValueString())
|
model.ProjectId = types.StringValue(model.ProjectId.ValueString())
|
||||||
model.InstanceId = types.StringValue(model.InstanceId.ValueString())
|
model.InstanceId = types.StringValue(model.InstanceId.ValueString())
|
||||||
|
|
|
||||||
|
|
@ -247,7 +247,6 @@ func (r *databaseResource) Create(ctx context.Context, req resource.CreateReques
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
// TODO: is this necessary to wait for the database-> API say 200 ?
|
|
||||||
waitResp, err := wait.CreateDatabaseWaitHandler(
|
waitResp, err := wait.CreateDatabaseWaitHandler(
|
||||||
ctx,
|
ctx,
|
||||||
r.client,
|
r.client,
|
||||||
|
|
@ -310,19 +309,8 @@ func (r *databaseResource) Create(ctx context.Context, req resource.CreateReques
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
database, err := r.client.GetDatabaseRequest(ctx, projectId, region, instanceId, databaseName).Execute()
|
|
||||||
if err != nil {
|
|
||||||
core.LogAndAddError(
|
|
||||||
ctx,
|
|
||||||
&resp.Diagnostics,
|
|
||||||
"Error creating database",
|
|
||||||
fmt.Sprintf("Getting database details after creation: %v", err),
|
|
||||||
)
|
|
||||||
return
|
|
||||||
}
|
|
||||||
|
|
||||||
// Map response body to schema
|
// Map response body to schema
|
||||||
err = mapResourceFields(database, &data, region)
|
err = mapResourceFields(waitResp, &data, region)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
core.LogAndAddError(
|
core.LogAndAddError(
|
||||||
ctx,
|
ctx,
|
||||||
|
|
@ -361,15 +349,10 @@ func (r *databaseResource) Read(ctx context.Context, req resource.ReadRequest, r
|
||||||
|
|
||||||
ctx = core.InitProviderContext(ctx)
|
ctx = core.InitProviderContext(ctx)
|
||||||
|
|
||||||
projectId, region, instanceId, databaseName, errExt := r.extractIdentityData(model, identityData)
|
projectId := model.ProjectId.ValueString()
|
||||||
if errExt != nil {
|
region := model.Region.ValueString()
|
||||||
core.LogAndAddError(
|
instanceId := model.InstanceId.ValueString()
|
||||||
ctx,
|
databaseName := model.DatabaseName.ValueString()
|
||||||
&resp.Diagnostics,
|
|
||||||
extractErrorSummary,
|
|
||||||
fmt.Sprintf(extractErrorMessage, errExt),
|
|
||||||
)
|
|
||||||
}
|
|
||||||
|
|
||||||
ctx = tflog.SetField(ctx, "project_id", projectId)
|
ctx = tflog.SetField(ctx, "project_id", projectId)
|
||||||
ctx = tflog.SetField(ctx, "instance_id", instanceId)
|
ctx = tflog.SetField(ctx, "instance_id", instanceId)
|
||||||
|
|
|
||||||
|
|
@ -302,9 +302,9 @@ func TestAccInstanceNoEncryption(t *testing.T) {
|
||||||
"##STACKIT_DatabaseManager##",
|
"##STACKIT_DatabaseManager##",
|
||||||
"##STACKIT_LoginManager##",
|
"##STACKIT_LoginManager##",
|
||||||
"##STACKIT_ProcessManager##",
|
"##STACKIT_ProcessManager##",
|
||||||
"##STACKIT_ServerManager##",
|
|
||||||
"##STACKIT_SQLAgentManager##",
|
"##STACKIT_SQLAgentManager##",
|
||||||
"##STACKIT_SQLAgentUser##",
|
"##STACKIT_SQLAgentUser##",
|
||||||
|
"##STACKIT_ServerManager##",
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
}
|
}
|
||||||
|
|
@ -402,7 +402,7 @@ func TestAccInstanceEncryption(t *testing.T) {
|
||||||
{
|
{
|
||||||
Name: userName,
|
Name: userName,
|
||||||
ProjectId: os.Getenv("TF_ACC_PROJECT_ID"),
|
ProjectId: os.Getenv("TF_ACC_PROJECT_ID"),
|
||||||
Roles: []string{"##STACKIT_LoginManager##", "##STACKIT_DatabaseManager##"},
|
Roles: []string{"##STACKIT_DatabaseManager##", "##STACKIT_LoginManager##"},
|
||||||
},
|
},
|
||||||
}
|
}
|
||||||
data.Databases = []Database{
|
data.Databases = []Database{
|
||||||
|
|
|
||||||
|
|
@ -94,8 +94,8 @@ func mapFields(userResp *sqlserverflexbeta.GetUserResponse, model *resourceModel
|
||||||
model.Username = types.StringPointerValue(user.Username)
|
model.Username = types.StringPointerValue(user.Username)
|
||||||
|
|
||||||
// Map roles
|
// Map roles
|
||||||
if user.Roles != nil {
|
if userResp.Roles != nil {
|
||||||
resRoles := *user.Roles
|
resRoles := *userResp.Roles
|
||||||
slices.Sort(resRoles)
|
slices.Sort(resRoles)
|
||||||
|
|
||||||
var roles []attr.Value
|
var roles []attr.Value
|
||||||
|
|
@ -103,11 +103,11 @@ func mapFields(userResp *sqlserverflexbeta.GetUserResponse, model *resourceModel
|
||||||
roles = append(roles, types.StringValue(string(role)))
|
roles = append(roles, types.StringValue(string(role)))
|
||||||
}
|
}
|
||||||
|
|
||||||
rolesSet, diags := types.SetValue(types.StringType, roles)
|
rolesSet, diags := types.ListValue(types.StringType, roles)
|
||||||
if diags.HasError() {
|
if diags.HasError() {
|
||||||
return fmt.Errorf("failed to map roles: %w", core.DiagsToError(diags))
|
return fmt.Errorf("failed to map roles: %w", core.DiagsToError(diags))
|
||||||
}
|
}
|
||||||
model.Roles = types.List(rolesSet)
|
model.Roles = rolesSet
|
||||||
}
|
}
|
||||||
|
|
||||||
// Ensure roles is not null
|
// Ensure roles is not null
|
||||||
|
|
@ -153,11 +153,11 @@ func mapFieldsCreate(userResp *sqlserverflexbeta.CreateUserResponse, model *reso
|
||||||
for _, role := range resRoles {
|
for _, role := range resRoles {
|
||||||
roles = append(roles, types.StringValue(string(role)))
|
roles = append(roles, types.StringValue(string(role)))
|
||||||
}
|
}
|
||||||
rolesSet, diags := types.SetValue(types.StringType, roles)
|
rolesList, diags := types.ListValue(types.StringType, roles)
|
||||||
if diags.HasError() {
|
if diags.HasError() {
|
||||||
return fmt.Errorf("failed to map roles: %w", core.DiagsToError(diags))
|
return fmt.Errorf("failed to map roles: %w", core.DiagsToError(diags))
|
||||||
}
|
}
|
||||||
model.Roles = types.List(rolesSet)
|
model.Roles = rolesList
|
||||||
}
|
}
|
||||||
|
|
||||||
if model.Roles.IsNull() || model.Roles.IsUnknown() {
|
if model.Roles.IsNull() || model.Roles.IsUnknown() {
|
||||||
|
|
|
||||||
|
|
@ -11,7 +11,6 @@ import (
|
||||||
"strings"
|
"strings"
|
||||||
"time"
|
"time"
|
||||||
|
|
||||||
"github.com/hashicorp/terraform-plugin-framework/attr"
|
|
||||||
"github.com/hashicorp/terraform-plugin-framework/path"
|
"github.com/hashicorp/terraform-plugin-framework/path"
|
||||||
"github.com/hashicorp/terraform-plugin-framework/resource"
|
"github.com/hashicorp/terraform-plugin-framework/resource"
|
||||||
"github.com/hashicorp/terraform-plugin-framework/resource/identityschema"
|
"github.com/hashicorp/terraform-plugin-framework/resource/identityschema"
|
||||||
|
|
@ -108,37 +107,25 @@ func (r *userResource) ModifyPlan(
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
// TODO: verify if this is needed - START
|
//// TODO: verify if this is needed - START
|
||||||
var configRoles []string
|
//var planRoles []string
|
||||||
diags := configModel.Roles.ElementsAs(ctx, &configRoles, false)
|
//diags := planModel.Roles.ElementsAs(ctx, &planRoles, false)
|
||||||
resp.Diagnostics.Append(diags...)
|
//resp.Diagnostics.Append(diags...)
|
||||||
if diags.HasError() {
|
//if diags.HasError() {
|
||||||
return
|
// return
|
||||||
}
|
//}
|
||||||
|
//slices.Sort(planRoles)
|
||||||
var planRoles []string
|
//var roles []attr.Value
|
||||||
diags = planModel.Roles.ElementsAs(ctx, &planRoles, false)
|
//for _, role := range planRoles {
|
||||||
resp.Diagnostics.Append(diags...)
|
// roles = append(roles, types.StringValue(string(role)))
|
||||||
if diags.HasError() {
|
//}
|
||||||
return
|
//rolesSet, diags := types.ListValue(types.StringType, roles)
|
||||||
}
|
//resp.Diagnostics.Append(diags...)
|
||||||
|
//if diags.HasError() {
|
||||||
slices.Sort(configRoles)
|
// return
|
||||||
slices.Sort(planRoles)
|
//}
|
||||||
|
//planModel.Roles = rolesSet
|
||||||
if !slices.Equal(configRoles, planRoles) {
|
//// TODO: verify if this is needed - END
|
||||||
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)...)
|
resp.Diagnostics.Append(resp.Plan.Set(ctx, planModel)...)
|
||||||
if resp.Diagnostics.HasError() {
|
if resp.Diagnostics.HasError() {
|
||||||
|
|
|
||||||
|
|
@ -489,17 +489,18 @@ func (p *Provider) Configure(ctx context.Context, req provider.ConfigureRequest,
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
roundTripper := core.NewRetryRoundTripper(
|
//roundTripper := core.NewRetryRoundTripper(
|
||||||
baseRoundTripper,
|
// baseRoundTripper,
|
||||||
maxRetries,
|
// maxRetries,
|
||||||
initialDelay,
|
// initialDelay,
|
||||||
maxDelay,
|
// maxDelay,
|
||||||
perTryTimeout,
|
// perTryTimeout,
|
||||||
)
|
//)
|
||||||
|
|
||||||
// Make round tripper and custom endpoints available during DataSource and Resource
|
// Make round tripper and custom endpoints available during DataSource and Resource
|
||||||
// type Configure methods.
|
// type Configure methods.
|
||||||
providerData.RoundTripper = roundTripper
|
// providerData.RoundTripper = roundTripper
|
||||||
|
providerData.RoundTripper = baseRoundTripper
|
||||||
resp.DataSourceData = providerData
|
resp.DataSourceData = providerData
|
||||||
resp.ResourceData = providerData
|
resp.ResourceData = providerData
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue