-
Notifications
You must be signed in to change notification settings - Fork 0
/
main.tf
executable file
·73 lines (52 loc) · 1.57 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
data "aws_caller_identity" "this" {}
data "aws_region" "current" {}
terraform {
required_version = ">= 0.12"
}
locals {
name = var.name
common_tags = {
"Name" = local.name
"Terraform" = true
"Environment" = var.environment
}
tags = merge(var.tags, local.common_tags)
}
data "aws_vpc" "acceptor" {
id = var.acceptor_vpc_id
}
data "aws_vpc" "requestor" {
id = var.requestor_vpc_id
}
data "aws_route_tables" "acceptor" {
vpc_id = var.acceptor_vpc_id
}
data "aws_route_tables" "requestor" {
vpc_id = var.requestor_vpc_id
}
resource "aws_vpc_peering_connection" "this" {
vpc_id = var.requestor_vpc_id
peer_vpc_id = var.acceptor_vpc_id
auto_accept = var.auto_accept
accepter {
allow_remote_vpc_dns_resolution = var.acceptor_allow_remote_vpc_dns_resolution
}
requester {
allow_remote_vpc_dns_resolution = var.requestor_allow_remote_vpc_dns_resolution
}
tags = local.tags
}
# Create routes from requestor to acceptor
resource "aws_route" "requestor" {
count = length(data.aws_route_tables.requestor.ids)
route_table_id = tolist(data.aws_route_tables.requestor.ids)[count.index]
destination_cidr_block = data.aws_vpc.acceptor.cidr_block
vpc_peering_connection_id = aws_vpc_peering_connection.this.id
}
# Create routes from acceptor to requestor
resource "aws_route" "acceptor" {
count = length(data.aws_route_tables.requestor.ids)
route_table_id = tolist(data.aws_route_tables.acceptor.ids)[count.index]
destination_cidr_block = data.aws_vpc.requestor.cidr_block
vpc_peering_connection_id = aws_vpc_peering_connection.this.id
}