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: Properly handle ICMP code and type with IPv6 ICMP (protocol 58) #6264

Merged
merged 1 commit into from
Oct 30, 2018
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
2 changes: 1 addition & 1 deletion aws/network_acl_entry.go
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ func expandNetworkAclEntries(configured []interface{}, entryType string) ([]*ec2
}

// Specify additional required fields for ICMP
if p == 1 {
if p == 1 || p == 58 {
Copy link
Contributor

Choose a reason for hiding this comment

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

IMO this wants a comment/constant explaining what 1 and 58 represent

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 created a technical debt issue for this: #6302

e.IcmpTypeCode = &ec2.IcmpTypeCode{}
if v, ok := data["icmp_code"]; ok {
e.IcmpTypeCode.Code = aws.Int64(int64(v.(int)))
Expand Down
52 changes: 52 additions & 0 deletions aws/resource_aws_network_acl_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ import (
"github.com/aws/aws-sdk-go/aws"
"github.com/aws/aws-sdk-go/aws/awserr"
"github.com/aws/aws-sdk-go/service/ec2"
"github.com/hashicorp/terraform/helper/acctest"
"github.com/hashicorp/terraform/helper/resource"
"github.com/hashicorp/terraform/terraform"
)
Expand Down Expand Up @@ -443,6 +444,26 @@ func TestAccAWSNetworkAcl_ipv6Rules(t *testing.T) {
})
}

func TestAccAWSNetworkAcl_ipv6ICMPRules(t *testing.T) {
var networkAcl ec2.NetworkAcl
rName := acctest.RandomWithPrefix("tf-acc-test")
resourceName := "aws_network_acl.test"

resource.ParallelTest(t, resource.TestCase{
PreCheck: func() { testAccPreCheck(t) },
Providers: testAccProviders,
CheckDestroy: testAccCheckAWSNetworkAclDestroy,
Steps: []resource.TestStep{
{
Config: testAccAWSNetworkAclConfigIpv6ICMP(rName),
Check: resource.ComposeTestCheckFunc(
testAccCheckAWSNetworkAclExists(resourceName, &networkAcl),
),
},
},
})
}

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

Expand Down Expand Up @@ -615,6 +636,37 @@ func testAccCheckSubnetIsNotAssociatedWithAcl(acl string, subnet string) resourc
}
}

func testAccAWSNetworkAclConfigIpv6ICMP(rName string) string {
return fmt.Sprintf(`
resource "aws_vpc" "test" {
cidr_block = "10.1.0.0/16"

tags {
Name = %q
}
}

resource "aws_network_acl" "test" {
vpc_id = "${aws_vpc.test.id}"

ingress {
action = "allow"
from_port = 0
icmp_code = -1
icmp_type = -1
ipv6_cidr_block = "::/0"
protocol = 58
rule_no = 1
to_port = 0
}

tags {
Name = %q
}
}
`, rName, rName)
}

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