AWS Amazon EC2 Rule

This page shows how to write Terraform and CloudFormation for Amazon EC2 Rule and write them securely.

aws_network_acl_rule (Terraform)

The Rule in Amazon EC2 can be configured in Terraform with the resource name aws_network_acl_rule. The following sections describe 4 examples of how to use the resource and its parameters.

Example Usage from GitHub

github-iconjrpradojr/terraform-aws-vpc-peering-inter-region
resource "aws_network_acl_rule" "in_accepter_public_from_requester" {
  provider       = aws.accepter
  count          = length(data.aws_subnet.requester.*.cidr_block)
  network_acl_id = tolist(data.aws_network_acls.accepter_public.ids)[0]
  rule_number    = 1000 + count.index
  egress         = false
github-iconvinovee/terraform-modules
resource "aws_network_acl_rule" "public_outbound" {
  count          = var.create_vpc && length(local.public_subnets) > 0 ? 1 : 0
  network_acl_id = aws_network_acl.public_nacl[count.index].id
  protocol       = "-1"
  rule_action    = "allow"
  rule_number    = 110
github-iconraghunadhpokkalath/2020-jun-project1-externals
resource "aws_network_acl_rule" "public_ingress_icmp_from_home_network" {
  # Allowing all ICMP from a trusted IP helps debugging networking issues.
  network_acl_id = aws_network_acl.public.id
  rule_number    = 100
  egress         = false
  protocol       = "icmp"
github-iconDNXLabs/terraform-aws-vpc-peering-inter-region
resource "aws_network_acl_rule" "in_accepter_public_from_requester" {
  provider       = aws.accepter
  count          = length(data.aws_subnet.requester.*.cidr_block)
  network_acl_id = tolist(data.aws_network_acls.accepter_public.ids)[0]
  rule_number    = 1000 + count.index
  egress         = false

Parameters

Explanation in Terraform Registry

Creates an entry (a rule) in a network ACL with the specified rule number.

NOTE on Network ACLs and Network ACL Rules: Terraform currently provides both a standalone Network ACL Rule resource and a Network ACL resource with rules defined in-line. At this time you cannot use a Network ACL with in-line rules in conjunction with any Network ACL Rule resources. Doing so will cause a conflict of rule settings and will overwrite rules.

AWS::EC2::NetworkAcl (CloudFormation)

The NetworkAcl in EC2 can be configured in CloudFormation with the resource name AWS::EC2::NetworkAcl. The following sections describe how to use the resource and its parameters.

Parameters

Explanation in CloudFormation Registry

Specifies a network ACL for your VPC.

Frequently asked questions

What is AWS Amazon EC2 Rule?

AWS Amazon EC2 Rule is a resource for Amazon EC2 of Amazon Web Service. Settings can be wrote in Terraform and CloudFormation.

Where can I find the example code for the AWS Amazon EC2 Rule?

For Terraform, the jrpradojr/terraform-aws-vpc-peering-inter-region, vinovee/terraform-modules and raghunadhpokkalath/2020-jun-project1-externals source code examples are useful. See the Terraform Example section for further details.