-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathvpc.tf
More file actions
55 lines (46 loc) · 1.58 KB
/
Copy pathvpc.tf
File metadata and controls
55 lines (46 loc) · 1.58 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
module "vpc" {
source = "terraform-aws-modules/vpc/aws"
version = "~> 5.7"
name = "${var.project_name}-vpc"
cidr = var.vpc_cidr
azs = ["${var.aws_region}a", "${var.aws_region}b"]
private_subnets = [cidrsubnet(var.vpc_cidr, 4, 0), cidrsubnet(var.vpc_cidr, 4, 1)]
public_subnets = [cidrsubnet(var.vpc_cidr, 4, 2), cidrsubnet(var.vpc_cidr, 4, 3)]
# Lambda workers + scheduler sit in private subnets; a single NAT gateway
# gives them outbound access (ECR pulls, AWS APIs) without public IPs.
enable_nat_gateway = true
single_nat_gateway = true
enable_dns_hostnames = true
enable_dns_support = true
}
# Interface endpoints let the scheduler and workers reach ECR/CloudWatch/STS
# without routing every call through the NAT gateway.
locals {
interface_endpoints = [
"ecr.api",
"ecr.dkr",
"logs",
"sts",
]
}
resource "aws_vpc_endpoint" "s3" {
vpc_id = module.vpc.vpc_id
service_name = "com.amazonaws.${var.aws_region}.s3"
vpc_endpoint_type = "Gateway"
route_table_ids = module.vpc.private_route_table_ids
tags = {
Name = "${var.project_name}-s3-endpoint"
}
}
resource "aws_vpc_endpoint" "interface" {
for_each = toset(local.interface_endpoints)
vpc_id = module.vpc.vpc_id
service_name = "com.amazonaws.${var.aws_region}.${each.value}"
vpc_endpoint_type = "Interface"
subnet_ids = module.vpc.private_subnets
security_group_ids = [aws_security_group.vpc_endpoints.id]
private_dns_enabled = true
tags = {
Name = "${var.project_name}-${each.value}-endpoint"
}
}