provider/scaleway: fix security_group_rule identification

This commit is contained in:
Raphael Randschau 2016-09-05 16:29:18 +02:00
parent cdcff09d99
commit 9f598a68af
No known key found for this signature in database
GPG Key ID: ECFD707E1275A182
2 changed files with 28 additions and 4 deletions

View File

@ -89,8 +89,16 @@ func resourceScalewaySecurityGroupRuleCreate(d *schema.ResourceData, m interface
return err
}
matches := func(rule api.ScalewaySecurityGroupRule) bool {
return rule.Action == req.Action &&
rule.Direction == req.Direction &&
rule.IPRange == req.IPRange &&
rule.Protocol == req.Protocol &&
rule.DestPortFrom == req.DestPortFrom
}
for _, rule := range resp.Rules {
if rule.Action == req.Action && rule.Direction == req.Direction && rule.IPRange == req.IPRange && rule.Protocol == req.Protocol {
if matches(rule) {
d.SetId(rule.ID)
break
}

View File

@ -21,10 +21,16 @@ func TestAccScalewaySecurityGroupRule_Basic(t *testing.T) {
Config: testAccCheckScalewaySecurityGroupRuleConfig,
Check: resource.ComposeTestCheckFunc(
testAccCheckScalewaySecurityGroupsExists("scaleway_security_group.base", &group),
resource.TestCheckResourceAttr("scaleway_security_group_rule.http", "action", "drop"),
resource.TestCheckResourceAttr("scaleway_security_group_rule.http", "action", "accept"),
resource.TestCheckResourceAttr("scaleway_security_group_rule.http", "direction", "inbound"),
resource.TestCheckResourceAttr("scaleway_security_group_rule.http", "ip_range", "0.0.0.0/0"),
resource.TestCheckResourceAttr("scaleway_security_group_rule.http", "protocol", "TCP"),
resource.TestCheckResourceAttr("scaleway_security_group_rule.http", "port", "80"),
resource.TestCheckResourceAttr("scaleway_security_group_rule.https", "action", "accept"),
resource.TestCheckResourceAttr("scaleway_security_group_rule.https", "direction", "inbound"),
resource.TestCheckResourceAttr("scaleway_security_group_rule.https", "ip_range", "0.0.0.0/0"),
resource.TestCheckResourceAttr("scaleway_security_group_rule.https", "protocol", "TCP"),
resource.TestCheckResourceAttr("scaleway_security_group_rule.https", "port", "443"),
testAccCheckScalewaySecurityGroupRuleExists("scaleway_security_group_rule.http", &group),
testAccCheckScalewaySecurityGroupRuleAttributes("scaleway_security_group_rule.http", &group),
),
@ -93,7 +99,7 @@ func testAccCheckScalewaySecurityGroupRuleAttributes(n string, group *api.Scalew
return err
}
if rule.Rules.Action != "drop" {
if rule.Rules.Action != "accept" {
return fmt.Errorf("Wrong rule action")
}
if rule.Rules.Direction != "inbound" {
@ -149,10 +155,20 @@ resource "scaleway_security_group" "base" {
resource "scaleway_security_group_rule" "http" {
security_group = "${scaleway_security_group.base.id}"
action = "drop"
action = "accept"
direction = "inbound"
ip_range = "0.0.0.0/0"
protocol = "TCP"
port = 80
}
resource "scaleway_security_group_rule" "https" {
security_group = "${scaleway_security_group.base.id}"
action = "accept"
direction = "inbound"
ip_range = "0.0.0.0/0"
protocol = "TCP"
port = 443
}
`