refactor(docs): remove duplicate util func to format possible values (#1050)
This commit is contained in:
parent
64d6fa9bea
commit
52b879b436
28 changed files with 30 additions and 77 deletions
|
|
@ -131,7 +131,7 @@ func (r *distributionDataSource) Schema(_ context.Context, _ datasource.SchemaRe
|
|||
Attributes: map[string]schema.Attribute{
|
||||
"type": schema.StringAttribute{
|
||||
Computed: true,
|
||||
Description: schemaDescriptions["config_backend_type"] + utils.SupportedValuesDocumentation(backendOptions),
|
||||
Description: schemaDescriptions["config_backend_type"] + utils.FormatPossibleValues(backendOptions...),
|
||||
},
|
||||
"origin_url": schema.StringAttribute{
|
||||
Computed: true,
|
||||
|
|
|
|||
|
|
@ -250,7 +250,7 @@ func (r *distributionResource) Schema(_ context.Context, _ resource.SchemaReques
|
|||
Attributes: map[string]schema.Attribute{
|
||||
"type": schema.StringAttribute{
|
||||
Required: true,
|
||||
Description: schemaDescriptions["config_backend_type"] + utils.SupportedValuesDocumentation(backendOptions),
|
||||
Description: schemaDescriptions["config_backend_type"] + utils.FormatPossibleValues(backendOptions...),
|
||||
Validators: []validator.String{stringvalidator.OneOf(backendOptions...)},
|
||||
},
|
||||
"origin_url": schema.StringAttribute{
|
||||
|
|
|
|||
|
|
@ -235,7 +235,7 @@ func (r *zoneResource) Schema(_ context.Context, _ resource.SchemaRequest, resp
|
|||
},
|
||||
},
|
||||
"type": schema.StringAttribute{
|
||||
Description: "Zone type. Defaults to `primary`. " + utils.SupportedValuesDocumentation(primaryOptions),
|
||||
Description: "Zone type. Defaults to `primary`. " + utils.FormatPossibleValues(primaryOptions...),
|
||||
Optional: true,
|
||||
Computed: true,
|
||||
Default: stringdefault.StaticString("primary"),
|
||||
|
|
|
|||
|
|
@ -126,7 +126,7 @@ func (d *networkInterfaceDataSource) Schema(_ context.Context, _ datasource.Sche
|
|||
ElementType: types.StringType,
|
||||
},
|
||||
"type": schema.StringAttribute{
|
||||
Description: "Type of network interface. Some of the possible values are: " + utils.SupportedValuesDocumentation(typeOptions),
|
||||
Description: "Type of network interface. Some of the possible values are: " + utils.FormatPossibleValues(typeOptions...),
|
||||
Computed: true,
|
||||
},
|
||||
},
|
||||
|
|
|
|||
|
|
@ -237,7 +237,7 @@ func (r *networkInterfaceResource) Schema(_ context.Context, _ resource.SchemaRe
|
|||
},
|
||||
},
|
||||
"type": schema.StringAttribute{
|
||||
Description: "Type of network interface. Some of the possible values are: " + utils.SupportedValuesDocumentation(typeOptions),
|
||||
Description: "Type of network interface. Some of the possible values are: " + utils.FormatPossibleValues(typeOptions...),
|
||||
Computed: true,
|
||||
PlanModifiers: []planmodifier.String{
|
||||
stringplanmodifier.UseStateForUnknown(),
|
||||
|
|
|
|||
|
|
@ -90,7 +90,7 @@ func (r *securityGroupRuleDataSource) Schema(_ context.Context, _ datasource.Sch
|
|||
},
|
||||
},
|
||||
"direction": schema.StringAttribute{
|
||||
Description: "The direction of the traffic which the rule should match. Some of the possible values are: " + utils.SupportedValuesDocumentation(directionOptions),
|
||||
Description: "The direction of the traffic which the rule should match. Some of the possible values are: " + utils.FormatPossibleValues(directionOptions...),
|
||||
Computed: true,
|
||||
},
|
||||
"description": schema.StringAttribute{
|
||||
|
|
|
|||
|
|
@ -230,7 +230,7 @@ func (r *securityGroupRuleResource) Schema(_ context.Context, _ resource.SchemaR
|
|||
},
|
||||
},
|
||||
"direction": schema.StringAttribute{
|
||||
Description: "The direction of the traffic which the rule should match. Some of the possible values are: " + utils.SupportedValuesDocumentation(directionOptions),
|
||||
Description: "The direction of the traffic which the rule should match. Some of the possible values are: " + utils.FormatPossibleValues(directionOptions...),
|
||||
Required: true,
|
||||
PlanModifiers: []planmodifier.String{
|
||||
stringplanmodifier.RequiresReplace(),
|
||||
|
|
|
|||
|
|
@ -262,7 +262,7 @@ func (r *serverResource) Schema(_ context.Context, _ resource.SchemaRequest, res
|
|||
},
|
||||
},
|
||||
"source_type": schema.StringAttribute{
|
||||
Description: "The type of the source. " + utils.SupportedValuesDocumentation(supportedSourceTypes),
|
||||
Description: "The type of the source. " + utils.FormatPossibleValues(supportedSourceTypes...),
|
||||
Required: true,
|
||||
PlanModifiers: []planmodifier.String{
|
||||
stringplanmodifier.RequiresReplace(),
|
||||
|
|
@ -366,7 +366,7 @@ func (r *serverResource) Schema(_ context.Context, _ resource.SchemaRequest, res
|
|||
Computed: true,
|
||||
},
|
||||
"desired_status": schema.StringAttribute{
|
||||
Description: "The desired status of the server resource. " + utils.SupportedValuesDocumentation(desiredStatusOptions),
|
||||
Description: "The desired status of the server resource. " + utils.FormatPossibleValues(desiredStatusOptions...),
|
||||
Optional: true,
|
||||
Validators: []validator.String{
|
||||
stringvalidator.OneOf(desiredStatusOptions...),
|
||||
|
|
|
|||
|
|
@ -118,7 +118,7 @@ func (r *volumeDataSource) Schema(_ context.Context, _ datasource.SchemaRequest,
|
|||
Computed: true,
|
||||
Attributes: map[string]schema.Attribute{
|
||||
"type": schema.StringAttribute{
|
||||
Description: "The type of the source. " + utils.SupportedValuesDocumentation(SupportedSourceTypes),
|
||||
Description: "The type of the source. " + utils.FormatPossibleValues(SupportedSourceTypes...),
|
||||
Computed: true,
|
||||
},
|
||||
"id": schema.StringAttribute{
|
||||
|
|
|
|||
|
|
@ -225,7 +225,7 @@ func (r *volumeResource) Schema(_ context.Context, _ resource.SchemaRequest, res
|
|||
},
|
||||
Attributes: map[string]schema.Attribute{
|
||||
"type": schema.StringAttribute{
|
||||
Description: "The type of the source. " + utils.SupportedValuesDocumentation(SupportedSourceTypes),
|
||||
Description: "The type of the source. " + utils.FormatPossibleValues(SupportedSourceTypes...),
|
||||
Required: true,
|
||||
PlanModifiers: []planmodifier.String{
|
||||
stringplanmodifier.RequiresReplace(),
|
||||
|
|
|
|||
|
|
@ -330,13 +330,13 @@ func (r *loadBalancerResource) Schema(_ context.Context, _ resource.SchemaReques
|
|||
"disable_security_group_assignment": "If set to true, this will disable the automatic assignment of a security group to the load balancer's targets. This option is primarily used to allow targets that are not within the load balancer's own network or SNA (STACKIT network area). When this is enabled, you are fully responsible for ensuring network connectivity to the targets, including managing all routing and security group rules manually. This setting cannot be changed after the load balancer is created.",
|
||||
"listeners": "List of all listeners which will accept traffic. Limited to 20.",
|
||||
"port": "Port number where we listen for traffic.",
|
||||
"protocol": "Protocol is the highest network protocol we understand to load balance. " + utils.SupportedValuesDocumentation(protocolOptions),
|
||||
"protocol": "Protocol is the highest network protocol we understand to load balance. " + utils.FormatPossibleValues(protocolOptions...),
|
||||
"target_pool": "Reference target pool by target pool name.",
|
||||
"name": "Load balancer name.",
|
||||
"plan_id": "The service plan ID. If not defined, the default service plan is `p10`. " + utils.FormatPossibleValues(servicePlanOptions...),
|
||||
"networks": "List of networks that listeners and targets reside in.",
|
||||
"network_id": "Openstack network ID.",
|
||||
"role": "The role defines how the load balancer is using the network. " + utils.SupportedValuesDocumentation(roleOptions),
|
||||
"role": "The role defines how the load balancer is using the network. " + utils.FormatPossibleValues(roleOptions...),
|
||||
"observability": "We offer Load Balancer metrics observability via ARGUS or external solutions. Not changeable after creation.",
|
||||
"observability_logs": "Observability logs configuration. Not changeable after creation.",
|
||||
"observability_logs_credentials_ref": "Credentials reference for logs. Not changeable after creation.",
|
||||
|
|
|
|||
|
|
@ -180,7 +180,7 @@ func (r *instanceResource) Schema(_ context.Context, _ resource.SchemaRequest, r
|
|||
"acl": "The Access Control List (ACL) for the MongoDB Flex instance.",
|
||||
"backup_schedule": `The backup schedule. Should follow the cron scheduling system format (e.g. "0 0 * * *").`,
|
||||
"options": "Custom parameters for the MongoDB Flex instance.",
|
||||
"type": fmt.Sprintf("Type of the MongoDB Flex instance. %s", utils.SupportedValuesDocumentation(typeOptions)),
|
||||
"type": fmt.Sprintf("Type of the MongoDB Flex instance. %s", utils.FormatPossibleValues(typeOptions...)),
|
||||
"snapshot_retention_days": "The number of days that continuous backups (controlled via the `backup_schedule`) will be retained.",
|
||||
"daily_snapshot_retention_days": "The number of days that daily backups will be retained.",
|
||||
"weekly_snapshot_retention_weeks": "The number of weeks that weekly backups will be retained.",
|
||||
|
|
|
|||
|
|
@ -123,7 +123,7 @@ func (r *userResource) Schema(_ context.Context, _ resource.SchemaRequest, resp
|
|||
"user_id": "User ID.",
|
||||
"instance_id": "ID of the PostgresFlex instance.",
|
||||
"project_id": "STACKIT project ID to which the instance is associated.",
|
||||
"roles": "Database access levels for the user. " + utils.SupportedValuesDocumentation(rolesOptions),
|
||||
"roles": "Database access levels for the user. " + utils.FormatPossibleValues(rolesOptions...),
|
||||
"region": "The resource region. If not defined, the provider region is used.",
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -110,20 +110,6 @@ func ConvertPointerSliceToStringSlice(pointerSlice []*string) []string {
|
|||
}
|
||||
return stringSlice
|
||||
}
|
||||
func SupportedValuesDocumentation(values []string) string {
|
||||
if len(values) == 0 {
|
||||
return ""
|
||||
}
|
||||
return "Supported values are: " + strings.Join(QuoteValues(values), ", ") + "."
|
||||
}
|
||||
|
||||
func QuoteValues(values []string) []string {
|
||||
quotedValues := make([]string, len(values))
|
||||
for i, value := range values {
|
||||
quotedValues[i] = fmt.Sprintf("`%s`", value)
|
||||
}
|
||||
return quotedValues
|
||||
}
|
||||
|
||||
func IsLegacyProjectRole(role string) bool {
|
||||
return utils.Contains(LegacyProjectRoles, role)
|
||||
|
|
|
|||
|
|
@ -253,39 +253,6 @@ 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)
|
||||
}
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
func TestIsLegacyProjectRole(t *testing.T) {
|
||||
tests := []struct {
|
||||
description string
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue