fix: add psql datasource

This commit is contained in:
Marcel_Henselin 2025-12-22 11:17:38 +01:00
parent d01ae71b75
commit b08b32ef1d
6 changed files with 109 additions and 13 deletions

View file

@ -1,4 +1,4 @@
package postgresflexa
package postgresflexalpha
import (
"context"
@ -145,6 +145,51 @@ func (r *instanceDataSource) Schema(_ context.Context, _ datasource.SchemaReques
Optional: true,
Description: descriptions["region"],
},
"encryption": schema.SingleNestedAttribute{
Required: true,
Attributes: map[string]schema.Attribute{
"key_id": schema.StringAttribute{
Description: descriptions["key_id"],
Computed: true,
},
"key_version": schema.StringAttribute{
Description: descriptions["key_version"],
Computed: true,
},
"keyring_id": schema.StringAttribute{
Description: descriptions["keyring_id"],
Computed: true,
},
"service_account": schema.StringAttribute{
Description: descriptions["service_account"],
Computed: true,
},
},
Description: descriptions["encryption"],
},
"network": schema.SingleNestedAttribute{
Computed: true,
Attributes: map[string]schema.Attribute{
"access_scope": schema.StringAttribute{
Description: descriptions["access_scope"],
Computed: true,
},
"acl": schema.ListAttribute{
Description: descriptions["acl"],
ElementType: types.StringType,
Computed: true,
},
"instance_address": schema.StringAttribute{
Description: descriptions["instance_address"],
Computed: true,
},
"router_address": schema.StringAttribute{
Description: descriptions["router_address"],
Computed: true,
},
},
Description: descriptions["network"],
},
},
}
}
@ -207,7 +252,16 @@ func (r *instanceDataSource) Read(ctx context.Context, req datasource.ReadReques
}
}
err = mapFields(ctx, instanceResp, &model, flavor, storage, region)
var network = &networkModel{}
if !(model.Network.IsNull() || model.Network.IsUnknown()) {
diags = model.Network.As(ctx, network, basetypes.ObjectAsOptions{})
resp.Diagnostics.Append(diags...)
if resp.Diagnostics.HasError() {
return
}
}
err = mapFields(ctx, instanceResp, &model, flavor, storage, network, region)
if err != nil {
core.LogAndAddError(ctx, &resp.Diagnostics, "Error reading instance", fmt.Sprintf("Processing API payload: %v", err))
return

View file

@ -8,6 +8,7 @@ import (
"strings"
"time"
"github.com/hashicorp/terraform-plugin-framework/resource/schema/listplanmodifier"
//postgresflex "github.com/mhenselin/terraform-provider-stackitprivatepreview/pkg/postgresflexalpha"
postgresflex "github.com/mhenselin/terraform-provider-stackitprivatepreview/pkg/postgresflexalpha"
"github.com/mhenselin/terraform-provider-stackitprivatepreview/pkg/postgresflexalpha/wait"
@ -341,11 +342,7 @@ func (r *instanceResource) Schema(_ context.Context, req resource.SchemaRequest,
},
},
},
//Blocks: nil,
//CustomType: nil,
Description: descriptions["encryption"],
//MarkdownDescription: "",
//DeprecationMessage: "",
//Validators: nil,
PlanModifiers: []planmodifier.Object{},
},
@ -357,17 +354,37 @@ func (r *instanceResource) Schema(_ context.Context, req resource.SchemaRequest,
Required: true,
PlanModifiers: []planmodifier.String{
stringplanmodifier.RequiresReplace(),
stringplanmodifier.UseStateForUnknown(),
},
Validators: []validator.String{
validate.NoSeparator(),
},
},
"acl": schema.ListAttribute{
Description: descriptions["acl"],
ElementType: types.StringType,
Required: true,
PlanModifiers: []planmodifier.List{
listplanmodifier.UseStateForUnknown(),
},
},
"instance_address": schema.StringAttribute{
Description: descriptions["instance_address"],
Computed: true,
PlanModifiers: []planmodifier.String{
stringplanmodifier.UseStateForUnknown(),
},
},
"router_address": schema.StringAttribute{
Description: descriptions["router_address"],
Computed: true,
PlanModifiers: []planmodifier.String{
stringplanmodifier.UseStateForUnknown(),
},
},
},
//Blocks: nil,
//CustomType: nil,
Description: descriptions["network"],
//MarkdownDescription: "",
//DeprecationMessage: "",
//Validators: nil,
PlanModifiers: []planmodifier.Object{},
},

View file

@ -486,8 +486,7 @@ func (p *Provider) Configure(ctx context.Context, req provider.ConfigureRequest,
// DataSources defines the data sources implemented in the provider.
func (p *Provider) DataSources(_ context.Context) []func() datasource.DataSource {
return []func() datasource.DataSource{
// TODO @mhenselin
// postgresFlexAlphaInstance.NewInstanceDataSource(),
postgresFlexAlphaInstance.NewInstanceDataSource,
postgresFlexAlphaUser.NewUserDataSource,
sqlServerFlexAlphaInstance.NewInstanceDataSource,
sqlserverFlexAlphaUser.NewUserDataSource,