chore(docs): add possible values for security group rule protocol (#857)

relates to #816
This commit is contained in:
Ruben Hönle 2025-05-21 16:17:00 +02:00 committed by GitHub
parent c6937154e8
commit 5b044d275f
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
4 changed files with 55 additions and 6 deletions

View file

@ -74,5 +74,5 @@ Required:
Optional:
- `name` (String) The protocol name which the rule should match. Either `name` or `number` must be provided.
- `name` (String) The protocol name which the rule should match. Either `name` or `number` must be provided. Possible values are: `ah`, `dccp`, `egp`, `esp`, `gre`, `icmp`, `igmp`, `ipip`, `ipv6-encap`, `ipv6-frag`, `ipv6-icmp`, `ipv6-nonxt`, `ipv6-opts`, `ipv6-route`, `ospf`, `pgm`, `rsvp`, `sctp`, `tcp`, `udp`, `udplite`, `vrrp`.
- `number` (Number) The protocol number which the rule should match. Either `name` or `number` must be provided.

View file

@ -34,10 +34,14 @@ import (
// Ensure the implementation satisfies the expected interfaces.
var (
_ resource.Resource = &securityGroupRuleResource{}
_ resource.ResourceWithConfigure = &securityGroupRuleResource{}
_ resource.ResourceWithImportState = &securityGroupRuleResource{}
icmpProtocols = []string{"icmp", "ipv6-icmp"}
_ resource.Resource = &securityGroupRuleResource{}
_ resource.ResourceWithConfigure = &securityGroupRuleResource{}
_ resource.ResourceWithImportState = &securityGroupRuleResource{}
icmpProtocols = []string{"icmp", "ipv6-icmp"}
protocolsPossibleValues = []string{
"ah", "dccp", "egp", "esp", "gre", "icmp", "igmp", "ipip", "ipv6-encap", "ipv6-frag", "ipv6-icmp",
"ipv6-nonxt", "ipv6-opts", "ipv6-route", "ospf", "pgm", "rsvp", "sctp", "tcp", "udp", "udplite", "vrrp",
}
)
type Model struct {
@ -329,7 +333,7 @@ func (r *securityGroupRuleResource) Schema(_ context.Context, _ resource.SchemaR
},
Attributes: map[string]schema.Attribute{
"name": schema.StringAttribute{
Description: "The protocol name which the rule should match. Either `name` or `number` must be provided.",
Description: fmt.Sprintf("The protocol name which the rule should match. Either `name` or `number` must be provided. %s", utils.FormatPossibleValues(protocolsPossibleValues)),
Optional: true,
Computed: true,
Validators: []validator.String{

View file

@ -144,3 +144,12 @@ func LogError(ctx context.Context, inputDiags *diag.Diagnostics, err error, summ
}
core.LogAndAddError(ctx, inputDiags, summary, description)
}
// FormatPossibleValues formats a slice into a comma-separated-list for usage in the provider docs
func FormatPossibleValues(values []string) string {
var formattedValues []string
for _, value := range values {
formattedValues = append(formattedValues, fmt.Sprintf("`%v`", value))
}
return fmt.Sprintf("Possible values are: %s.", strings.Join(formattedValues, ", "))
}

View file

@ -1,6 +1,7 @@
package utils
import (
"fmt"
"testing"
"github.com/google/go-cmp/cmp"
@ -268,3 +269,38 @@ func TestIsLegacyProjectRole(t *testing.T) {
})
}
}
func TestFormatPossibleValues(t *testing.T) {
gotPrefix := "Possible values are:"
type args struct {
values []string
}
tests := []struct {
name string
args args
want string
}{
{
name: "single string value",
args: args{
values: []string{"foo"},
},
want: fmt.Sprintf("%s `foo`.", gotPrefix),
},
{
name: "multiple string value",
args: args{
values: []string{"foo", "bar", "trololol"},
},
want: fmt.Sprintf("%s `foo`, `bar`, `trololol`.", gotPrefix),
},
}
for _, tt := range tests {
t.Run(tt.name, func(t *testing.T) {
if got := FormatPossibleValues(tt.args.values); got != tt.want {
t.Errorf("FormatPossibleValues() = %v, want %v", got, tt.want)
}
})
}
}