Skip to content

Commit

Permalink
Merge pull request #2454 from enm10k/master
Browse files Browse the repository at this point in the history
resource/aws_network_acl_rule: Fix DiffSuppressFunc
  • Loading branch information
bflad committed Oct 25, 2018
2 parents 301344e + 757fa20 commit 5873d7a
Show file tree
Hide file tree
Showing 2 changed files with 71 additions and 3 deletions.
11 changes: 8 additions & 3 deletions aws/resource_aws_network_acl_rule.go
Original file line number Diff line number Diff line change
Expand Up @@ -42,10 +42,15 @@ func resourceAwsNetworkAclRule() *schema.Resource {
Required: true,
ForceNew: true,
DiffSuppressFunc: func(k, old, new string, d *schema.ResourceData) bool {
if old == "all" && new == "-1" || old == "-1" && new == "all" {
return true
pi := protocolIntegers()
if val, ok := pi[old]; ok {
old = strconv.Itoa(val)
}
return false
if val, ok := pi[new]; ok {
new = strconv.Itoa(val)
}

return old == new
},
},
"rule_action": {
Expand Down
63 changes: 63 additions & 0 deletions aws/resource_aws_network_acl_rule_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -85,6 +85,25 @@ func TestAccAWSNetworkAclRule_allProtocol(t *testing.T) {
})
}

func TestAccAWSNetworkAclRule_tcpProtocol(t *testing.T) {

resource.Test(t, resource.TestCase{
PreCheck: func() { testAccPreCheck(t) },
Providers: testAccProviders,
CheckDestroy: testAccCheckAWSNetworkAclRuleDestroy,
Steps: []resource.TestStep{
{
Config: testAccAWSNetworkAclRuleTcpProtocolConfig,
ExpectNonEmptyPlan: false,
},
{
Config: testAccAWSNetworkAclRuleTcpProtocolConfigNoRealUpdate,
ExpectNonEmptyPlan: false,
},
},
})
}

func TestResourceAWSNetworkAclRule_validateICMPArgumentValue(t *testing.T) {
type testCases struct {
Value string
Expand Down Expand Up @@ -371,6 +390,28 @@ resource "aws_network_acl_rule" "baz" {
}
`

const testAccAWSNetworkAclRuleTcpProtocolConfigNoRealUpdate = `
resource "aws_vpc" "foo" {
cidr_block = "10.3.0.0/16"
tags {
Name = "testAccAWSNetworkAclRuleTcpProtocolConfigNoRealUpdate"
}
}
resource "aws_network_acl" "bar" {
vpc_id = "${aws_vpc.foo.id}"
}
resource "aws_network_acl_rule" "baz" {
network_acl_id = "${aws_network_acl.bar.id}"
rule_number = 150
egress = false
protocol = "tcp"
rule_action = "allow"
cidr_block = "0.0.0.0/0"
from_port = 22
to_port = 22
}
`

const testAccAWSNetworkAclRuleAllProtocolConfig = `
resource "aws_vpc" "foo" {
cidr_block = "10.3.0.0/16"
Expand Down Expand Up @@ -398,6 +439,28 @@ resource "aws_network_acl_rule" "baz" {
}
`

const testAccAWSNetworkAclRuleTcpProtocolConfig = `
resource "aws_vpc" "foo" {
cidr_block = "10.3.0.0/16"
tags {
Name = "testAccAWSNetworkAclRuleTcpProtocolConfig"
}
}
resource "aws_network_acl" "bar" {
vpc_id = "${aws_vpc.foo.id}"
}
resource "aws_network_acl_rule" "baz" {
network_acl_id = "${aws_network_acl.bar.id}"
rule_number = 150
egress = false
protocol = "6"
rule_action = "allow"
cidr_block = "0.0.0.0/0"
from_port = 22
to_port = 22
}
`

const testAccAWSNetworkAclRuleIpv6Config = `
resource "aws_vpc" "foo" {
cidr_block = "10.3.0.0/16"
Expand Down

0 comments on commit 5873d7a

Please sign in to comment.