Skip to content

Commit 89fa6e5

Browse files
malteehrlenmalte-ehrlenbahkauv70
authored
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>
1 parent 30a01c3 commit 89fa6e5

4 files changed

Lines changed: 10 additions & 5 deletions

File tree

docs/data-sources/cdn_distribution.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -55,7 +55,7 @@ Read-Only:
5555

5656
- `origin_request_headers` (Map of String) The configured origin request headers for the backend
5757
- `origin_url` (String) The configured backend type for the distribution
58-
- `type` (String) The configured backend type
58+
- `type` (String) The configured backend type. Supported values are: `http`.
5959

6060

6161

docs/resources/cdn_distribution.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -61,7 +61,7 @@ Required:
6161
Required:
6262

6363
- `origin_url` (String) The configured backend type for the distribution
64-
- `type` (String) The configured backend type
64+
- `type` (String) The configured backend type. Supported values are: `http`.
6565

6666
Optional:
6767

stackit/internal/services/cdn/distribution/datasource.go

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -73,6 +73,7 @@ func (r *distributionDataSource) Metadata(_ context.Context, req datasource.Meta
7373
}
7474

7575
func (r *distributionDataSource) Schema(_ context.Context, _ datasource.SchemaRequest, resp *datasource.SchemaResponse) {
76+
backendOptions := []string{"http"}
7677
resp.Schema = schema.Schema{
7778
MarkdownDescription: features.AddBetaDescription("CDN distribution data source schema."),
7879
Description: "CDN distribution data source schema.",
@@ -147,7 +148,7 @@ func (r *distributionDataSource) Schema(_ context.Context, _ datasource.SchemaRe
147148
Attributes: map[string]schema.Attribute{
148149
"type": schema.StringAttribute{
149150
Computed: true,
150-
Description: schemaDescriptions["config_backend_type"],
151+
Description: schemaDescriptions["config_backend_type"] + utils.SupportedValuesDocumentation(backendOptions),
151152
},
152153
"origin_url": schema.StringAttribute{
153154
Computed: true,

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

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ import (
88
"strings"
99

1010
"github.com/google/uuid"
11+
"github.com/hashicorp/terraform-plugin-framework-validators/stringvalidator"
1112
"github.com/hashicorp/terraform-plugin-framework/attr"
1213
"github.com/hashicorp/terraform-plugin-framework/path"
1314
"github.com/hashicorp/terraform-plugin-framework/resource"
@@ -24,6 +25,7 @@ import (
2425
"github.com/stackitcloud/stackit-sdk-go/services/cdn/wait"
2526
"github.com/stackitcloud/terraform-provider-stackit/stackit/internal/core"
2627
"github.com/stackitcloud/terraform-provider-stackit/stackit/internal/features"
28+
"github.com/stackitcloud/terraform-provider-stackit/stackit/internal/utils"
2729
"github.com/stackitcloud/terraform-provider-stackit/stackit/internal/validate"
2830
)
2931

@@ -46,7 +48,7 @@ var schemaDescriptions = map[string]string{
4648
"config": "The distribution configuration",
4749
"config_backend": "The configured backend for the distribution",
4850
"config_regions": "The configured regions where content will be hosted",
49-
"config_backend_type": "The configured backend type",
51+
"config_backend_type": "The configured backend type. ",
5052
"config_backend_origin_url": "The configured backend type for the distribution",
5153
"config_backend_origin_request_headers": "The configured origin request headers for the backend",
5254
"domain_name": "The name of the domain",
@@ -142,6 +144,7 @@ func (r *distributionResource) Metadata(_ context.Context, req resource.Metadata
142144
}
143145

144146
func (r *distributionResource) Schema(_ context.Context, _ resource.SchemaRequest, resp *resource.SchemaResponse) {
147+
backendOptions := []string{"http"}
145148
resp.Schema = schema.Schema{
146149
MarkdownDescription: features.AddBetaDescription("CDN distribution data source schema."),
147150
Description: "CDN distribution data source schema.",
@@ -218,7 +221,8 @@ func (r *distributionResource) Schema(_ context.Context, _ resource.SchemaReques
218221
Attributes: map[string]schema.Attribute{
219222
"type": schema.StringAttribute{
220223
Required: true,
221-
Description: schemaDescriptions["config_backend_type"],
224+
Description: schemaDescriptions["config_backend_type"] + utils.SupportedValuesDocumentation(backendOptions),
225+
Validators: []validator.String{stringvalidator.OneOf(backendOptions...)},
222226
},
223227
"origin_url": schema.StringAttribute{
224228
Required: true,

0 commit comments

Comments
 (0)