feat: add validation for project_id and instance_id attributes in datasource schema

This commit is contained in:
Andre_Harms 2026-02-05 23:29:34 +01:00
parent a46e26b69b
commit 5ec7e54d41

View file

@ -7,10 +7,12 @@ import (
"github.com/hashicorp/terraform-plugin-framework/datasource/schema"
"github.com/hashicorp/terraform-plugin-framework/diag"
"github.com/hashicorp/terraform-plugin-framework/schema/validator"
"github.com/hashicorp/terraform-plugin-framework/types"
"tf-provider.git.onstackit.cloud/stackit-dev-tools/terraform-provider-stackitprivatepreview/stackit/internal/conversion"
postgresflexalpha2 "tf-provider.git.onstackit.cloud/stackit-dev-tools/terraform-provider-stackitprivatepreview/stackit/internal/services/postgresflexalpha/database/datasources_gen"
postgresflexUtils "tf-provider.git.onstackit.cloud/stackit-dev-tools/terraform-provider-stackitprivatepreview/stackit/internal/services/postgresflexalpha/utils"
"tf-provider.git.onstackit.cloud/stackit-dev-tools/terraform-provider-stackitprivatepreview/stackit/internal/validate"
"github.com/hashicorp/terraform-plugin-framework/datasource"
"github.com/hashicorp/terraform-plugin-log/tflog"
@ -83,11 +85,19 @@ func (r *databaseDataSource) Schema(ctx context.Context, _ datasource.SchemaRequ
Description: "STACKIT project ID to which the instance is associated.",
MarkdownDescription: "STACKIT project ID to which the instance is associated.",
Required: true,
Validators: []validator.String{
validate.UUID(),
validate.NoSeparator(),
},
}
s.Attributes["instance_id"] = schema.StringAttribute{
Description: "ID of the PostgresFlex instance.",
MarkdownDescription: "ID of the PostgresFlex instance.",
Required: true,
Validators: []validator.String{
validate.UUID(),
validate.NoSeparator(),
},
}
s.Attributes["region"] = schema.StringAttribute{
Description: "Region of the PostgresFlex instance.",
@ -96,13 +106,11 @@ func (r *databaseDataSource) Schema(ctx context.Context, _ datasource.SchemaRequ
}
s.Attributes["database_id"] = schema.Int64Attribute{
Description: "The ID of the database.",
Optional: true,
Computed: true,
Required: true,
}
s.Attributes["id"] = schema.StringAttribute{
Description: "Terraform's internal resource ID. It is structured as \\\"`project_id`,`region`,`instance_id`," +
"`database_id`\\\".\",",
Optional: true,
Computed: true,
}