AWS Amazon EC2 Network ACL

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

aws_network_acl (Terraform)

The Network ACL in Amazon EC2 can be configured in Terraform with the resource name aws_network_acl. The following sections describe 3 examples of how to use the resource and its parameters.

Example Usage from GitHub

nacl.tf#L1
resource "aws_network_acl" "acl-02363a11d7ec94225" {
    vpc_id     = "vpc-07d17e9a63e917701"
    subnet_ids = ["subnet-044e67e5ccb2d56bb", "subnet-0e6e8fcd90b8a13de"]

    ingress {
        from_port  = 0
NACL.tf#L2
resource "aws_network_acl" "pub_az1_nacl" {
  vpc_id     = aws_vpc.green_vpc.id
  subnet_ids = [aws_subnet.pub_az1_subnet.id]
  tags = {
    Name = "Public-AZ1-NACL"
  }
NACL.tf#L2
resource "aws_network_acl" "pub_az1_nacl" {
  vpc_id     = aws_vpc.green_vpc.id
  subnet_ids = [aws_subnet.pub_az1_subnet.id]
  tags = {
    Name = "Public-AZ1-NACL"
  }

Review your Terraform file for AWS best practices

Shisho Cloud, our free checker to make sure your Terraform configuration follows best practices, is available (beta).

Parameters

Explanation in Terraform Registry

Provides an network ACL resource. You might set up network ACLs with rules similar to your security groups in order to add an additional layer of security to your VPC.

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.

Tips: Best Practices for The Other AWS Amazon EC2 Resources

In addition to the aws_default_vpc, AWS Amazon EC2 has the other resources that should be configured for security reasons. Please check some examples of those resources and precautions.

risk-label

aws_default_vpc

Ensure to avoid using default VPC

It is better to define the own VPC and use it.

risk-label

aws_network_acl_rule

Ensure your network ACL rule blocks unwanted inbound traffic

It is better to block unwanted inbound traffic.

risk-label

aws_ebs_volume

Ensure to use a customer-managed key for EBS volume encryption

It is better to use a customer-managed key for EBS volume encryption. It can be gain more control over the encryption by using customer-managed keys (CMK).

risk-label

aws_instance

Ensure to avoid storing AWS access keys in user data

It is better to avoid storing AWS access keys in user data. `aws_iam_instance_profile` could be used instead.

risk-label

aws_security_group

Ensure your security group blocks unwanted inbound traffic

It is better to block unwanted inbound traffic.

Review your AWS Amazon EC2 settings

In addition to the above, there are other security points you should be aware of making sure that your .tf files are protected in Shisho Cloud.

AWS::EC2::NetworkAcl (CloudFormation)

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

Example Usage from GitHub

cfn.yml#L303
    Type: AWS::EC2::NetworkAcl
    Properties:
       Tags:
         - Key: Name
           Value: elb1app1acl
       VpcId:
Acl.yml#L17
    Type: AWS::EC2::NetworkAcl
    Properties:
       Tags:
         - Key: Name
           Value: elbpubacl
       VpcId:
ec2_networkaclentry_reused_ports.yml#L11
    Type: AWS::EC2::NetworkAcl
    Properties:
      VpcId: !Ref VPC
  myNetworkAcl2:
    Type: AWS::EC2::NetworkAcl
    Properties:
ec2_networkaclentry_duplicate_rule_numbers.yml#L11
    Type: AWS::EC2::NetworkAcl
    Properties:
      VpcId: !Ref VPC
  myNetworkAcl2:
    Type: AWS::EC2::NetworkAcl
    Properties:
ec2_networkaclentry_egress_ingress_reused_ports.yml#L11
    Type: AWS::EC2::NetworkAcl
    Properties:
      VpcId: !Ref VPC
  myNetworkAcl2:
    Type: AWS::EC2::NetworkAcl
    Properties:
dev-staging-network-acl.json#L7
            "Type" : "AWS::EC2::NetworkAcl",
            "Properties" : {
               "VpcId" :  { "Fn::ImportValue" : {"Fn::Sub" : "dev-staging-network-DevStagingVpc" } },
               "Tags" : [ { "Key" : "Name", "Value" : "DevStaging Server Subnet A Network Acl" } ]
            }
         },
prod-network-acl.json#L7
            "Type" : "AWS::EC2::NetworkAcl",
            "Properties" : {
               "VpcId" :  { "Fn::ImportValue" : {"Fn::Sub" : "prod-network-ProdVpc" } },
               "Tags" : [ { "Key" : "Name", "Value" : "Prod Server Subnet A Network Acl" } ]
            }
         },
vpc08bf684639ded31d9network_acls.json#L68
            "Type": "AWS::EC2::NetworkAcl"
        },
        "acl0115e220fcc11a9ddassociation1": {
            "Properties": {
                "NetworkAclId": {
                    "Ref": "acl0115e220fcc11a9dd"
02createAcls.json#L44
            "Type":"AWS::EC2::NetworkAcl",
            "Properties":{
                "VpcId":{
                    "Ref":"vpc"
                }
            }
BaselineSecurity.json#L12
            "Type": "AWS::EC2::NetworkAcl",
            "Properties": {
                "VpcId": {
                    "Fn::ImportValue": {"Fn::Sub": "${pNetworkStackName}-VPCID"}
                }
            }

Parameters

Explanation in CloudFormation Registry

Specifies a network ACL for your VPC.

Frequently asked questions

What is AWS Amazon EC2 Network ACL?

AWS Amazon EC2 Network ACL 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 Network ACL?

For Terraform, the tappoflw/tappo1, DianaMayesCloud/Project-v1 and DianaMayesCloud/Project-v2 source code examples are useful. See the Terraform Example section for further details.

For CloudFormation, the vinithacejojohn/cfn_ELB, vinithacejojohn/cfn_ELB and stelligent/cfn_nag source code examples are useful. See the CloudFormation Example section for further details.