Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

resource/aws_network_acl: Make action in ingress / egress case insensitive #1000

Merged
merged 1 commit into from
Jun 29, 2017
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 14 additions & 1 deletion aws/resource_aws_network_acl.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import (
"log"
"sort"
"strconv"
"strings"
"time"

"github.com/aws/aws-sdk-go/aws"
Expand Down Expand Up @@ -71,6 +72,12 @@ func resourceAwsNetworkAcl() *schema.Resource {
"action": {
Type: schema.TypeString,
Required: true,
DiffSuppressFunc: func(k, old, new string, d *schema.ResourceData) bool {
if strings.ToLower(old) == strings.ToLower(new) {
return true
}
return false
},
},
"protocol": {
Type: schema.TypeString,
Expand Down Expand Up @@ -118,6 +125,12 @@ func resourceAwsNetworkAcl() *schema.Resource {
"action": {
Type: schema.TypeString,
Required: true,
DiffSuppressFunc: func(k, old, new string, d *schema.ResourceData) bool {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This diff suppress is fairly common. Worth splitting it out into a core level function?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I agree it's common - one thing i saw in the committers channel the other day is that sometimes it's preferred to copy small pieces of code like this rather than need to vendor them - thoughts?

if strings.ToLower(old) == strings.ToLower(new) {
return true
}
return false
},
},
"protocol": {
Type: schema.TypeString,
Expand Down Expand Up @@ -528,7 +541,7 @@ func resourceAwsNetworkAclEntryHash(v interface{}) int {
buf.WriteString(fmt.Sprintf("%d-", m["from_port"].(int)))
buf.WriteString(fmt.Sprintf("%d-", m["to_port"].(int)))
buf.WriteString(fmt.Sprintf("%d-", m["rule_no"].(int)))
buf.WriteString(fmt.Sprintf("%s-", m["action"].(string)))
buf.WriteString(fmt.Sprintf("%s-", strings.ToLower(m["action"].(string))))

// The AWS network ACL API only speaks protocol numbers, and that's
// all we store. Never hash a protocol name.
Expand Down
46 changes: 46 additions & 0 deletions aws/resource_aws_network_acl_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -140,6 +140,25 @@ func TestAccAWSNetworkAcl_OnlyIngressRules_update(t *testing.T) {
})
}

func TestAccAWSNetworkAcl_CaseSensitivityNoChanges(t *testing.T) {
var networkAcl ec2.NetworkAcl

resource.Test(t, resource.TestCase{
PreCheck: func() { testAccPreCheck(t) },
IDRefreshName: "aws_network_acl.foos",
Providers: testAccProviders,
CheckDestroy: testAccCheckAWSNetworkAclDestroy,
Steps: []resource.TestStep{
{
Config: testAccAWSNetworkAclCaseSensitiveConfig,
Check: resource.ComposeAggregateTestCheckFunc(
testAccCheckAWSNetworkAclExists("aws_network_acl.foos", &networkAcl),
),
},
},
})
}

func TestAccAWSNetworkAcl_OnlyEgressRules(t *testing.T) {
var networkAcl ec2.NetworkAcl

Expand Down Expand Up @@ -522,6 +541,33 @@ resource "aws_network_acl" "foos" {
subnet_ids = ["${aws_subnet.blob.id}"]
}
`

const testAccAWSNetworkAclCaseSensitiveConfig = `
resource "aws_vpc" "foo" {
cidr_block = "10.1.0.0/16"
tags {
Name = "TestAccAWSNetworkAcl_OnlyIngressRules"
}
}
resource "aws_subnet" "blob" {
cidr_block = "10.1.1.0/24"
vpc_id = "${aws_vpc.foo.id}"
map_public_ip_on_launch = true
}
resource "aws_network_acl" "foos" {
vpc_id = "${aws_vpc.foo.id}"
ingress = {
protocol = "tcp"
rule_no = 1
action = "Allow"
cidr_block = "10.2.0.0/18"
from_port = 0
to_port = 22
}
subnet_ids = ["${aws_subnet.blob.id}"]
}
`

const testAccAWSNetworkAclIngressConfigChange = `
resource "aws_vpc" "foo" {
cidr_block = "10.1.0.0/16"
Expand Down