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

Configure network ACLs for public/private/intra subnets #174

Closed
wants to merge 13 commits into from
31 changes: 31 additions & 0 deletions examples/network-acls/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
# Simple VPC with Network ACLs

Configuration in this directory creates set of VPC resources along with network ACLs for public subnets.

There is a public and private subnet created per availability zone in addition to single NAT Gateway shared between all 3 availability zones. Network ACL rules for inbound and outbound traffic are defined.

## Usage

To run this example you need to execute:

```bash
$ terraform init
$ terraform plan
$ terraform apply
```

Note that this example may create resources which can cost money (AWS Elastic IP, for example). Run `terraform destroy` when you don't need these resources.

<!-- BEGINNING OF PRE-COMMIT-TERRAFORM DOCS HOOK -->

## Outputs

| Name | Description |
|------|-------------|
| nat_public_ips | NAT gateways |
| private_subnets | Subnets |
| public_subnets | List of IDs of public subnets |
| vpc_cidr_block | CIDR blocks |
| vpc_id | VPC |

<!-- END OF PRE-COMMIT-TERRAFORM DOCS HOOK -->
143 changes: 143 additions & 0 deletions examples/network-acls/main.tf
Original file line number Diff line number Diff line change
@@ -0,0 +1,143 @@
provider "aws" {
region = "eu-west-1"
}

module "vpc" {
source = "../../"

name = "network-acls-example"

cidr = "10.0.0.0/16"

azs = ["eu-west-1a", "eu-west-1b", "eu-west-1c"]
private_subnets = ["10.0.1.0/24", "10.0.2.0/24", "10.0.3.0/24"]
public_subnets = ["10.0.101.0/24", "10.0.102.0/24", "10.0.103.0/24"]

public_inbound_acl_rules = "${concat(local.network_acls["default_inbound"], local.network_acls["public_inbound"])}"
public_outbound_acl_rules = "${concat(local.network_acls["default_outbound"], local.network_acls["public_outbound"])}"

assign_generated_ipv6_cidr_block = true

enable_nat_gateway = true
single_nat_gateway = true

public_subnet_tags = {
Name = "overridden-name-public"
}

tags = {
Owner = "user"
Environment = "dev"
}

vpc_tags = {
Name = "vpc-name"
}
}

locals {
network_acls = {
default_inbound = [
{
rule_number = 900
rule_action = "allow"
from_port = 1024
to_port = 65535
protocol = "tcp"
cidr_block = "0.0.0.0/0"
description = "Allow inbound return traffic from hosts"
},
]

default_outbound = [
{
rule_number = 900
rule_action = "allow"
from_port = 32768
to_port = 65535
protocol = "tcp"
cidr_block = "0.0.0.0/0"
description = "Allows outbound responses to clients"
},
]

public_inbound = [
{
rule_number = 100
rule_action = "allow"
from_port = 80
to_port = 80
protocol = "tcp"
cidr_block = "0.0.0.0/0"
description = "Allow inbound HTTP traffic from any IPv4 address"
},
{
rule_number = 110
rule_action = "allow"
from_port = 443
to_port = 443
protocol = "tcp"
cidr_block = "0.0.0.0/0"
description = "Allow inbound HTTPS traffic from any IPv4 address"
},
{
rule_number = 120
rule_action = "allow"
from_port = 22
to_port = 22
protocol = "tcp"
cidr_block = "0.0.0.0/0"
description = "Allow inbound SSH traffic from any IPv4 address"
},
{
rule_number = 130
rule_action = "allow"
from_port = 3389
to_port = 3389
protocol = "tcp"
cidr_block = "0.0.0.0/0"
description = "Allow inbound RDP traffic from any IPv4 address"
},
]

public_outbound = [
{
rule_number = 100
rule_action = "allow"
from_port = 80
to_port = 80
protocol = "tcp"
cidr_block = "0.0.0.0/0"
description = "Allow outbound HTTP traffic from the subnet to the Internet"
},
{
rule_number = 110
rule_action = "allow"
from_port = 443
to_port = 443
protocol = "tcp"
cidr_block = "0.0.0.0/0"
description = "Allow outbound HTTPS traffic from the subnet to the Internet"
},
{
rule_number = 120
rule_action = "allow"
from_port = 1433
to_port = 1433
protocol = "tcp"
cidr_block = "10.0.100.0/22"
description = "Allow outbound MS SQL access to database servers in the private subnet"
},

{
rule_number = 130
rule_action = "allow"
from_port = 22
to_port = 22
protocol = "tcp"
cidr_block = "10.0.100.0/22"
description = "Allows outbound SSH access to instances in your private subnet"
},
]
}
}
33 changes: 33 additions & 0 deletions examples/network-acls/outputs.tf
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
# VPC
output "vpc_id" {
description = "The ID of the VPC"
value = "${module.vpc.vpc_id}"
}

# CIDR blocks
output "vpc_cidr_block" {
description = "The CIDR block of the VPC"
value = ["${module.vpc.vpc_cidr_block}"]
}

//output "vpc_ipv6_cidr_block" {
// description = "The IPv6 CIDR block"
// value = ["${module.vpc.vpc_ipv6_cidr_block}"]
//}

# Subnets
output "private_subnets" {
description = "List of IDs of private subnets"
value = ["${module.vpc.private_subnets}"]
}

output "public_subnets" {
description = "List of IDs of public subnets"
value = ["${module.vpc.public_subnets}"]
}

# NAT gateways
output "nat_public_ips" {
description = "List of public Elastic IPs created for AWS NAT Gateway"
value = ["${module.vpc.nat_public_ips}"]
}
Loading