Skip to content

Commit 3fb28d1

Browse files
authored
Document possible values of schema fields (#455)
* Document possible values of schema fields * Change from possible to supported
1 parent 846a2ba commit 3fb28d1

10 files changed

Lines changed: 76 additions & 15 deletions

File tree

docs/resources/dns_zone.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,7 @@ resource "stackit_dns_zone" "example" {
4747
- `primaries` (List of String) Primary name server for secondary zone. E.g. ["1.2.3.4"]
4848
- `refresh_time` (Number) Refresh time. E.g. 3600
4949
- `retry_time` (Number) Retry time. E.g. 600
50-
- `type` (String) Zone type. Defaults to `primary`
50+
- `type` (String) Zone type. Defaults to `primary`. Supported values are: `primary`, `secondary`.
5151

5252
### Read-Only
5353

docs/resources/loadbalancer.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -203,7 +203,7 @@ Optional:
203203

204204
- `display_name` (String)
205205
- `port` (Number) Port number where we listen for traffic.
206-
- `protocol` (String) Protocol is the highest network protocol we understand to load balance.
206+
- `protocol` (String) Protocol is the highest network protocol we understand to load balance. Supported values are: `PROTOCOL_UNSPECIFIED`, `PROTOCOL_TCP`, `PROTOCOL_UDP`, `PROTOCOL_TCP_PROXY`, `PROTOCOL_TLS_PASSTHROUGH`.
207207
- `server_name_indicators` (Attributes List) A list of domain names to match in order to pass TLS traffic to the target pool in the current listener (see [below for nested schema](#nestedatt--listeners--server_name_indicators))
208208
- `target_pool` (String) Reference target pool by target pool name.
209209

@@ -225,7 +225,7 @@ Required:
225225

226226
Optional:
227227

228-
- `role` (String) The role defines how the load balancer is using the network.
228+
- `role` (String) The role defines how the load balancer is using the network. Supported values are: `ROLE_UNSPECIFIED`, `ROLE_LISTENERS_AND_TARGETS`, `ROLE_LISTENERS`, `ROLE_TARGETS`.
229229

230230

231231
<a id="nestedatt--target_pools"></a>

docs/resources/mongodbflex_user.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@ resource "stackit_mongodbflex_user" "example" {
3030
- `database` (String)
3131
- `instance_id` (String) ID of the MongoDB Flex instance.
3232
- `project_id` (String) STACKIT project ID to which the instance is associated.
33-
- `roles` (Set of String) Database access levels for the user.
33+
- `roles` (Set of String) Database access levels for the user. Supported values are: `read`, `readWrite`.
3434

3535
### Optional
3636

docs/resources/postgresflex_user.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@ resource "stackit_postgresflex_user" "example" {
2828

2929
- `instance_id` (String) ID of the PostgresFlex instance.
3030
- `project_id` (String) STACKIT project ID to which the instance is associated.
31-
- `roles` (Set of String)
31+
- `roles` (Set of String) Database access levels for the user. Supported values are: `login`, `createdb`.
3232
- `username` (String)
3333

3434
### Read-Only

stackit/internal/services/dns/zone/resource.go

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -114,6 +114,8 @@ func (r *zoneResource) Configure(ctx context.Context, req resource.ConfigureRequ
114114

115115
// Schema defines the schema for the resource.
116116
func (r *zoneResource) Schema(_ context.Context, _ resource.SchemaRequest, resp *resource.SchemaResponse) {
117+
primaryOptions := []string{"primary", "secondary"}
118+
117119
resp.Schema = schema.Schema{
118120
Description: "DNS Zone resource schema.",
119121
Attributes: map[string]schema.Attribute{
@@ -254,12 +256,12 @@ func (r *zoneResource) Schema(_ context.Context, _ resource.SchemaRequest, resp
254256
},
255257
},
256258
"type": schema.StringAttribute{
257-
Description: "Zone type. Defaults to `primary`",
259+
Description: "Zone type. Defaults to `primary`. " + utils.SupportedValuesDocumentation(primaryOptions),
258260
Optional: true,
259261
Computed: true,
260262
Default: stringdefault.StaticString("primary"),
261263
Validators: []validator.String{
262-
stringvalidator.OneOf("primary", "secondary"),
264+
stringvalidator.OneOf(primaryOptions...),
263265
},
264266
},
265267
"primary_name_server": schema.StringAttribute{

stackit/internal/services/loadbalancer/loadbalancer/resource.go

Lines changed: 10 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -28,11 +28,12 @@ import (
2828
"github.com/hashicorp/terraform-plugin-log/tflog"
2929
"github.com/stackitcloud/stackit-sdk-go/core/config"
3030
"github.com/stackitcloud/stackit-sdk-go/core/oapierror"
31-
"github.com/stackitcloud/stackit-sdk-go/core/utils"
31+
sdkUtils "github.com/stackitcloud/stackit-sdk-go/core/utils"
3232
"github.com/stackitcloud/stackit-sdk-go/services/loadbalancer"
3333
"github.com/stackitcloud/stackit-sdk-go/services/loadbalancer/wait"
3434
"github.com/stackitcloud/terraform-provider-stackit/stackit/internal/conversion"
3535
"github.com/stackitcloud/terraform-provider-stackit/stackit/internal/core"
36+
"github.com/stackitcloud/terraform-provider-stackit/stackit/internal/utils"
3637
"github.com/stackitcloud/terraform-provider-stackit/stackit/internal/validate"
3738
)
3839

@@ -219,19 +220,22 @@ func (r *loadBalancerResource) Configure(ctx context.Context, req resource.Confi
219220

220221
// Schema defines the schema for the resource.
221222
func (r *loadBalancerResource) Schema(_ context.Context, _ resource.SchemaRequest, resp *resource.SchemaResponse) {
223+
protocolOptions := []string{"PROTOCOL_UNSPECIFIED", "PROTOCOL_TCP", "PROTOCOL_UDP", "PROTOCOL_TCP_PROXY", "PROTOCOL_TLS_PASSTHROUGH"}
224+
roleOptions := []string{"ROLE_UNSPECIFIED", "ROLE_LISTENERS_AND_TARGETS", "ROLE_LISTENERS", "ROLE_TARGETS"}
225+
222226
descriptions := map[string]string{
223227
"main": "Load Balancer resource schema.",
224228
"id": "Terraform's internal resource ID. It is structured as \"`project_id`\",\"`name`\".",
225229
"project_id": "STACKIT project ID to which the Load Balancer is associated.",
226230
"external_address": "External Load Balancer IP address where this Load Balancer is exposed.",
227231
"listeners": "List of all listeners which will accept traffic. Limited to 20.",
228232
"port": "Port number where we listen for traffic.",
229-
"protocol": "Protocol is the highest network protocol we understand to load balance.",
233+
"protocol": "Protocol is the highest network protocol we understand to load balance. " + utils.SupportedValuesDocumentation(protocolOptions),
230234
"target_pool": "Reference target pool by target pool name.",
231235
"name": "Load balancer name.",
232236
"networks": "List of networks that listeners and targets reside in.",
233237
"network_id": "Openstack network ID.",
234-
"role": "The role defines how the load balancer is using the network.",
238+
"role": "The role defines how the load balancer is using the network. " + utils.SupportedValuesDocumentation(roleOptions),
235239
"options": "Defines any optional functionality you want to have enabled on your load balancer.",
236240
"acl": "Load Balancer is accessible only from an IP address in this range.",
237241
"private_network_only": "If true, Load Balancer is accessible only via a private network IP address.",
@@ -350,7 +354,7 @@ The example below uses OpenStack to create the network, router, a public IP addr
350354
stringplanmodifier.UseStateForUnknown(),
351355
},
352356
Validators: []validator.String{
353-
stringvalidator.OneOf("PROTOCOL_UNSPECIFIED", "PROTOCOL_TCP", "PROTOCOL_UDP", "PROTOCOL_TCP_PROXY", "PROTOCOL_TLS_PASSTHROUGH"),
357+
stringvalidator.OneOf(protocolOptions...),
354358
},
355359
},
356360
"server_name_indicators": schema.ListNestedAttribute{
@@ -420,7 +424,7 @@ The example below uses OpenStack to create the network, router, a public IP addr
420424
stringplanmodifier.UseStateForUnknown(),
421425
},
422426
Validators: []validator.String{
423-
stringvalidator.OneOf("ROLE_UNSPECIFIED", "ROLE_LISTENERS_AND_TARGETS", "ROLE_LISTENERS", "ROLE_TARGETS"),
427+
stringvalidator.OneOf(roleOptions...),
424428
},
425429
},
426430
},
@@ -669,7 +673,7 @@ func (r *loadBalancerResource) Update(ctx context.Context, req resource.UpdateRe
669673
ctx = tflog.SetField(ctx, "target_pool_name", targetPoolName)
670674

671675
// Generate API request body from model
672-
payload, err := toTargetPoolUpdatePayload(ctx, utils.Ptr(targetPoolModel))
676+
payload, err := toTargetPoolUpdatePayload(ctx, sdkUtils.Ptr(targetPoolModel))
673677
if err != nil {
674678
core.LogAndAddError(ctx, &resp.Diagnostics, "Error updating load balancer", fmt.Sprintf("Creating API payload for target pool: %v", err))
675679
return

stackit/internal/services/mongodbflex/user/resource.go

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@ import (
1212
"github.com/hashicorp/terraform-plugin-log/tflog"
1313
"github.com/stackitcloud/terraform-provider-stackit/stackit/internal/conversion"
1414
"github.com/stackitcloud/terraform-provider-stackit/stackit/internal/core"
15+
"github.com/stackitcloud/terraform-provider-stackit/stackit/internal/utils"
1516
"github.com/stackitcloud/terraform-provider-stackit/stackit/internal/validate"
1617

1718
"github.com/hashicorp/terraform-plugin-framework/attr"
@@ -99,13 +100,15 @@ func (r *userResource) Configure(ctx context.Context, req resource.ConfigureRequ
99100

100101
// Schema defines the schema for the resource.
101102
func (r *userResource) Schema(_ context.Context, _ resource.SchemaRequest, resp *resource.SchemaResponse) {
103+
rolesOptions := []string{"read", "readWrite"}
104+
102105
descriptions := map[string]string{
103106
"main": "MongoDB Flex user resource schema. Must have a `region` specified in the provider configuration.",
104107
"id": "Terraform's internal resource ID. It is structured as \"`project_id`,`instance_id`,`user_id`\".",
105108
"user_id": "User ID.",
106109
"instance_id": "ID of the MongoDB Flex instance.",
107110
"project_id": "STACKIT project ID to which the instance is associated.",
108-
"roles": "Database access levels for the user.",
111+
"roles": "Database access levels for the user. " + utils.SupportedValuesDocumentation(rolesOptions),
109112
}
110113

111114
resp.Schema = schema.Schema{
@@ -166,7 +169,7 @@ func (r *userResource) Schema(_ context.Context, _ resource.SchemaRequest, resp
166169
Required: true,
167170
Validators: []validator.Set{
168171
setvalidator.ValueStringsAre(
169-
stringvalidator.OneOf("read", "readWrite"),
172+
stringvalidator.OneOf(rolesOptions...),
170173
),
171174
},
172175
},

stackit/internal/services/postgresflex/user/resource.go

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@ import (
1212
"github.com/hashicorp/terraform-plugin-log/tflog"
1313
"github.com/stackitcloud/terraform-provider-stackit/stackit/internal/conversion"
1414
"github.com/stackitcloud/terraform-provider-stackit/stackit/internal/core"
15+
"github.com/stackitcloud/terraform-provider-stackit/stackit/internal/utils"
1516
"github.com/stackitcloud/terraform-provider-stackit/stackit/internal/validate"
1617

1718
"github.com/hashicorp/terraform-plugin-framework/attr"
@@ -100,12 +101,15 @@ func (r *userResource) Configure(ctx context.Context, req resource.ConfigureRequ
100101

101102
// Schema defines the schema for the resource.
102103
func (r *userResource) Schema(_ context.Context, _ resource.SchemaRequest, resp *resource.SchemaResponse) {
104+
rolesOptions := []string{"login", "createdb"}
105+
103106
descriptions := map[string]string{
104107
"main": "PostgresFlex user resource schema. Must have a `region` specified in the provider configuration.",
105108
"id": "Terraform's internal resource ID. It is structured as \"`project_id`,`instance_id`,`user_id`\".",
106109
"user_id": "User ID.",
107110
"instance_id": "ID of the PostgresFlex instance.",
108111
"project_id": "STACKIT project ID to which the instance is associated.",
112+
"roles": "Database access levels for the user. " + utils.SupportedValuesDocumentation(rolesOptions),
109113
}
110114

111115
resp.Schema = schema.Schema{
@@ -159,6 +163,7 @@ func (r *userResource) Schema(_ context.Context, _ resource.SchemaRequest, resp
159163
},
160164
},
161165
"roles": schema.SetAttribute{
166+
Description: descriptions["roles"],
162167
ElementType: types.StringType,
163168
Required: true,
164169
PlanModifiers: []planmodifier.Set{

stackit/internal/utils/utils.go

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -76,3 +76,17 @@ func SimplifyBackupSchedule(schedule string) string {
7676
})
7777
return simplifiedSchedule
7878
}
79+
80+
func SupportedValuesDocumentation(values []string) string {
81+
if len(values) == 0 {
82+
return ""
83+
}
84+
return "Supported values are: " + strings.Join(quoteValues(values), ", ") + "."
85+
}
86+
87+
func quoteValues(values []string) []string {
88+
for i, value := range values {
89+
values[i] = fmt.Sprintf("`%s`", value)
90+
}
91+
return values
92+
}

stackit/internal/utils/utils_test.go

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -192,3 +192,36 @@ func TestSimplifyBackupSchedule(t *testing.T) {
192192
})
193193
}
194194
}
195+
196+
func TestSupportedValuesDocumentation(t *testing.T) {
197+
tests := []struct {
198+
description string
199+
values []string
200+
expected string
201+
}{
202+
{
203+
"empty values",
204+
[]string{},
205+
"",
206+
},
207+
{
208+
"single value",
209+
[]string{"value"},
210+
"Supported values are: `value`.",
211+
},
212+
{
213+
"multiple values",
214+
[]string{"value1", "value2", "value3"},
215+
"Supported values are: `value1`, `value2`, `value3`.",
216+
},
217+
}
218+
219+
for _, tt := range tests {
220+
t.Run(tt.description, func(t *testing.T) {
221+
output := SupportedValuesDocumentation(tt.values)
222+
if output != tt.expected {
223+
t.Fatalf("Data does not match: %s", output)
224+
}
225+
})
226+
}
227+
}

0 commit comments

Comments
 (0)