Document possible values of schema fields (#455)
* Document possible values of schema fields * Change from possible to supported
This commit is contained in:
parent
846a2ba181
commit
3fb28d1248
10 changed files with 76 additions and 15 deletions
|
|
@ -47,7 +47,7 @@ resource "stackit_dns_zone" "example" {
|
||||||
- `primaries` (List of String) Primary name server for secondary zone. E.g. ["1.2.3.4"]
|
- `primaries` (List of String) Primary name server for secondary zone. E.g. ["1.2.3.4"]
|
||||||
- `refresh_time` (Number) Refresh time. E.g. 3600
|
- `refresh_time` (Number) Refresh time. E.g. 3600
|
||||||
- `retry_time` (Number) Retry time. E.g. 600
|
- `retry_time` (Number) Retry time. E.g. 600
|
||||||
- `type` (String) Zone type. Defaults to `primary`
|
- `type` (String) Zone type. Defaults to `primary`. Supported values are: `primary`, `secondary`.
|
||||||
|
|
||||||
### Read-Only
|
### Read-Only
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -203,7 +203,7 @@ Optional:
|
||||||
|
|
||||||
- `display_name` (String)
|
- `display_name` (String)
|
||||||
- `port` (Number) Port number where we listen for traffic.
|
- `port` (Number) Port number where we listen for traffic.
|
||||||
- `protocol` (String) Protocol is the highest network protocol we understand to load balance.
|
- `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`.
|
||||||
- `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))
|
- `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))
|
||||||
- `target_pool` (String) Reference target pool by target pool name.
|
- `target_pool` (String) Reference target pool by target pool name.
|
||||||
|
|
||||||
|
|
@ -225,7 +225,7 @@ Required:
|
||||||
|
|
||||||
Optional:
|
Optional:
|
||||||
|
|
||||||
- `role` (String) The role defines how the load balancer is using the network.
|
- `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`.
|
||||||
|
|
||||||
|
|
||||||
<a id="nestedatt--target_pools"></a>
|
<a id="nestedatt--target_pools"></a>
|
||||||
|
|
|
||||||
|
|
@ -30,7 +30,7 @@ resource "stackit_mongodbflex_user" "example" {
|
||||||
- `database` (String)
|
- `database` (String)
|
||||||
- `instance_id` (String) ID of the MongoDB Flex instance.
|
- `instance_id` (String) ID of the MongoDB Flex instance.
|
||||||
- `project_id` (String) STACKIT project ID to which the instance is associated.
|
- `project_id` (String) STACKIT project ID to which the instance is associated.
|
||||||
- `roles` (Set of String) Database access levels for the user.
|
- `roles` (Set of String) Database access levels for the user. Supported values are: `read`, `readWrite`.
|
||||||
|
|
||||||
### Optional
|
### Optional
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -28,7 +28,7 @@ resource "stackit_postgresflex_user" "example" {
|
||||||
|
|
||||||
- `instance_id` (String) ID of the PostgresFlex instance.
|
- `instance_id` (String) ID of the PostgresFlex instance.
|
||||||
- `project_id` (String) STACKIT project ID to which the instance is associated.
|
- `project_id` (String) STACKIT project ID to which the instance is associated.
|
||||||
- `roles` (Set of String)
|
- `roles` (Set of String) Database access levels for the user. Supported values are: `login`, `createdb`.
|
||||||
- `username` (String)
|
- `username` (String)
|
||||||
|
|
||||||
### Read-Only
|
### Read-Only
|
||||||
|
|
|
||||||
|
|
@ -114,6 +114,8 @@ func (r *zoneResource) Configure(ctx context.Context, req resource.ConfigureRequ
|
||||||
|
|
||||||
// Schema defines the schema for the resource.
|
// Schema defines the schema for the resource.
|
||||||
func (r *zoneResource) Schema(_ context.Context, _ resource.SchemaRequest, resp *resource.SchemaResponse) {
|
func (r *zoneResource) Schema(_ context.Context, _ resource.SchemaRequest, resp *resource.SchemaResponse) {
|
||||||
|
primaryOptions := []string{"primary", "secondary"}
|
||||||
|
|
||||||
resp.Schema = schema.Schema{
|
resp.Schema = schema.Schema{
|
||||||
Description: "DNS Zone resource schema.",
|
Description: "DNS Zone resource schema.",
|
||||||
Attributes: map[string]schema.Attribute{
|
Attributes: map[string]schema.Attribute{
|
||||||
|
|
@ -254,12 +256,12 @@ func (r *zoneResource) Schema(_ context.Context, _ resource.SchemaRequest, resp
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
"type": schema.StringAttribute{
|
"type": schema.StringAttribute{
|
||||||
Description: "Zone type. Defaults to `primary`",
|
Description: "Zone type. Defaults to `primary`. " + utils.SupportedValuesDocumentation(primaryOptions),
|
||||||
Optional: true,
|
Optional: true,
|
||||||
Computed: true,
|
Computed: true,
|
||||||
Default: stringdefault.StaticString("primary"),
|
Default: stringdefault.StaticString("primary"),
|
||||||
Validators: []validator.String{
|
Validators: []validator.String{
|
||||||
stringvalidator.OneOf("primary", "secondary"),
|
stringvalidator.OneOf(primaryOptions...),
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
"primary_name_server": schema.StringAttribute{
|
"primary_name_server": schema.StringAttribute{
|
||||||
|
|
|
||||||
|
|
@ -28,11 +28,12 @@ import (
|
||||||
"github.com/hashicorp/terraform-plugin-log/tflog"
|
"github.com/hashicorp/terraform-plugin-log/tflog"
|
||||||
"github.com/stackitcloud/stackit-sdk-go/core/config"
|
"github.com/stackitcloud/stackit-sdk-go/core/config"
|
||||||
"github.com/stackitcloud/stackit-sdk-go/core/oapierror"
|
"github.com/stackitcloud/stackit-sdk-go/core/oapierror"
|
||||||
"github.com/stackitcloud/stackit-sdk-go/core/utils"
|
sdkUtils "github.com/stackitcloud/stackit-sdk-go/core/utils"
|
||||||
"github.com/stackitcloud/stackit-sdk-go/services/loadbalancer"
|
"github.com/stackitcloud/stackit-sdk-go/services/loadbalancer"
|
||||||
"github.com/stackitcloud/stackit-sdk-go/services/loadbalancer/wait"
|
"github.com/stackitcloud/stackit-sdk-go/services/loadbalancer/wait"
|
||||||
"github.com/stackitcloud/terraform-provider-stackit/stackit/internal/conversion"
|
"github.com/stackitcloud/terraform-provider-stackit/stackit/internal/conversion"
|
||||||
"github.com/stackitcloud/terraform-provider-stackit/stackit/internal/core"
|
"github.com/stackitcloud/terraform-provider-stackit/stackit/internal/core"
|
||||||
|
"github.com/stackitcloud/terraform-provider-stackit/stackit/internal/utils"
|
||||||
"github.com/stackitcloud/terraform-provider-stackit/stackit/internal/validate"
|
"github.com/stackitcloud/terraform-provider-stackit/stackit/internal/validate"
|
||||||
)
|
)
|
||||||
|
|
||||||
|
|
@ -219,6 +220,9 @@ func (r *loadBalancerResource) Configure(ctx context.Context, req resource.Confi
|
||||||
|
|
||||||
// Schema defines the schema for the resource.
|
// Schema defines the schema for the resource.
|
||||||
func (r *loadBalancerResource) Schema(_ context.Context, _ resource.SchemaRequest, resp *resource.SchemaResponse) {
|
func (r *loadBalancerResource) Schema(_ context.Context, _ resource.SchemaRequest, resp *resource.SchemaResponse) {
|
||||||
|
protocolOptions := []string{"PROTOCOL_UNSPECIFIED", "PROTOCOL_TCP", "PROTOCOL_UDP", "PROTOCOL_TCP_PROXY", "PROTOCOL_TLS_PASSTHROUGH"}
|
||||||
|
roleOptions := []string{"ROLE_UNSPECIFIED", "ROLE_LISTENERS_AND_TARGETS", "ROLE_LISTENERS", "ROLE_TARGETS"}
|
||||||
|
|
||||||
descriptions := map[string]string{
|
descriptions := map[string]string{
|
||||||
"main": "Load Balancer resource schema.",
|
"main": "Load Balancer resource schema.",
|
||||||
"id": "Terraform's internal resource ID. It is structured as \"`project_id`\",\"`name`\".",
|
"id": "Terraform's internal resource ID. It is structured as \"`project_id`\",\"`name`\".",
|
||||||
|
|
@ -226,12 +230,12 @@ func (r *loadBalancerResource) Schema(_ context.Context, _ resource.SchemaReques
|
||||||
"external_address": "External Load Balancer IP address where this Load Balancer is exposed.",
|
"external_address": "External Load Balancer IP address where this Load Balancer is exposed.",
|
||||||
"listeners": "List of all listeners which will accept traffic. Limited to 20.",
|
"listeners": "List of all listeners which will accept traffic. Limited to 20.",
|
||||||
"port": "Port number where we listen for traffic.",
|
"port": "Port number where we listen for traffic.",
|
||||||
"protocol": "Protocol is the highest network protocol we understand to load balance.",
|
"protocol": "Protocol is the highest network protocol we understand to load balance. " + utils.SupportedValuesDocumentation(protocolOptions),
|
||||||
"target_pool": "Reference target pool by target pool name.",
|
"target_pool": "Reference target pool by target pool name.",
|
||||||
"name": "Load balancer name.",
|
"name": "Load balancer name.",
|
||||||
"networks": "List of networks that listeners and targets reside in.",
|
"networks": "List of networks that listeners and targets reside in.",
|
||||||
"network_id": "Openstack network ID.",
|
"network_id": "Openstack network ID.",
|
||||||
"role": "The role defines how the load balancer is using the network.",
|
"role": "The role defines how the load balancer is using the network. " + utils.SupportedValuesDocumentation(roleOptions),
|
||||||
"options": "Defines any optional functionality you want to have enabled on your load balancer.",
|
"options": "Defines any optional functionality you want to have enabled on your load balancer.",
|
||||||
"acl": "Load Balancer is accessible only from an IP address in this range.",
|
"acl": "Load Balancer is accessible only from an IP address in this range.",
|
||||||
"private_network_only": "If true, Load Balancer is accessible only via a private network IP address.",
|
"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
|
||||||
stringplanmodifier.UseStateForUnknown(),
|
stringplanmodifier.UseStateForUnknown(),
|
||||||
},
|
},
|
||||||
Validators: []validator.String{
|
Validators: []validator.String{
|
||||||
stringvalidator.OneOf("PROTOCOL_UNSPECIFIED", "PROTOCOL_TCP", "PROTOCOL_UDP", "PROTOCOL_TCP_PROXY", "PROTOCOL_TLS_PASSTHROUGH"),
|
stringvalidator.OneOf(protocolOptions...),
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
"server_name_indicators": schema.ListNestedAttribute{
|
"server_name_indicators": schema.ListNestedAttribute{
|
||||||
|
|
@ -420,7 +424,7 @@ The example below uses OpenStack to create the network, router, a public IP addr
|
||||||
stringplanmodifier.UseStateForUnknown(),
|
stringplanmodifier.UseStateForUnknown(),
|
||||||
},
|
},
|
||||||
Validators: []validator.String{
|
Validators: []validator.String{
|
||||||
stringvalidator.OneOf("ROLE_UNSPECIFIED", "ROLE_LISTENERS_AND_TARGETS", "ROLE_LISTENERS", "ROLE_TARGETS"),
|
stringvalidator.OneOf(roleOptions...),
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
|
|
@ -669,7 +673,7 @@ func (r *loadBalancerResource) Update(ctx context.Context, req resource.UpdateRe
|
||||||
ctx = tflog.SetField(ctx, "target_pool_name", targetPoolName)
|
ctx = tflog.SetField(ctx, "target_pool_name", targetPoolName)
|
||||||
|
|
||||||
// Generate API request body from model
|
// Generate API request body from model
|
||||||
payload, err := toTargetPoolUpdatePayload(ctx, utils.Ptr(targetPoolModel))
|
payload, err := toTargetPoolUpdatePayload(ctx, sdkUtils.Ptr(targetPoolModel))
|
||||||
if err != nil {
|
if err != nil {
|
||||||
core.LogAndAddError(ctx, &resp.Diagnostics, "Error updating load balancer", fmt.Sprintf("Creating API payload for target pool: %v", err))
|
core.LogAndAddError(ctx, &resp.Diagnostics, "Error updating load balancer", fmt.Sprintf("Creating API payload for target pool: %v", err))
|
||||||
return
|
return
|
||||||
|
|
|
||||||
|
|
@ -12,6 +12,7 @@ import (
|
||||||
"github.com/hashicorp/terraform-plugin-log/tflog"
|
"github.com/hashicorp/terraform-plugin-log/tflog"
|
||||||
"github.com/stackitcloud/terraform-provider-stackit/stackit/internal/conversion"
|
"github.com/stackitcloud/terraform-provider-stackit/stackit/internal/conversion"
|
||||||
"github.com/stackitcloud/terraform-provider-stackit/stackit/internal/core"
|
"github.com/stackitcloud/terraform-provider-stackit/stackit/internal/core"
|
||||||
|
"github.com/stackitcloud/terraform-provider-stackit/stackit/internal/utils"
|
||||||
"github.com/stackitcloud/terraform-provider-stackit/stackit/internal/validate"
|
"github.com/stackitcloud/terraform-provider-stackit/stackit/internal/validate"
|
||||||
|
|
||||||
"github.com/hashicorp/terraform-plugin-framework/attr"
|
"github.com/hashicorp/terraform-plugin-framework/attr"
|
||||||
|
|
@ -99,13 +100,15 @@ func (r *userResource) Configure(ctx context.Context, req resource.ConfigureRequ
|
||||||
|
|
||||||
// Schema defines the schema for the resource.
|
// Schema defines the schema for the resource.
|
||||||
func (r *userResource) Schema(_ context.Context, _ resource.SchemaRequest, resp *resource.SchemaResponse) {
|
func (r *userResource) Schema(_ context.Context, _ resource.SchemaRequest, resp *resource.SchemaResponse) {
|
||||||
|
rolesOptions := []string{"read", "readWrite"}
|
||||||
|
|
||||||
descriptions := map[string]string{
|
descriptions := map[string]string{
|
||||||
"main": "MongoDB Flex user resource schema. Must have a `region` specified in the provider configuration.",
|
"main": "MongoDB Flex user resource schema. Must have a `region` specified in the provider configuration.",
|
||||||
"id": "Terraform's internal resource ID. It is structured as \"`project_id`,`instance_id`,`user_id`\".",
|
"id": "Terraform's internal resource ID. It is structured as \"`project_id`,`instance_id`,`user_id`\".",
|
||||||
"user_id": "User ID.",
|
"user_id": "User ID.",
|
||||||
"instance_id": "ID of the MongoDB Flex instance.",
|
"instance_id": "ID of the MongoDB Flex instance.",
|
||||||
"project_id": "STACKIT project ID to which the instance is associated.",
|
"project_id": "STACKIT project ID to which the instance is associated.",
|
||||||
"roles": "Database access levels for the user.",
|
"roles": "Database access levels for the user. " + utils.SupportedValuesDocumentation(rolesOptions),
|
||||||
}
|
}
|
||||||
|
|
||||||
resp.Schema = schema.Schema{
|
resp.Schema = schema.Schema{
|
||||||
|
|
@ -166,7 +169,7 @@ func (r *userResource) Schema(_ context.Context, _ resource.SchemaRequest, resp
|
||||||
Required: true,
|
Required: true,
|
||||||
Validators: []validator.Set{
|
Validators: []validator.Set{
|
||||||
setvalidator.ValueStringsAre(
|
setvalidator.ValueStringsAre(
|
||||||
stringvalidator.OneOf("read", "readWrite"),
|
stringvalidator.OneOf(rolesOptions...),
|
||||||
),
|
),
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
|
|
|
||||||
|
|
@ -12,6 +12,7 @@ import (
|
||||||
"github.com/hashicorp/terraform-plugin-log/tflog"
|
"github.com/hashicorp/terraform-plugin-log/tflog"
|
||||||
"github.com/stackitcloud/terraform-provider-stackit/stackit/internal/conversion"
|
"github.com/stackitcloud/terraform-provider-stackit/stackit/internal/conversion"
|
||||||
"github.com/stackitcloud/terraform-provider-stackit/stackit/internal/core"
|
"github.com/stackitcloud/terraform-provider-stackit/stackit/internal/core"
|
||||||
|
"github.com/stackitcloud/terraform-provider-stackit/stackit/internal/utils"
|
||||||
"github.com/stackitcloud/terraform-provider-stackit/stackit/internal/validate"
|
"github.com/stackitcloud/terraform-provider-stackit/stackit/internal/validate"
|
||||||
|
|
||||||
"github.com/hashicorp/terraform-plugin-framework/attr"
|
"github.com/hashicorp/terraform-plugin-framework/attr"
|
||||||
|
|
@ -100,12 +101,15 @@ func (r *userResource) Configure(ctx context.Context, req resource.ConfigureRequ
|
||||||
|
|
||||||
// Schema defines the schema for the resource.
|
// Schema defines the schema for the resource.
|
||||||
func (r *userResource) Schema(_ context.Context, _ resource.SchemaRequest, resp *resource.SchemaResponse) {
|
func (r *userResource) Schema(_ context.Context, _ resource.SchemaRequest, resp *resource.SchemaResponse) {
|
||||||
|
rolesOptions := []string{"login", "createdb"}
|
||||||
|
|
||||||
descriptions := map[string]string{
|
descriptions := map[string]string{
|
||||||
"main": "PostgresFlex user resource schema. Must have a `region` specified in the provider configuration.",
|
"main": "PostgresFlex user resource schema. Must have a `region` specified in the provider configuration.",
|
||||||
"id": "Terraform's internal resource ID. It is structured as \"`project_id`,`instance_id`,`user_id`\".",
|
"id": "Terraform's internal resource ID. It is structured as \"`project_id`,`instance_id`,`user_id`\".",
|
||||||
"user_id": "User ID.",
|
"user_id": "User ID.",
|
||||||
"instance_id": "ID of the PostgresFlex instance.",
|
"instance_id": "ID of the PostgresFlex instance.",
|
||||||
"project_id": "STACKIT project ID to which the instance is associated.",
|
"project_id": "STACKIT project ID to which the instance is associated.",
|
||||||
|
"roles": "Database access levels for the user. " + utils.SupportedValuesDocumentation(rolesOptions),
|
||||||
}
|
}
|
||||||
|
|
||||||
resp.Schema = schema.Schema{
|
resp.Schema = schema.Schema{
|
||||||
|
|
@ -159,6 +163,7 @@ func (r *userResource) Schema(_ context.Context, _ resource.SchemaRequest, resp
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
"roles": schema.SetAttribute{
|
"roles": schema.SetAttribute{
|
||||||
|
Description: descriptions["roles"],
|
||||||
ElementType: types.StringType,
|
ElementType: types.StringType,
|
||||||
Required: true,
|
Required: true,
|
||||||
PlanModifiers: []planmodifier.Set{
|
PlanModifiers: []planmodifier.Set{
|
||||||
|
|
|
||||||
|
|
@ -76,3 +76,17 @@ func SimplifyBackupSchedule(schedule string) string {
|
||||||
})
|
})
|
||||||
return simplifiedSchedule
|
return simplifiedSchedule
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func SupportedValuesDocumentation(values []string) string {
|
||||||
|
if len(values) == 0 {
|
||||||
|
return ""
|
||||||
|
}
|
||||||
|
return "Supported values are: " + strings.Join(quoteValues(values), ", ") + "."
|
||||||
|
}
|
||||||
|
|
||||||
|
func quoteValues(values []string) []string {
|
||||||
|
for i, value := range values {
|
||||||
|
values[i] = fmt.Sprintf("`%s`", value)
|
||||||
|
}
|
||||||
|
return values
|
||||||
|
}
|
||||||
|
|
|
||||||
|
|
@ -192,3 +192,36 @@ func TestSimplifyBackupSchedule(t *testing.T) {
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func TestSupportedValuesDocumentation(t *testing.T) {
|
||||||
|
tests := []struct {
|
||||||
|
description string
|
||||||
|
values []string
|
||||||
|
expected string
|
||||||
|
}{
|
||||||
|
{
|
||||||
|
"empty values",
|
||||||
|
[]string{},
|
||||||
|
"",
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"single value",
|
||||||
|
[]string{"value"},
|
||||||
|
"Supported values are: `value`.",
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"multiple values",
|
||||||
|
[]string{"value1", "value2", "value3"},
|
||||||
|
"Supported values are: `value1`, `value2`, `value3`.",
|
||||||
|
},
|
||||||
|
}
|
||||||
|
|
||||||
|
for _, tt := range tests {
|
||||||
|
t.Run(tt.description, func(t *testing.T) {
|
||||||
|
output := SupportedValuesDocumentation(tt.values)
|
||||||
|
if output != tt.expected {
|
||||||
|
t.Fatalf("Data does not match: %s", output)
|
||||||
|
}
|
||||||
|
})
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue