-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathpeer.tf
72 lines (47 loc) · 1.44 KB
/
peer.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
data "aws_vpc" "vpc_main" {
default = true
}
data "aws_caller_identity" "peer" {
provider = "aws.peer"
}
provider "aws" {
alias = "peer"
region = "${var.region}"
# Accepter's credentials.
}
# Requester's side of the connection.
resource "aws_vpc_peering_connection" "peer" {
vpc_id = "${data.aws_vpc.vpc_main.id}"
peer_vpc_id = "${aws_vpc.vpc_hml.id}"
peer_owner_id = "${data.aws_caller_identity.peer.account_id}"
peer_region = "${var.region}"
auto_accept = false
tags = {
Side = "Requester"
}
}
# Accepter's side of the connection.
resource "aws_vpc_peering_connection_accepter" "peer" {
provider = "aws.peer"
vpc_peering_connection_id = "${aws_vpc_peering_connection.peer.id}"
auto_accept = true
tags = {
Side = "Accepter"
}
}
#route back
resource "aws_route" "peer_add_back"{
route_table_id = "${data.aws_route_table.selected.id}"
destination_cidr_block = "${data.aws_vpc.vpc_main.cidr_block}"
vpc_peering_connection_id = "${aws_vpc_peering_connection.peer.id}"
}
#route go
#find out data about main vpc
data "aws_route_table" "default_vpc" {
vpc_id = "${data.aws_vpc.vpc_main.id}"
}
resource "aws_route" "peer_add_forw"{
route_table_id = "${data.aws_route_table.default_vpc.id}"
destination_cidr_block = "${aws_subnet.subnet_hmla.cidr_block}"
vpc_peering_connection_id = "${aws_vpc_peering_connection.peer.id}"
}