-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathroute_table.tf
56 lines (36 loc) · 1.46 KB
/
route_table.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
44
45
46
47
48
49
50
51
52
53
54
55
56
data "aws_vpc" "this" {
provider = aws.this
id = var.this_vpc_id
}
data "aws_vpc" "peer" {
provider = aws.peer
id = var.peer_vpc_id
}
data "aws_route_tables" "this" {
provider = aws.this
count = length(var.this_vpc_route_table_ids) == 0 ? 1 : 0
vpc_id = data.aws_vpc.this.id
}
resource "aws_route" "peer_routing_from_this" {
provider = aws.this
count = length(local.this_vpc_route_table_ids)
route_table_id = local.this_vpc_route_table_ids[count.index]
destination_cidr_block = data.aws_vpc.peer.cidr_block
vpc_peering_connection_id = aws_vpc_peering_connection.this.id
}
locals {
this_vpc_route_table_ids = (var.target_workaround == true || length(var.this_vpc_route_table_ids) > 0) ? var.this_vpc_route_table_ids : toset(flatten(data.aws_route_tables.this[*].ids))
peer_vpc_route_table_ids = (var.target_workaround == true || length(var.peer_vpc_route_table_ids) > 0) ? var.peer_vpc_route_table_ids : toset(flatten(data.aws_route_tables.peer[*].ids))
}
data "aws_route_tables" "peer" {
provider = aws.peer
count = length(var.peer_vpc_route_table_ids) == 0 ? 1 : 0
vpc_id = data.aws_vpc.peer.id
}
resource "aws_route" "this_rounting_from_peer" {
provider = aws.peer
count = length(local.peer_vpc_route_table_ids)
route_table_id = local.peer_vpc_route_table_ids[count.index]
destination_cidr_block = data.aws_vpc.this.cidr_block
vpc_peering_connection_id = aws_vpc_peering_connection.this.id
}