Skip to content

Commit 93a6f40

Browse files
feat: add vpc endpoint policies to supported services (#601)
* feat: add vpc endpoint policies to supported services * chore: empty commit to re-run * chore: Run pre-commit terraform_docs hook Co-authored-by: Anton Babenko <[email protected]>
1 parent bbfd33e commit 93a6f40

File tree

7 files changed

+394
-93
lines changed

7 files changed

+394
-93
lines changed

README.md

Lines changed: 67 additions & 33 deletions
Large diffs are not rendered by default.

examples/complete-vpc/README.md

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,9 @@ Note that this example may create resources which can cost money (AWS Elastic IP
4040

4141
| Name |
4242
|------|
43-
| [aws_security_group](https://registry.terraform.io/providers/hashicorp/aws/3.10/docs/data-sources/security_group) |
43+
| [aws_iam_policy_document](https://registry.terraform.io/providers/hashicorp/aws/latest/docs/data-sources/iam_policy_document) |
44+
| [aws_security_group](https://registry.terraform.io/providers/hashicorp/aws/latest/docs/data-sources/security_group) |
45+
| [aws_vpc_endpoint](https://registry.terraform.io/providers/hashicorp/aws/latest/docs/data-sources/vpc_endpoint) |
4446

4547
## Inputs
4648

examples/complete-vpc/main.tf

Lines changed: 50 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -59,6 +59,7 @@ module "vpc" {
5959

6060
# VPC endpoint for DynamoDB
6161
enable_dynamodb_endpoint = true
62+
dynamodb_endpoint_policy = data.aws_iam_policy_document.dynamodb_endpoint_policy.json
6263

6364
# VPC endpoint for SSM
6465
enable_ssm_endpoint = true
@@ -77,6 +78,7 @@ module "vpc" {
7778

7879
# VPC Endpoint for EC2
7980
enable_ec2_endpoint = true
81+
ec2_endpoint_policy = data.aws_iam_policy_document.generic_endpoint_policy.json
8082
ec2_endpoint_private_dns_enabled = true
8183
ec2_endpoint_security_group_ids = [data.aws_security_group.default.id]
8284

@@ -87,11 +89,13 @@ module "vpc" {
8789

8890
# VPC Endpoint for ECR API
8991
enable_ecr_api_endpoint = true
92+
ecr_api_endpoint_policy = data.aws_iam_policy_document.generic_endpoint_policy.json
9093
ecr_api_endpoint_private_dns_enabled = true
9194
ecr_api_endpoint_security_group_ids = [data.aws_security_group.default.id]
9295

9396
# VPC Endpoint for ECR DKR
9497
enable_ecr_dkr_endpoint = true
98+
ecr_dkr_endpoint_policy = data.aws_iam_policy_document.generic_endpoint_policy.json
9599
ecr_dkr_endpoint_private_dns_enabled = true
96100
ecr_dkr_endpoint_security_group_ids = [data.aws_security_group.default.id]
97101

@@ -142,3 +146,49 @@ module "vpc" {
142146
Endpoint = "true"
143147
}
144148
}
149+
150+
# Data source used to avoid race condition
151+
data "aws_vpc_endpoint" "dynamodb" {
152+
vpc_id = module.vpc.vpc_id
153+
service_name = "com.amazonaws.eu-west-1.dynamodb"
154+
}
155+
156+
data "aws_iam_policy_document" "dynamodb_endpoint_policy" {
157+
statement {
158+
effect = "Deny"
159+
actions = ["dynamodb:*"]
160+
resources = ["*"]
161+
162+
principals {
163+
type = "*"
164+
identifiers = ["*"]
165+
}
166+
167+
condition {
168+
test = "StringNotEquals"
169+
variable = "aws:sourceVpce"
170+
171+
values = [data.aws_vpc_endpoint.dynamodb.id]
172+
}
173+
}
174+
}
175+
176+
data "aws_iam_policy_document" "generic_endpoint_policy" {
177+
statement {
178+
effect = "Deny"
179+
actions = ["*"]
180+
resources = ["*"]
181+
182+
principals {
183+
type = "*"
184+
identifiers = ["*"]
185+
}
186+
187+
condition {
188+
test = "StringNotEquals"
189+
variable = "aws:sourceVpce"
190+
191+
values = [data.aws_vpc_endpoint.dynamodb.id]
192+
}
193+
}
194+
}

examples/ipv6/README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,7 @@ Note that this example may create resources which can cost money (AWS Elastic IP
3838

3939
| Name |
4040
|------|
41-
| [aws_availability_zones](https://registry.terraform.io/providers/hashicorp/aws/2.70/docs/data-sources/availability_zones) |
41+
| [aws_availability_zones](https://registry.terraform.io/providers/hashicorp/aws/latest/docs/data-sources/availability_zones) |
4242

4343
## Inputs
4444

examples/vpc-flow-logs/README.md

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -47,12 +47,12 @@ Note that this example may create resources which can cost money (AWS Elastic IP
4747

4848
| Name |
4949
|------|
50-
| [aws_cloudwatch_log_group](https://registry.terraform.io/providers/hashicorp/aws/2.70/docs/resources/cloudwatch_log_group) |
51-
| [aws_iam_policy_document](https://registry.terraform.io/providers/hashicorp/aws/2.70/docs/data-sources/iam_policy_document) |
52-
| [aws_iam_policy](https://registry.terraform.io/providers/hashicorp/aws/2.70/docs/resources/iam_policy) |
53-
| [aws_iam_role_policy_attachment](https://registry.terraform.io/providers/hashicorp/aws/2.70/docs/resources/iam_role_policy_attachment) |
54-
| [aws_iam_role](https://registry.terraform.io/providers/hashicorp/aws/2.70/docs/resources/iam_role) |
55-
| [random_pet](https://registry.terraform.io/providers/hashicorp/random/2/docs/resources/pet) |
50+
| [aws_cloudwatch_log_group](https://registry.terraform.io/providers/hashicorp/aws/latest/docs/resources/cloudwatch_log_group) |
51+
| [aws_iam_policy](https://registry.terraform.io/providers/hashicorp/aws/latest/docs/resources/iam_policy) |
52+
| [aws_iam_policy_document](https://registry.terraform.io/providers/hashicorp/aws/latest/docs/data-sources/iam_policy_document) |
53+
| [aws_iam_role](https://registry.terraform.io/providers/hashicorp/aws/latest/docs/resources/iam_role) |
54+
| [aws_iam_role_policy_attachment](https://registry.terraform.io/providers/hashicorp/aws/latest/docs/resources/iam_role_policy_attachment) |
55+
| [random_pet](https://registry.terraform.io/providers/hashicorp/random/latest/docs/resources/pet) |
5656

5757
## Inputs
5858

0 commit comments

Comments
 (0)