-
Notifications
You must be signed in to change notification settings - Fork 4
/
peerlink.tf
58 lines (49 loc) · 2.13 KB
/
peerlink.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
##################################################
# File: peerlink.tf #
# Created Date: 03222019 #
# Author: Fred Stuck #
# Version: 0.1 #
# Description: Setup VPC Peer Link #
# #
# Change History: #
# 03222019: Initial File #
# #
##################################################
resource "aws_vpc_peering_connection" "peer" {
for_each = var.peer_requester
vpc_id = aws_vpc.main_vpc.id
peer_vpc_id = element(split("|", each.value),1)
peer_owner_id = element(split("|", each.value),0)
auto_accept = var.acctnum == element(split("|", each.value),0) ? true : false
requester {
allow_classic_link_to_remote_vpc = false
allow_remote_vpc_dns_resolution = element(split("|", each.value),3)
allow_vpc_to_remote_classic_link = false
}
tags = merge(var.tags, map("Name", "${each.key}-peerlink"))
}
resource "aws_vpc_peering_connection_accepter" "peer" {
for_each = var.peer_accepter
vpc_peering_connection_id = element(split("|", each.value),0)
auto_accept = true
accepter {
allow_classic_link_to_remote_vpc = false
allow_remote_vpc_dns_resolution = element(split("|", each.value),2)
allow_vpc_to_remote_classic_link = false
}
lifecycle {
ignore_changes = [tags]
}
}
resource "aws_route" "accepter_routes" {
for_each = {for route in local.peerlink_accepter_routes : route.name => route}
route_table_id = each.value.route_table
destination_cidr_block = each.value.cidr
vpc_peering_connection_id = each.value.conn_id
}
resource "aws_route" "requester_routes" {
for_each = {for route in local.peerlink_requester_routes : route.name => route}
route_table_id = each.value.route_table
destination_cidr_block = each.value.cidr
vpc_peering_connection_id = aws_vpc_peering_connection.peer[each.value.peer_link_name].id
}