Skip to content

Commit 6961558

Browse files
authored
Merge pull request #113 from kookmin-sw/mhsong-dev
add ecr vpc endpoint
2 parents 986aa5d + e6d26e0 commit 6961558

File tree

2 files changed

+61
-1
lines changed

2 files changed

+61
-1
lines changed

IaC/kubernetes_cluster/main.tf

+1-1
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@ module "vpc" {
2828
source = "./vpc"
2929
vpc_name = "${var.main_suffix}-k8s-vpc"
3030
vpc_cidr = var.vpc_cidr
31-
current_region = data.aws_region.current_region.id
31+
current_region = data.aws_region.current_region.name
3232
region_azs = data.aws_availability_zones.region_azs.names
3333
public_subnet_cidrs = var.public_subnet_cidrs
3434
private_subnet_cidrs = var.private_subnet_cidrs

IaC/kubernetes_cluster/vpc/vpc.tf

+60
Original file line numberDiff line numberDiff line change
@@ -106,4 +106,64 @@ resource "aws_route_table_association" "private_subnet_route_associations" {
106106
count = length(var.private_subnet_cidrs)
107107
subnet_id = aws_subnet.private_subnets[count.index].id
108108
route_table_id = aws_route_table.private_route_tables[count.index].id
109+
}
110+
111+
### vpc endpoint
112+
resource "aws_security_group" "vpc_endpoint_sg" {
113+
ingress = [{
114+
cidr_blocks = [aws_vpc.vpc.cidr_block]
115+
description = "same vpc allow"
116+
from_port = 443
117+
to_port = 443
118+
protocol = "tcp"
119+
ipv6_cidr_blocks = []
120+
prefix_list_ids = []
121+
security_groups = []
122+
self = false
123+
}]
124+
125+
egress = [{
126+
cidr_blocks = ["0.0.0.0/0"]
127+
description = "alow all outbound"
128+
from_port = 0
129+
to_port = 0
130+
protocol = "-1"
131+
ipv6_cidr_blocks = []
132+
prefix_list_ids = []
133+
security_groups = []
134+
self = false
135+
}]
136+
vpc_id = aws_vpc.vpc.id
137+
138+
tags = {
139+
"Name" = "${var.vpc_name}-vpc-endpoint-sg"
140+
}
141+
}
142+
143+
resource "aws_vpc_endpoint" "ecr-api" {
144+
vpc_id = aws_vpc.vpc.id
145+
service_name = "com.amazonaws.${var.current_region}.ecr.api"
146+
vpc_endpoint_type = "Interface"
147+
148+
security_group_ids = [
149+
aws_security_group.vpc_endpoint_sg.id,
150+
]
151+
152+
subnet_ids = tolist(aws_subnet.private_subnets[*].id)
153+
154+
private_dns_enabled = true
155+
}
156+
157+
resource "aws_vpc_endpoint" "ecr-dkr" {
158+
vpc_id = aws_vpc.vpc.id
159+
service_name = "com.amazonaws.${var.current_region}.ecr.dkr"
160+
vpc_endpoint_type = "Interface"
161+
162+
security_group_ids = [
163+
aws_security_group.vpc_endpoint_sg.id,
164+
]
165+
166+
subnet_ids = tolist(aws_subnet.private_subnets[*].id)
167+
168+
private_dns_enabled = true
109169
}

0 commit comments

Comments
 (0)