-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathnat.tf
More file actions
44 lines (38 loc) · 1.28 KB
/
nat.tf
File metadata and controls
44 lines (38 loc) · 1.28 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
resource "aws_eip" "nat_gateway" {
count = length(aws_subnet.public) > 0 ? 1 : 0
domain = "vpc"
tags = var.default_tags
}
moved {
from = aws_eip.nat_gateway
to = aws_eip.nat_gateway[0]
}
resource "aws_internet_gateway" "redpanda" {
count = local.create_vpc || var.create_internet_gateway ? 1 : 0
vpc_id = data.aws_vpc.redpanda.id
tags = var.default_tags
}
resource "aws_nat_gateway" "redpanda" {
count = length(aws_subnet.public) > 0 ? 1 : 0
allocation_id = aws_eip.nat_gateway[0].id
subnet_id = aws_subnet.public[0].id
depends_on = [
aws_internet_gateway.redpanda,
]
tags = var.default_tags
}
locals {
create_private_routes = length(aws_subnet.public) > 0 && length(aws_subnet.private) > 0
}
resource "aws_route" "nat" {
count = local.create_private_routes ? length(var.private_subnet_cidrs) : 0
route_table_id = aws_route_table.private.*.id[count.index]
destination_cidr_block = "0.0.0.0/0"
nat_gateway_id = aws_nat_gateway.redpanda[0].id
}
resource "aws_route" "public" {
count = local.create_vpc || var.create_internet_gateway ? 1 : 0
route_table_id = aws_route_table.main.id
destination_cidr_block = "0.0.0.0/0"
gateway_id = aws_internet_gateway.redpanda[0].id
}