-
Notifications
You must be signed in to change notification settings - Fork 11
/
Copy pathmain.tf
69 lines (63 loc) · 1.91 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
# Accepter's credentials
provider "aws" {
alias = "peer"
region = var.peer_region
profile = var.peer_profile
}
data "aws_caller_identity" "peer" {
provider = aws.peer
}
data "aws_region" "peer" {
provider = aws.peer
}
########################
# Initiate the request #
########################
resource "aws_vpc_peering_connection" "this" {
vpc_id = var.this_vpc_id
peer_vpc_id = var.peer_vpc_id
peer_owner_id = data.aws_caller_identity.peer.account_id
peer_region = data.aws_region.peer.id
auto_accept = false
tags = merge(
var.tags,
{
"Name" = format("%s-peering-requester", var.name)
},
)
}
######################
# Accept the request #
######################
resource "aws_vpc_peering_connection_accepter" "peer" {
provider = aws.peer
vpc_peering_connection_id = aws_vpc_peering_connection.this.id
auto_accept = var.auto_accept_peering
tags = merge(
var.tags,
{
"Name" = format("%s-peering-accepter", var.name)
},
)
}
########################
# Routes for requester #
########################
resource "aws_route" "route_tables" {
count = length(var.this_route_table_ids)
route_table_id = element(var.this_route_table_ids, count.index)
destination_cidr_block = var.peer_cidr_block
vpc_peering_connection_id = aws_vpc_peering_connection.this.id
depends_on = [aws_vpc_peering_connection.this]
}
########################
# Routes for accepter #
########################
resource "aws_route" "peer_route_tables" {
provider = aws.peer
count = length(var.peer_route_table_ids)
route_table_id = element(var.peer_route_table_ids, count.index)
destination_cidr_block = var.this_cidr_block
vpc_peering_connection_id = aws_vpc_peering_connection.this.id
depends_on = [aws_vpc_peering_connection.this]
}