Skip to content

Commit c233a4c

Browse files
committed
fix(vpc): set correct default policy value
1 parent 56d47ea commit c233a4c

File tree

5 files changed

+1018
-439
lines changed

5 files changed

+1018
-439
lines changed

docs/resources/vpc_acl.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,7 @@ resource "scaleway_vpc_acl" "acl01" {
3939
The following arguments are supported:
4040

4141
- `vpc_id` - (Required) The VPC ID the ACL belongs to.
42-
- `default_policy` - (Required) The action to take for packets which do not match any rules.
42+
- `default_policy` - (Optional, Defaults to `accept) The action to take for packets which do not match any rules.
4343
- `is_ipv6` - (Optional) Defines whether this set of ACL rules is for IPv6 (false = IPv4). Each Network ACL can have rules for only one IP type.
4444
- `rules` - (Optional) The list of Network ACL rules.
4545
- `protocol` - (Optional) The protocol to which this rule applies. Default value: ANY.

internal/services/vpc/acl.go

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,8 @@ func ResourceACL() *schema.Resource {
3131
},
3232
"default_policy": {
3333
Type: schema.TypeString,
34-
Required: true,
34+
Optional: true,
35+
Default: vpc.ActionAccept,
3536
Description: "The action to take for packets which do not match any rules",
3637
ValidateDiagFunc: verify.ValidateEnum[vpc.Action](),
3738
},
@@ -43,7 +44,7 @@ func ResourceACL() *schema.Resource {
4344
},
4445
"rules": {
4546
Type: schema.TypeList,
46-
Required: true,
47+
Optional: true,
4748
Description: "The list of Network ACL rules",
4849
Elem: &schema.Resource{
4950
Schema: map[string]*schema.Schema{
@@ -201,7 +202,7 @@ func ResourceVPCACLDelete(ctx context.Context, d *schema.ResourceData, m any) di
201202
_, err = vpcAPI.SetACL(&vpc.SetACLRequest{
202203
VpcID: locality.ExpandID(ID),
203204
Region: region,
204-
DefaultPolicy: "drop",
205+
DefaultPolicy: vpc.ActionAccept,
205206
}, scw.WithContext(ctx))
206207
if err != nil {
207208
return diag.FromErr(err)

internal/services/vpc/acl_test.go

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,36 @@ import (
1313
)
1414

1515
func TestAccACL_Basic(t *testing.T) {
16+
tt := acctest.NewTestTools(t)
17+
defer tt.Cleanup()
18+
resource.ParallelTest(t, resource.TestCase{
19+
PreCheck: func() { acctest.PreCheck(t) },
20+
ProviderFactories: tt.ProviderFactories,
21+
CheckDestroy: isACLDestroyed(tt),
22+
Steps: []resource.TestStep{
23+
{
24+
Config: `
25+
resource "scaleway_vpc" "vpc01" {
26+
name = "tf-vpc-acl-basic"
27+
}
28+
29+
resource "scaleway_vpc_acl" "acl01" {
30+
vpc_id = scaleway_vpc.vpc01.id
31+
is_ipv6 = false
32+
}
33+
`,
34+
Check: resource.ComposeTestCheckFunc(
35+
isACLPresent(tt, "scaleway_vpc_acl.acl01"),
36+
resource.TestCheckResourceAttrPair("scaleway_vpc_acl.acl01", "vpc_id", "scaleway_vpc.vpc01", "id"),
37+
resource.TestCheckResourceAttr("scaleway_vpc_acl.acl01", "is_ipv6", "false"),
38+
resource.TestCheckResourceAttr("scaleway_vpc_acl.acl01", "default_policy", "accept"),
39+
),
40+
},
41+
},
42+
})
43+
}
44+
45+
func TestAccACL_WithRules(t *testing.T) {
1646
tt := acctest.NewTestTools(t)
1747
defer tt.Cleanup()
1848
resource.ParallelTest(t, resource.TestCase{

0 commit comments

Comments
 (0)