forked from nicksantamaria/example-terraform-aws-vpc-peering
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmain.tf
52 lines (48 loc) · 1.46 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
/**
* Setup AWS provider.
*/
provider "aws" {
region = var.region
}
/**
* Make AWS account ID available.
*
* This is added as an output so that other stacks can reference this. Usually
* required for VPC peering.
*/
data "aws_caller_identity" "current" {}
/**
* VPC peering connection.
*
* Establishes a relationship resource between the "primary" and "secondary" VPC.
*/
resource "aws_vpc_peering_connection" "primary2secondary" {
peer_owner_id = data.aws_caller_identity.current.account_id
peer_vpc_id = aws_vpc.secondary.id
vpc_id = aws_vpc.primary.id
auto_accept = true
}
/**
* Route rule.
*
* Creates a new route rule on the "primary" VPC main route table. All requests
* to the "secondary" VPC's IP range will be directed to the VPC peering
* connection.
*/
resource "aws_route" "primary2secondary" {
route_table_id = aws_vpc.primary.main_route_table_id
destination_cidr_block = aws_vpc.secondary.cidr_block
vpc_peering_connection_id = aws_vpc_peering_connection.primary2secondary.id
}
/**
* Route rule.
*
* Creates a new route rule on the "secondary" VPC main route table. All
* requests to the "secondary" VPC's IP range will be directed to the VPC
* peering connection.
*/
resource "aws_route" "secondary2primary" {
route_table_id = aws_vpc.secondary.main_route_table_id
destination_cidr_block = aws_vpc.primary.cidr_block
vpc_peering_connection_id = aws_vpc_peering_connection.primary2secondary.id
}