Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
17 changes: 12 additions & 5 deletions stackit/internal/services/secretsmanager/instance/resource.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,6 @@ import (
"github.com/stackitcloud/terraform-provider-stackit/stackit/internal/core"
"github.com/stackitcloud/terraform-provider-stackit/stackit/internal/validate"

"github.com/hashicorp/terraform-plugin-framework/path"
"github.com/hashicorp/terraform-plugin-framework/resource"
"github.com/hashicorp/terraform-plugin-framework/resource/schema"
"github.com/hashicorp/terraform-plugin-framework/resource/schema/planmodifier"
Expand Down Expand Up @@ -180,8 +179,15 @@ func (r *instanceResource) Create(ctx context.Context, req resource.CreateReques

ctx = core.LogResponse(ctx)

if createResp.Id == nil {
core.LogAndAddError(ctx, &resp.Diagnostics, "Error creating instance", "Got empty instance id")
return
}
instanceId := *createResp.Id
ctx = tflog.SetField(ctx, "instance_id", instanceId)
ctx = utils.SetAndLogStateFields(ctx, &resp.Diagnostics, &resp.State, map[string]any{
"project_id": projectId,
"instance_id": instanceId,
})

// Create ACLs
err = updateACLs(ctx, projectId, instanceId, acls, r.client)
Expand Down Expand Up @@ -364,9 +370,10 @@ func (r *instanceResource) ImportState(ctx context.Context, req resource.ImportS
)
return
}

resp.Diagnostics.Append(resp.State.SetAttribute(ctx, path.Root("project_id"), idParts[0])...)
resp.Diagnostics.Append(resp.State.SetAttribute(ctx, path.Root("instance_id"), idParts[1])...)
ctx = utils.SetAndLogStateFields(ctx, &resp.Diagnostics, &resp.State, map[string]any{
"project_id": idParts[0],
"instance_id": idParts[1],
})
tflog.Info(ctx, "Secrets Manager instance state imported")
}

Expand Down
16 changes: 10 additions & 6 deletions stackit/internal/services/secretsmanager/user/resource.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,6 @@ import (
"github.com/stackitcloud/terraform-provider-stackit/stackit/internal/core"
"github.com/stackitcloud/terraform-provider-stackit/stackit/internal/validate"

"github.com/hashicorp/terraform-plugin-framework/path"
"github.com/hashicorp/terraform-plugin-framework/resource"
"github.com/hashicorp/terraform-plugin-framework/resource/schema"
"github.com/hashicorp/terraform-plugin-framework/resource/schema/planmodifier"
Expand Down Expand Up @@ -191,7 +190,11 @@ func (r *userResource) Create(ctx context.Context, req resource.CreateRequest, r
return
}
userId := *userResp.Id
ctx = tflog.SetField(ctx, "user_id", userId)
ctx = utils.SetAndLogStateFields(ctx, &resp.Diagnostics, &resp.State, map[string]any{
"project_id": projectId,
"instance_id": instanceId,
"user_id": userId,
})

// Map response body to schema
err = mapFields(userResp, &model)
Expand Down Expand Up @@ -354,10 +357,11 @@ func (r *userResource) ImportState(ctx context.Context, req resource.ImportState
)
return
}

resp.Diagnostics.Append(resp.State.SetAttribute(ctx, path.Root("project_id"), idParts[0])...)
resp.Diagnostics.Append(resp.State.SetAttribute(ctx, path.Root("instance_id"), idParts[1])...)
resp.Diagnostics.Append(resp.State.SetAttribute(ctx, path.Root("user_id"), idParts[2])...)
ctx = utils.SetAndLogStateFields(ctx, &resp.Diagnostics, &resp.State, map[string]any{
"project_id": idParts[0],
"instance_id": idParts[1],
"user_id": idParts[2],
})
core.LogAndAddWarning(ctx, &resp.Diagnostics,
"Secrets Manager user imported with empty password",
"The user password is not imported as it is only available upon creation of a new user. The password field will be empty.",
Expand Down
Loading