From d01ae71b75e3b0e6fdd6bd10dcb0a904fbe8fc8e Mon Sep 17 00:00:00 2001 From: "Marcel S. Henselin" Date: Mon, 22 Dec 2025 10:56:04 +0100 Subject: [PATCH] fix: int64 user_id and some more --- pkg/sqlserverflexalpha/wait/wait.go | 4 ++- sample/main.tf | 13 ++++--- sample/postresql.tf | 8 ----- sample/user.tf | 24 ++++++++----- .../postgresflexalpha/instance/resource.go | 4 +++ .../postgresflexalpha/user/resource.go | 11 +++--- .../sqlserverflexalpha/instance/datasource.go | 34 +++++++++++++------ .../sqlserverflexalpha/user/resource.go | 11 +++--- 8 files changed, 65 insertions(+), 44 deletions(-) diff --git a/pkg/sqlserverflexalpha/wait/wait.go b/pkg/sqlserverflexalpha/wait/wait.go index 73bd9767..c9a3e2e4 100644 --- a/pkg/sqlserverflexalpha/wait/wait.go +++ b/pkg/sqlserverflexalpha/wait/wait.go @@ -40,6 +40,8 @@ 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 return true, s, nil case strings.ToLower(InstanceStateUnknown), strings.ToLower(InstanceStateFailed): return true, s, fmt.Errorf("create failed for instance with id %s", instanceId) @@ -48,7 +50,7 @@ func CreateInstanceWaitHandler(ctx context.Context, a APIClientInstanceInterface } }) handler.SetTimeout(45 * time.Minute) - handler.SetSleepBeforeWait(5 * time.Second) + handler.SetSleepBeforeWait(15 * time.Second) return handler } diff --git a/sample/main.tf b/sample/main.tf index 570cfd6f..64cbbe25 100644 --- a/sample/main.tf +++ b/sample/main.tf @@ -1,8 +1,11 @@ # see other files -resource "stackit_sqlserverflexalpha_user" "ptlsdbuser" { - project_id = stackitalpha_postgresflexalpha_instance.ptlsdbsrv.project_id - instance_id = stackitalpha_postgresflexalpha_instance.ptlsdbsrv.id - username = var.db_username - roles = ["login"] +data "stackitprivatepreview_sqlserverflexalpha_instance" "existing" { + project_id = var.project_id + instance_id = "b31575e9-9dbd-4ff6-b341-82d89c34f14f" + region = "eu01" +} + +output "myinstance" { + value = data.stackitprivatepreview_sqlserverflexalpha_instance.existing } diff --git a/sample/postresql.tf b/sample/postresql.tf index b849bfad..7295f6f2 100644 --- a/sample/postresql.tf +++ b/sample/postresql.tf @@ -26,11 +26,3 @@ resource "stackitprivatepreview_postgresflexalpha_instance" "ptlsdbsrv" { } version = 14 } - - -resource "stackitprivatepreview_sqlserverflexalpha_user" "ptlsdbuser" { - project_id = stackitprivatepreview_postgresflexalpha_instance.ptlsdbsrv.project_id - instance_id = stackitprivatepreview_postgresflexalpha_instance.ptlsdbsrv.id - username = var.db_username - roles = ["createdb", "login", "createrole"] -} diff --git a/sample/user.tf b/sample/user.tf index fe7698f6..2ebbb040 100644 --- a/sample/user.tf +++ b/sample/user.tf @@ -1,12 +1,20 @@ -data "stackit_postgresflexalpha_user" "example" { - project_id = stackitalpha_postgresflexalpha_instance.ptlsdbsrv.project_id - instance_id = stackitalpha_postgresflexalpha_instance.ptlsdbsrv.id +data "stackitprivatepreview_postgresflexalpha_user" "example" { + project_id = stackitprivatepreview_postgresflexalpha_instance.ptlsdbsrv.project_id + instance_id = stackitprivatepreview_postgresflexalpha_instance.ptlsdbsrv.id user_id = 1 } -resource "stackit_sqlserverflexalpha_user" "ptlsdbuser" { - project_id = stackitalpha_postgresflexalpha_instance.ptlsdbsrv.project_id - instance_id = stackitalpha_postgresflexalpha_instance.ptlsdbsrv.id +resource "stackitprivatepreview_postgresflexalpha_user" "ptlsdbuser" { + project_id = stackitprivatepreview_postgresflexalpha_instance.ptlsdbsrv.project_id + instance_id = stackitprivatepreview_postgresflexalpha_instance.ptlsdbsrv.id username = var.db_username - roles = ["createdb", "login", "createrole"] -} \ No newline at end of file + # roles = ["createdb", "login", "createrole"] + roles = ["createdb", "login"] +} + +resource "stackitprivatepreview_sqlserverflexalpha_user" "ptlsdbuser" { + project_id = stackitprivatepreview_sqlserverflexalpha_instance.ptlsdbsqlsrv.project_id + instance_id = stackitprivatepreview_sqlserverflexalpha_instance.ptlsdbsqlsrv.id + username = var.db_username + roles = ["login"] +} diff --git a/stackit/internal/services/postgresflexalpha/instance/resource.go b/stackit/internal/services/postgresflexalpha/instance/resource.go index 2f6b6594..fd42787a 100644 --- a/stackit/internal/services/postgresflexalpha/instance/resource.go +++ b/stackit/internal/services/postgresflexalpha/instance/resource.go @@ -278,6 +278,10 @@ func (r *instanceResource) Schema(_ context.Context, req resource.SchemaRequest, }, "size": schema.Int64Attribute{ Required: true, + //PlanModifiers: []planmodifier.Int64{ + // TODO - req replace if new size smaller than state size + // int64planmodifier.RequiresReplaceIf(), + //}, }, }, }, diff --git a/stackit/internal/services/postgresflexalpha/user/resource.go b/stackit/internal/services/postgresflexalpha/user/resource.go index 15882af2..ad90b81e 100644 --- a/stackit/internal/services/postgresflexalpha/user/resource.go +++ b/stackit/internal/services/postgresflexalpha/user/resource.go @@ -7,6 +7,7 @@ import ( "strconv" "strings" + "github.com/hashicorp/terraform-plugin-framework/resource/schema/int64planmodifier" "github.com/mhenselin/terraform-provider-stackitprivatepreview/pkg/postgresflexalpha/wait" postgresflexUtils "github.com/mhenselin/terraform-provider-stackitprivatepreview/stackit/internal/services/postgresflexalpha/utils" @@ -147,15 +148,13 @@ func (r *userResource) Schema(_ context.Context, _ resource.SchemaRequest, resp stringplanmodifier.UseStateForUnknown(), }, }, - "user_id": schema.StringAttribute{ + "user_id": schema.Int64Attribute{ Description: descriptions["user_id"], Computed: true, - PlanModifiers: []planmodifier.String{ - stringplanmodifier.UseStateForUnknown(), - }, - Validators: []validator.String{ - validate.NoSeparator(), + PlanModifiers: []planmodifier.Int64{ + int64planmodifier.UseStateForUnknown(), }, + Validators: []validator.Int64{}, }, "instance_id": schema.StringAttribute{ Description: descriptions["instance_id"], diff --git a/stackit/internal/services/sqlserverflexalpha/instance/datasource.go b/stackit/internal/services/sqlserverflexalpha/instance/datasource.go index be17d464..871529e5 100644 --- a/stackit/internal/services/sqlserverflexalpha/instance/datasource.go +++ b/stackit/internal/services/sqlserverflexalpha/instance/datasource.go @@ -64,16 +64,23 @@ func (r *instanceDataSource) Configure(ctx context.Context, req datasource.Confi // Schema defines the schema for the data source. func (r *instanceDataSource) Schema(_ context.Context, _ datasource.SchemaRequest, resp *datasource.SchemaResponse) { descriptions := map[string]string{ - "main": "SQLServer Flex instance data source schema. Must have a `region` specified in the provider configuration.", - "id": "Terraform's internal data source. ID. It is structured as \"`project_id`,`region`,`instance_id`\".", - "instance_id": "ID of the SQLServer Flex instance.", - "project_id": "STACKIT project ID to which the instance is associated.", - "name": "Instance name.", - "acl": "The Access Control List (ACL) for the SQLServer Flex instance.", - "backup_schedule": `The backup schedule. Should follow the cron scheduling system format (e.g. "0 0 * * *").`, - "options": "Custom parameters for the SQLServer Flex instance.", - "region": "The resource region. If not defined, the provider region is used.", - // TODO @mhenselin + "main": "SQLServer Flex ALPHA instance resource schema. Must have a `region` specified in the provider configuration.", + "id": "Terraform's internal resource ID. It is structured as \"`project_id`,`region`,`instance_id`\".", + "instance_id": "ID of the SQLServer Flex instance.", + "project_id": "STACKIT project ID to which the instance is associated.", + "name": "Instance name.", + "access_scope": "The access scope of the instance. (e.g. SNA)", + "acl": "The Access Control List (ACL) for the SQLServer Flex instance.", + "backup_schedule": `The backup schedule. Should follow the cron scheduling system format (e.g. "0 0 * * *")`, + "region": "The resource region. If not defined, the provider region is used.", + "encryption": "The encryption block.", + "network": "The network block.", + "keyring_id": "STACKIT KMS - KeyRing ID of the encryption key to use.", + "key_id": "STACKIT KMS - Key ID of the encryption key to use.", + "key_version": "STACKIT KMS - Key version to use in the encryption key.", + "service:account": "STACKIT KMS - service account to use in the encryption key.", + "instance_address": "The returned instance IP address of the SQLServer Flex instance.", + "router_address": "The returned router IP address of the SQLServer Flex instance.", } resp.Schema = schema.Schema{ @@ -107,6 +114,10 @@ func (r *instanceDataSource) Schema(_ context.Context, _ datasource.SchemaReques Description: descriptions["backup_schedule"], Computed: true, }, + "is_deletable": schema.BoolAttribute{ + Description: descriptions["is_deletable"], + Computed: true, + }, "flavor": schema.SingleNestedAttribute{ Computed: true, Attributes: map[string]schema.Attribute{ @@ -122,6 +133,9 @@ func (r *instanceDataSource) Schema(_ context.Context, _ datasource.SchemaReques "ram": schema.Int64Attribute{ Computed: true, }, + "node_type": schema.StringAttribute{ + Computed: true, + }, }, }, "replicas": schema.Int64Attribute{ diff --git a/stackit/internal/services/sqlserverflexalpha/user/resource.go b/stackit/internal/services/sqlserverflexalpha/user/resource.go index 1f0702c6..ec049e50 100644 --- a/stackit/internal/services/sqlserverflexalpha/user/resource.go +++ b/stackit/internal/services/sqlserverflexalpha/user/resource.go @@ -8,6 +8,7 @@ import ( "strconv" "strings" + "github.com/hashicorp/terraform-plugin-framework/resource/schema/int64planmodifier" "github.com/mhenselin/terraform-provider-stackitprivatepreview/pkg/sqlserverflexalpha" sqlserverflexalphaUtils "github.com/mhenselin/terraform-provider-stackitprivatepreview/stackit/internal/services/sqlserverflexalpha/utils" @@ -143,15 +144,13 @@ func (r *userResource) Schema(_ context.Context, _ resource.SchemaRequest, resp stringplanmodifier.UseStateForUnknown(), }, }, - "user_id": schema.StringAttribute{ + "user_id": schema.Int64Attribute{ Description: descriptions["user_id"], Computed: true, - PlanModifiers: []planmodifier.String{ - stringplanmodifier.UseStateForUnknown(), - }, - Validators: []validator.String{ - validate.NoSeparator(), + PlanModifiers: []planmodifier.Int64{ + int64planmodifier.UseStateForUnknown(), }, + Validators: []validator.Int64{}, }, "instance_id": schema.StringAttribute{ Description: descriptions["instance_id"],