diff --git a/pkg/postgresflexalpha/wait/wait.go b/pkg/postgresflexalpha/wait/wait.go index a858e99c..e6b0fd51 100644 --- a/pkg/postgresflexalpha/wait/wait.go +++ b/pkg/postgresflexalpha/wait/wait.go @@ -7,6 +7,7 @@ import ( "fmt" "time" + "github.com/hashicorp/terraform-plugin-log/tflog" postgresflex "github.com/mhenselin/terraform-provider-stackitprivatepreview/pkg/postgresflexalpha" "github.com/stackitcloud/stackit-sdk-go/core/oapierror" @@ -68,6 +69,14 @@ func CreateInstanceWaitHandler( case InstanceStateProgressing: return false, nil, nil case InstanceStateSuccess: + if s.Network.InstanceAddress == nil { + tflog.Info(ctx, "Waiting for instance_address") + return false, nil, nil + } + if s.Network.RouterAddress == nil { + tflog.Info(ctx, "Waiting for router_address") + return false, nil, nil + } instanceCreated = true instanceGetResponse = s case InstanceStateFailed: diff --git a/pkg/sqlserverflexalpha/wait/wait.go b/pkg/sqlserverflexalpha/wait/wait.go index c9a3e2e4..7f2a4f02 100644 --- a/pkg/sqlserverflexalpha/wait/wait.go +++ b/pkg/sqlserverflexalpha/wait/wait.go @@ -10,6 +10,7 @@ import ( "strings" "time" + "github.com/hashicorp/terraform-plugin-log/tflog" sqlserverflex "github.com/mhenselin/terraform-provider-stackitprivatepreview/pkg/sqlserverflexalpha" "github.com/stackitcloud/stackit-sdk-go/core/oapierror" "github.com/stackitcloud/stackit-sdk-go/core/wait" @@ -40,8 +41,14 @@ func CreateInstanceWaitHandler(ctx context.Context, a APIClientInstanceInterface } switch strings.ToLower(string(*s.Status)) { case strings.ToLower(InstanceStateSuccess): - // if no instance address - return false - // if no router address - return false + if s.Network.InstanceAddress == nil { + tflog.Info(ctx, "Waiting for instance_address") + return false, nil, nil + } + if s.Network.RouterAddress == nil { + tflog.Info(ctx, "Waiting for router_address") + return false, nil, nil + } return true, s, nil case strings.ToLower(InstanceStateUnknown), strings.ToLower(InstanceStateFailed): return true, s, fmt.Errorf("create failed for instance with id %s", instanceId) diff --git a/sample/postresql.tf b/sample/postresql.tf index 7295f6f2..c337e594 100644 --- a/sample/postresql.tf +++ b/sample/postresql.tf @@ -26,3 +26,13 @@ resource "stackitprivatepreview_postgresflexalpha_instance" "ptlsdbsrv" { } version = 14 } + +data "stackitprivatepreview_postgresflexalpha_instance" "datapsql" { + project_id = var.project_id + instance_id = "e0c028e0-a201-4b75-8ee5-50a0ad17b0d7" + region = "eu01" +} + +output "sample_psqlinstance" { + value = data.stackitprivatepreview_postgresflexalpha_instance.datapsql +} diff --git a/stackit/internal/services/postgresflexalpha/instance/datasource.go.bak b/stackit/internal/services/postgresflexalpha/instance/datasource.go similarity index 80% rename from stackit/internal/services/postgresflexalpha/instance/datasource.go.bak rename to stackit/internal/services/postgresflexalpha/instance/datasource.go index 874e2999..aa54f7eb 100644 --- a/stackit/internal/services/postgresflexalpha/instance/datasource.go.bak +++ b/stackit/internal/services/postgresflexalpha/instance/datasource.go @@ -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 diff --git a/stackit/internal/services/postgresflexalpha/instance/resource.go b/stackit/internal/services/postgresflexalpha/instance/resource.go index fd42787a..38834766 100644 --- a/stackit/internal/services/postgresflexalpha/instance/resource.go +++ b/stackit/internal/services/postgresflexalpha/instance/resource.go @@ -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{}, }, diff --git a/stackit/provider.go b/stackit/provider.go index 62ddf866..9a891519 100644 --- a/stackit/provider.go +++ b/stackit/provider.go @@ -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,