Skip to content

Commit c8bde3c

Browse files
chore: Add dedicated NACL rules to intra subnets in example with VPC and S3 Gateway endpoint (#367)
Co-authored-by: Anton Babenko <[email protected]>
1 parent a6e4480 commit c8bde3c

File tree

2 files changed

+34
-0
lines changed

2 files changed

+34
-0
lines changed

examples/with-vpc-s3-endpoint/README.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -48,6 +48,7 @@ Note that this example may create resources which cost money. Run `terraform des
4848
| Name | Type |
4949
|------|------|
5050
| [random_pet.this](https://registry.terraform.io/providers/hashicorp/random/latest/docs/resources/pet) | resource |
51+
| [aws_ec2_managed_prefix_list.this](https://registry.terraform.io/providers/hashicorp/aws/latest/docs/data-sources/ec2_managed_prefix_list) | data source |
5152
| [aws_iam_policy_document.bucket](https://registry.terraform.io/providers/hashicorp/aws/latest/docs/data-sources/iam_policy_document) | data source |
5253
| [aws_iam_policy_document.endpoint](https://registry.terraform.io/providers/hashicorp/aws/latest/docs/data-sources/iam_policy_document) | data source |
5354
| [aws_region.current](https://registry.terraform.io/providers/hashicorp/aws/latest/docs/data-sources/region) | data source |

examples/with-vpc-s3-endpoint/main.tf

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -55,6 +55,10 @@ resource "random_pet" "this" {
5555
length = 2
5656
}
5757

58+
data "aws_ec2_managed_prefix_list" "this" {
59+
name = "com.amazonaws.${data.aws_region.current.name}.s3"
60+
}
61+
5862
module "vpc" {
5963
source = "terraform-aws-modules/vpc/aws"
6064
version = "~> 3.0"
@@ -66,6 +70,35 @@ module "vpc" {
6670

6771
# Intra subnets are designed to have no Internet access via NAT Gateway.
6872
intra_subnets = ["10.0.1.0/24", "10.0.2.0/24", "10.0.3.0/24"]
73+
74+
intra_dedicated_network_acl = true
75+
intra_inbound_acl_rules = concat(
76+
# NACL rule for local traffic
77+
[
78+
{
79+
rule_number = 100
80+
rule_action = "allow"
81+
from_port = 0
82+
to_port = 0
83+
protocol = "-1"
84+
cidr_block = "10.0.0.0/16"
85+
},
86+
],
87+
# NACL rules for the response traffic from addresses in the AWS S3 prefix list
88+
[for k, v in zipmap(
89+
range(length(data.aws_ec2_managed_prefix_list.this.entries[*].cidr)),
90+
data.aws_ec2_managed_prefix_list.this.entries[*].cidr
91+
) :
92+
{
93+
rule_number = 200 + k
94+
rule_action = "allow"
95+
from_port = 1024
96+
to_port = 65535
97+
protocol = "tcp"
98+
cidr_block = v
99+
}
100+
]
101+
)
69102
}
70103

71104
module "vpc_endpoints" {

0 commit comments

Comments
 (0)