CDN distribution: add string validator for backend type (#798)

* CDN distribution: add string validator for backend type

* Update stackit/internal/services/cdn/distribution/resource.go

Co-authored-by: Rüdiger Schmitz <ruediger.schmitz@inovex.de>

* fix suggestion apply

---------

Co-authored-by: Malte Ehrlen <malte.ehrlen@freiheit.com>
Co-authored-by: Rüdiger Schmitz <ruediger.schmitz@inovex.de>
This commit is contained in:
Malte Ehrlen 2025-04-30 14:33:25 +03:00 committed by GitHub
parent 30a01c3037
commit 89fa6e5777
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
4 changed files with 10 additions and 5 deletions

View file

@ -73,6 +73,7 @@ func (r *distributionDataSource) Metadata(_ context.Context, req datasource.Meta
}
func (r *distributionDataSource) Schema(_ context.Context, _ datasource.SchemaRequest, resp *datasource.SchemaResponse) {
backendOptions := []string{"http"}
resp.Schema = schema.Schema{
MarkdownDescription: features.AddBetaDescription("CDN distribution data source schema."),
Description: "CDN distribution data source schema.",
@ -147,7 +148,7 @@ func (r *distributionDataSource) Schema(_ context.Context, _ datasource.SchemaRe
Attributes: map[string]schema.Attribute{
"type": schema.StringAttribute{
Computed: true,
Description: schemaDescriptions["config_backend_type"],
Description: schemaDescriptions["config_backend_type"] + utils.SupportedValuesDocumentation(backendOptions),
},
"origin_url": schema.StringAttribute{
Computed: true,

View file

@ -8,6 +8,7 @@ import (
"strings"
"github.com/google/uuid"
"github.com/hashicorp/terraform-plugin-framework-validators/stringvalidator"
"github.com/hashicorp/terraform-plugin-framework/attr"
"github.com/hashicorp/terraform-plugin-framework/path"
"github.com/hashicorp/terraform-plugin-framework/resource"
@ -24,6 +25,7 @@ import (
"github.com/stackitcloud/stackit-sdk-go/services/cdn/wait"
"github.com/stackitcloud/terraform-provider-stackit/stackit/internal/core"
"github.com/stackitcloud/terraform-provider-stackit/stackit/internal/features"
"github.com/stackitcloud/terraform-provider-stackit/stackit/internal/utils"
"github.com/stackitcloud/terraform-provider-stackit/stackit/internal/validate"
)
@ -46,7 +48,7 @@ var schemaDescriptions = map[string]string{
"config": "The distribution configuration",
"config_backend": "The configured backend for the distribution",
"config_regions": "The configured regions where content will be hosted",
"config_backend_type": "The configured backend type",
"config_backend_type": "The configured backend type. ",
"config_backend_origin_url": "The configured backend type for the distribution",
"config_backend_origin_request_headers": "The configured origin request headers for the backend",
"domain_name": "The name of the domain",
@ -142,6 +144,7 @@ func (r *distributionResource) Metadata(_ context.Context, req resource.Metadata
}
func (r *distributionResource) Schema(_ context.Context, _ resource.SchemaRequest, resp *resource.SchemaResponse) {
backendOptions := []string{"http"}
resp.Schema = schema.Schema{
MarkdownDescription: features.AddBetaDescription("CDN distribution data source schema."),
Description: "CDN distribution data source schema.",
@ -218,7 +221,8 @@ func (r *distributionResource) Schema(_ context.Context, _ resource.SchemaReques
Attributes: map[string]schema.Attribute{
"type": schema.StringAttribute{
Required: true,
Description: schemaDescriptions["config_backend_type"],
Description: schemaDescriptions["config_backend_type"] + utils.SupportedValuesDocumentation(backendOptions),
Validators: []validator.String{stringvalidator.OneOf(backendOptions...)},
},
"origin_url": schema.StringAttribute{
Required: true,