Merge pull request #8661 from nicolai86/fix/scaleway-security-groups

provider/scaleway: fix security_group_rule identification
This commit is contained in:
Paul Stack 2016-09-06 13:41:43 +01:00 committed by GitHub
commit fd541a41de
2 changed files with 28 additions and 4 deletions

View File

@ -89,8 +89,16 @@ func resourceScalewaySecurityGroupRuleCreate(d *schema.ResourceData, m interface
return err 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 { 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) d.SetId(rule.ID)
break break
} }

View File

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