-
Notifications
You must be signed in to change notification settings - Fork 0
/
peering.tf
43 lines (37 loc) · 1.45 KB
/
peering.tf
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
resource "aws_vpc_peering_connection" "peering" {
count = var.is_peering_required ? 1 : 0
vpc_id = aws_vpc.main.id #requestor
peer_vpc_id = data.aws_vpc.default.id #acceptor
auto_accept = true
tags = merge(
var.common_tags,
var.vpc_peering_tags,
{
Name = "${local.resource_name}-default"
}
)
}
resource "aws_route" "public_peering" {
count = var.is_peering_required ? 1 : 0
route_table_id = aws_route_table.public.id
destination_cidr_block = data.aws_vpc.default.cidr_block
vpc_peering_connection_id = aws_vpc_peering_connection.peering[count.index].id
}
resource "aws_route" "private_peering" {
count = var.is_peering_required ? 1 : 0
route_table_id = aws_route_table.private.id
destination_cidr_block = data.aws_vpc.default.cidr_block
vpc_peering_connection_id = aws_vpc_peering_connection.peering[count.index].id
}
resource "aws_route" "database_peering" {
count = var.is_peering_required ? 1 : 0
route_table_id = aws_route_table.database.id
destination_cidr_block = data.aws_vpc.default.cidr_block
vpc_peering_connection_id = aws_vpc_peering_connection.peering[count.index].id
}
resource "aws_route" "default_peering" {
count = var.is_peering_required ? 1 : 0
route_table_id = data.aws_route_table.main.route_table_id
destination_cidr_block = var.vpc_cidr
vpc_peering_connection_id = aws_vpc_peering_connection.peering[count.index].id
}