From 9f598a68afca1c871aa8e40d13f5a235e8c70438 Mon Sep 17 00:00:00 2001 From: Raphael Randschau Date: Mon, 5 Sep 2016 16:29:18 +0200 Subject: [PATCH] provider/scaleway: fix security_group_rule identification --- .../resource_scaleway_security_group_rule.go | 10 ++++++++- ...ource_scaleway_security_group_rule_test.go | 22 ++++++++++++++++--- 2 files changed, 28 insertions(+), 4 deletions(-) diff --git a/builtin/providers/scaleway/resource_scaleway_security_group_rule.go b/builtin/providers/scaleway/resource_scaleway_security_group_rule.go index d79070bfe..03d29a95f 100644 --- a/builtin/providers/scaleway/resource_scaleway_security_group_rule.go +++ b/builtin/providers/scaleway/resource_scaleway_security_group_rule.go @@ -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 } diff --git a/builtin/providers/scaleway/resource_scaleway_security_group_rule_test.go b/builtin/providers/scaleway/resource_scaleway_security_group_rule_test.go index aeafa41b6..bedebe971 100644 --- a/builtin/providers/scaleway/resource_scaleway_security_group_rule_test.go +++ b/builtin/providers/scaleway/resource_scaleway_security_group_rule_test.go @@ -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 +} `