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
resource "aws_network_acl" "acl-02363a11d7ec94225" {
vpc_id = "vpc-07d17e9a63e917701"
subnet_ids = ["subnet-044e67e5ccb2d56bb", "subnet-0e6e8fcd90b8a13de"]
ingress {
from_port = 0
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"
}
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"
}
Parameters
-
arn
optional computed - string -
egress
optional computed - set of object-
action
- string -
cidr_block
- string -
from_port
- number -
icmp_code
- number -
icmp_type
- number -
ipv6_cidr_block
- string -
protocol
- string -
rule_no
- number -
to_port
- number
-
-
id
optional computed - string -
ingress
optional computed - set of object-
action
- string -
cidr_block
- string -
from_port
- number -
icmp_code
- number -
icmp_type
- number -
ipv6_cidr_block
- string -
protocol
- string -
rule_no
- number -
to_port
- number
-
-
owner_id
optional computed - string -
subnet_ids
optional computed - set of string -
tags
optional - map from string to string -
vpc_id
required - string
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.
aws_default_vpc
Ensure to avoid using default VPC
It is better to define the own VPC and use it.
aws_network_acl_rule
Ensure your network ACL rule blocks unwanted inbound traffic
It is better to block unwanted inbound traffic.
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).
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.
aws_security_group
Ensure your security group blocks unwanted inbound traffic
It is better to block unwanted inbound traffic.
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
Type: AWS::EC2::NetworkAcl
Properties:
Tags:
- Key: Name
Value: elb1app1acl
VpcId:
Type: AWS::EC2::NetworkAcl
Properties:
Tags:
- Key: Name
Value: elbpubacl
VpcId:
Type: AWS::EC2::NetworkAcl
Properties:
VpcId: !Ref VPC
myNetworkAcl2:
Type: AWS::EC2::NetworkAcl
Properties:
Type: AWS::EC2::NetworkAcl
Properties:
VpcId: !Ref VPC
myNetworkAcl2:
Type: AWS::EC2::NetworkAcl
Properties:
Type: AWS::EC2::NetworkAcl
Properties:
VpcId: !Ref VPC
myNetworkAcl2:
Type: AWS::EC2::NetworkAcl
Properties:
"Type" : "AWS::EC2::NetworkAcl",
"Properties" : {
"VpcId" : { "Fn::ImportValue" : {"Fn::Sub" : "dev-staging-network-DevStagingVpc" } },
"Tags" : [ { "Key" : "Name", "Value" : "DevStaging Server Subnet A Network Acl" } ]
}
},
"Type" : "AWS::EC2::NetworkAcl",
"Properties" : {
"VpcId" : { "Fn::ImportValue" : {"Fn::Sub" : "prod-network-ProdVpc" } },
"Tags" : [ { "Key" : "Name", "Value" : "Prod Server Subnet A Network Acl" } ]
}
},
"Type": "AWS::EC2::NetworkAcl"
},
"acl0115e220fcc11a9ddassociation1": {
"Properties": {
"NetworkAclId": {
"Ref": "acl0115e220fcc11a9dd"
"Type":"AWS::EC2::NetworkAcl",
"Properties":{
"VpcId":{
"Ref":"vpc"
}
}
"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.