Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix(instance): fix ipv6 security rule validation #482

Merged
merged 1 commit into from
Jun 2, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion scaleway/resource_instance_security_group.go
Original file line number Diff line number Diff line change
Expand Up @@ -417,7 +417,7 @@ func securityGroupRuleSchema() *schema.Resource {
"ip_range": {
Type: schema.TypeString,
Optional: true,
ValidateFunc: validation.CIDRNetwork(0, 32),
ValidateFunc: validation.CIDRNetwork(0, 128),
Description: "Ip range for this rule (e.g: 192.168.1.0/24). Only one of ip or ip_range should be provided",
},
},
Expand Down
68 changes: 68 additions & 0 deletions scaleway/resource_instance_security_group_rules_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -195,4 +195,72 @@ func TestAccScalewayInstanceSecurityGroupRules(t *testing.T) {
},
})
})
t.Run("IP Ranges", func(t *testing.T) {
config := `
resource scaleway_instance_security_group sg01 {
external_rules = true
}
resource scaleway_instance_security_group_rules sgrs01 {
security_group_id = scaleway_instance_security_group.sg01.id
inbound_rule {
action = "accept"
port = 80
ip_range = "0.0.0.0/0"
}
inbound_rule {
action = "drop"
port = 443
ip_range = "1.2.0.0/16"
}
outbound_rule {
action = "accept"
port = 80
ip_range = "1.2.3.0/32"
}
outbound_rule {
action = "drop"
port = 443
ip_range = "2002::/24"
}
outbound_rule {
action = "drop"
port = 443
ip_range = "2002:0:0:1234::/64"
}
outbound_rule {
action = "drop"
port = 443
ip_range = "2002::1234:abcd:ffff:c0a8:101/128"
}

}
`

resource.Test(t, resource.TestCase{
PreCheck: func() { testAccPreCheck(t) },
Providers: testAccProviders,
CheckDestroy: testAccCheckScalewayInstanceSecurityGroupDestroy,
Steps: []resource.TestStep{
{
Config: config,
},
{
ImportState: true,
ResourceName: "scaleway_instance_security_group_rules.sgrs01",
Config: config,
Check: resource.ComposeTestCheckFunc(
testAccCheckScalewayInstanceSecurityGroupExists("scaleway_instance_security_group.sg01"),
resource.TestCheckResourceAttr("scaleway_instance_security_group_rules.sgrs01", "inbound_rule.#", "6"),
resource.TestCheckResourceAttr("scaleway_instance_security_group_rules.sgrs01", "inbound_rule.0.ip_range", "0.0.0.0/0"),
resource.TestCheckResourceAttr("scaleway_instance_security_group_rules.sgrs01", "inbound_rule.1.ip_range", "1.2.0.0/16"),
resource.TestCheckResourceAttr("scaleway_instance_security_group_rules.sgrs01", "outbound_rule.0.ip_range", "1.2.3.0/32"),
resource.TestCheckResourceAttr("scaleway_instance_security_group_rules.sgrs01", "outbound_rule.1.ip_range", "2002::/24"),
resource.TestCheckResourceAttr("scaleway_instance_security_group_rules.sgrs01", "outbound_rule.1.ip_range", "2002:0:0:1234::/64"),
resource.TestCheckResourceAttr("scaleway_instance_security_group_rules.sgrs01", "outbound_rule.1.ip_range", "2002::1234:abcd:ffff:c0a8:101/128"),
),
},
},
})
})

}