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

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/resource_aws_network_acl_rule.go
Original file line number Diff line number Diff line change
Expand Up @@ -139,7 +139,7 @@ func resourceAwsNetworkAclRuleCreate(d *schema.ResourceData, meta interface{}) e

// Specify additional required fields for ICMP. For the list
// of ICMP codes and types, see: https://www.iana.org/assignments/icmp-parameters/icmp-parameters.xhtml
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.

whilst this is clear in that there's a test for it - IMO we want a comment/constant to explain what these are so it doesn't require a lookup

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 hope #6302 covers this here as well. Probably best to solve this "globally". 😄

params.IcmpTypeCode = &ec2.IcmpTypeCode{}
if v, ok := d.GetOk("icmp_type"); ok {
icmpType, err := strconv.Atoi(v.(string))
Expand Down
53 changes: 53 additions & 0 deletions aws/resource_aws_network_acl_rule_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,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 @@ -66,6 +67,26 @@ func TestAccAWSNetworkAclRule_ipv6(t *testing.T) {
})
}

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

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

func TestAccAWSNetworkAclRule_allProtocol(t *testing.T) {

resource.ParallelTest(t, resource.TestCase{
Expand Down Expand Up @@ -487,3 +508,35 @@ resource "aws_network_acl_rule" "baz" {
to_port = 22
}
`

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

tags {
Name = %q
}
}

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

tags {
Name = %q
}
}

resource "aws_network_acl_rule" "test" {
from_port = -1
icmp_code = -1
icmp_type = -1
ipv6_cidr_block = "::/0"
network_acl_id = "${aws_network_acl.test.id}"
protocol = 58
rule_action = "allow"
rule_number = 150
to_port = -1
}
`, rName, rName)
}