Skip to content

Commit

Permalink
improve tests
Browse files Browse the repository at this point in the history
  • Loading branch information
loicbourgois committed Feb 3, 2020
1 parent 12a109c commit 28a6fdf
Showing 1 changed file with 47 additions and 1 deletion.
48 changes: 47 additions & 1 deletion scaleway/resource_instance_security_group_rules_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@ package scaleway

import (
"github.com/hashicorp/terraform-plugin-sdk/helper/resource"
"github.com/scaleway/scaleway-sdk-go/api/instance/v1"
"github.com/scaleway/scaleway-sdk-go/scw"
"testing"
)

Expand All @@ -22,6 +24,30 @@ func TestAccScalewayInstanceSecurityGroupRules(t *testing.T) {
Config: conf1,
Check: resource.ComposeTestCheckFunc(
testAccCheckScalewayInstanceSecurityGroupExists("scaleway_instance_security_group.sg01"),
testAccCheckScalewayInstanceSecurityGroupRuleMatch("scaleway_instance_security_group.sg01", 0, &instance.SecurityGroupRule{
Direction: instance.SecurityGroupRuleDirectionInbound,
IPRange: expandIPNet("0.0.0.0/0"),
DestPortFrom: scw.Uint32Ptr(80),
DestPortTo: nil,
Protocol: instance.SecurityGroupRuleProtocolTCP,
Action: instance.SecurityGroupRuleActionAccept,
}),

),
},
{
Config: conf2,
Check: resource.ComposeTestCheckFunc(
testAccCheckScalewayInstanceSecurityGroupExists("scaleway_instance_security_group.sg01"),
testAccCheckScalewayInstanceSecurityGroupRuleMatch("scaleway_instance_security_group.sg01", 0, &instance.SecurityGroupRule{
Direction: instance.SecurityGroupRuleDirectionInbound,
IPRange: expandIPNet("0.0.0.0/0"),
DestPortFrom: scw.Uint32Ptr(80),
DestPortTo: nil,
Protocol: instance.SecurityGroupRuleProtocolTCP,
Action: instance.SecurityGroupRuleActionAccept,
}),
resource.TestCheckResourceAttrPair("scaleway_instance_security_group.sg01", "id", "scaleway_instance_security_group_rules.sgrs01", "security_group_id"),
),
},
},
Expand All @@ -30,6 +56,24 @@ func TestAccScalewayInstanceSecurityGroupRules(t *testing.T) {

var conf1 = `
resource scaleway_instance_server s01 {
image = "ubuntu_bionic"
type = "DEV1-S"
security_group_id = scaleway_instance_security_group.sg01.id
}
resource scaleway_instance_security_group sg01 {
inbound_rule {
action = "accept"
port = 80
ip_range = "0.0.0.0/0"
}
}
`

var conf2 = `
resource scaleway_instance_server s01 {
image = "ubuntu_bionic"
type = "DEV1-S"
security_group_id = scaleway_instance_security_group.sg01.id
}
Expand All @@ -40,7 +84,9 @@ resource scaleway_instance_security_group sg01 {
resource scaleway_instance_security_group_rules sgrs01 {
security_group_id = scaleway_instance_security_group.sg01.id
inbound_rule {
address = scaleway_instance_server.s01.private_ip
action = "accept"
port = 80
ip_range = "0.0.0.0/0"
}
}
`
Expand Down

0 comments on commit 28a6fdf

Please sign in to comment.