Skip to content

Commit 5b044d2

Browse files
authored
chore(docs): add possible values for security group rule protocol (#857)
relates to #816
1 parent c693715 commit 5b044d2

4 files changed

Lines changed: 55 additions & 6 deletions

File tree

docs/resources/security_group_rule.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -74,5 +74,5 @@ Required:
7474

7575
Optional:
7676

77-
- `name` (String) The protocol name which the rule should match. Either `name` or `number` must be provided.
77+
- `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`.
7878
- `number` (Number) The protocol number which the rule should match. Either `name` or `number` must be provided.

stackit/internal/services/iaas/securitygrouprule/resource.go

Lines changed: 9 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -34,10 +34,14 @@ import (
3434

3535
// Ensure the implementation satisfies the expected interfaces.
3636
var (
37-
_ resource.Resource = &securityGroupRuleResource{}
38-
_ resource.ResourceWithConfigure = &securityGroupRuleResource{}
39-
_ resource.ResourceWithImportState = &securityGroupRuleResource{}
40-
icmpProtocols = []string{"icmp", "ipv6-icmp"}
37+
_ resource.Resource = &securityGroupRuleResource{}
38+
_ resource.ResourceWithConfigure = &securityGroupRuleResource{}
39+
_ resource.ResourceWithImportState = &securityGroupRuleResource{}
40+
icmpProtocols = []string{"icmp", "ipv6-icmp"}
41+
protocolsPossibleValues = []string{
42+
"ah", "dccp", "egp", "esp", "gre", "icmp", "igmp", "ipip", "ipv6-encap", "ipv6-frag", "ipv6-icmp",
43+
"ipv6-nonxt", "ipv6-opts", "ipv6-route", "ospf", "pgm", "rsvp", "sctp", "tcp", "udp", "udplite", "vrrp",
44+
}
4145
)
4246

4347
type Model struct {
@@ -329,7 +333,7 @@ func (r *securityGroupRuleResource) Schema(_ context.Context, _ resource.SchemaR
329333
},
330334
Attributes: map[string]schema.Attribute{
331335
"name": schema.StringAttribute{
332-
Description: "The protocol name which the rule should match. Either `name` or `number` must be provided.",
336+
Description: fmt.Sprintf("The protocol name which the rule should match. Either `name` or `number` must be provided. %s", utils.FormatPossibleValues(protocolsPossibleValues)),
333337
Optional: true,
334338
Computed: true,
335339
Validators: []validator.String{

stackit/internal/utils/utils.go

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -144,3 +144,12 @@ func LogError(ctx context.Context, inputDiags *diag.Diagnostics, err error, summ
144144
}
145145
core.LogAndAddError(ctx, inputDiags, summary, description)
146146
}
147+
148+
// FormatPossibleValues formats a slice into a comma-separated-list for usage in the provider docs
149+
func FormatPossibleValues(values []string) string {
150+
var formattedValues []string
151+
for _, value := range values {
152+
formattedValues = append(formattedValues, fmt.Sprintf("`%v`", value))
153+
}
154+
return fmt.Sprintf("Possible values are: %s.", strings.Join(formattedValues, ", "))
155+
}

stackit/internal/utils/utils_test.go

Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
package utils
22

33
import (
4+
"fmt"
45
"testing"
56

67
"github.com/google/go-cmp/cmp"
@@ -268,3 +269,38 @@ func TestIsLegacyProjectRole(t *testing.T) {
268269
})
269270
}
270271
}
272+
273+
func TestFormatPossibleValues(t *testing.T) {
274+
gotPrefix := "Possible values are:"
275+
276+
type args struct {
277+
values []string
278+
}
279+
tests := []struct {
280+
name string
281+
args args
282+
want string
283+
}{
284+
{
285+
name: "single string value",
286+
args: args{
287+
values: []string{"foo"},
288+
},
289+
want: fmt.Sprintf("%s `foo`.", gotPrefix),
290+
},
291+
{
292+
name: "multiple string value",
293+
args: args{
294+
values: []string{"foo", "bar", "trololol"},
295+
},
296+
want: fmt.Sprintf("%s `foo`, `bar`, `trololol`.", gotPrefix),
297+
},
298+
}
299+
for _, tt := range tests {
300+
t.Run(tt.name, func(t *testing.T) {
301+
if got := FormatPossibleValues(tt.args.values); got != tt.want {
302+
t.Errorf("FormatPossibleValues() = %v, want %v", got, tt.want)
303+
}
304+
})
305+
}
306+
}

0 commit comments

Comments
 (0)