-
Notifications
You must be signed in to change notification settings - Fork 93
/
main.tf
113 lines (102 loc) · 4.72 KB
/
main.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
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
##########################
# VPC peering connection #
##########################
resource "aws_vpc_peering_connection" "this" {
provider = aws.this
peer_owner_id = data.aws_caller_identity.peer.account_id
peer_vpc_id = var.peer_vpc_id
vpc_id = var.this_vpc_id
peer_region = data.aws_region.peer.name
tags = local.requester_tags
# hardcoded
timeouts {
create = "15m"
delete = "15m"
}
}
######################################
# VPC peering accepter configuration #
######################################
resource "aws_vpc_peering_connection_accepter" "peer_accepter" {
provider = aws.peer
vpc_peering_connection_id = aws_vpc_peering_connection.this.id
auto_accept = var.auto_accept_peering
tags = local.accepter_tags
}
#######################
# VPC peering options #
#######################
resource "aws_vpc_peering_connection_options" "this" {
provider = aws.this
vpc_peering_connection_id = aws_vpc_peering_connection_accepter.peer_accepter.id
requester {
allow_remote_vpc_dns_resolution = var.this_dns_resolution
}
}
resource "aws_vpc_peering_connection_options" "accepter" {
provider = aws.peer
vpc_peering_connection_id = aws_vpc_peering_connection_accepter.peer_accepter.id
accepter {
allow_remote_vpc_dns_resolution = var.peer_dns_resolution
}
}
###################
# This VPC Routes # Routes from THIS route table to PEER CIDR
###################
resource "aws_route" "this_routes" {
provider = aws.this
# Only create routes for this route table if input dictates it, and in that case, for all combinations
count = local.create_routes_this ? length(local.this_ipv4_routes) : 0
route_table_id = local.this_ipv4_routes[count.index].rts_id
destination_cidr_block = local.this_ipv4_routes[count.index].dest_ipv4_cidr
vpc_peering_connection_id = aws_vpc_peering_connection.this.id
}
resource "aws_route" "this_ipv6_routes" {
provider = aws.this
# Only create routes for this route table if input dictates it, and in that case, for all combinations
count = local.create_routes_this ? length(local.this_ipv6_routes) : 0
route_table_id = local.this_ipv6_routes[count.index].rts_id
destination_ipv6_cidr_block = local.this_ipv6_routes[count.index].dest_ipv6_cidr
vpc_peering_connection_id = aws_vpc_peering_connection.this.id
}
###################
# This VPC Associated Routes # Routes from THIS route table to associated PEER CIDR
###################
resource "aws_route" "this_associated_routes" {
provider = aws.this
# Only create routes for this route table if input dictates it, and in that case, for all combinations
count = local.create_associated_routes_this ? length(local.this_associated_routes) : 0
route_table_id = local.this_associated_routes[count.index].rts_id
destination_cidr_block = local.this_associated_routes[count.index].dest_cidr
vpc_peering_connection_id = aws_vpc_peering_connection.this.id
}
###################
# Peer VPC Routes # Routes from PEER route table to THIS CIDR
###################
resource "aws_route" "peer_routes" {
provider = aws.peer
# Only create routes for peer route table if input dictates it, and in that case, for all combinations
count = local.create_routes_peer ? length(local.peer_ipv4_routes) : 0
route_table_id = local.peer_ipv4_routes[count.index].rts_id
destination_cidr_block = local.peer_ipv4_routes[count.index].dest_ipv4_cidr
vpc_peering_connection_id = aws_vpc_peering_connection.this.id
}
resource "aws_route" "peer_ipv6_routes" {
provider = aws.peer
# Only create routes for peer route table if input dictates it, and in that case, for all combinations
count = local.create_routes_peer ? length(local.peer_ipv6_routes) : 0
route_table_id = local.peer_ipv6_routes[count.index].rts_id
destination_ipv6_cidr_block = local.peer_ipv6_routes[count.index].dest_ipv6_cidr
vpc_peering_connection_id = aws_vpc_peering_connection.this.id
}
###################
# Peer VPC Associated Routes # Routes from PEER route table to THIS CIDR
###################
resource "aws_route" "peer_associated_routes" {
provider = aws.peer
# Only create routes for peer route table if input dictates it, and in that case, for all combinations
count = local.create_associated_routes_peer ? length(local.peer_associated_routes) : 0
route_table_id = local.peer_associated_routes[count.index].rts_id
destination_cidr_block = local.peer_associated_routes[count.index].dest_cidr
vpc_peering_connection_id = aws_vpc_peering_connection.this.id
}