Skip to content

Commit e08fcb4

Browse files
author
Dmitry Berezovsky
committed
Added vpc_peering module
1 parent 7282507 commit e08fcb4

File tree

6 files changed

+111
-1
lines changed

6 files changed

+111
-1
lines changed
Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
output "private_ip" {
2+
value = "${aws_instance.clearos.private_ip}"
3+
}
4+
5+
output "instance_id" {
6+
value = "${aws_instance.clearos.id}"
7+
}
8+
9+
output "public_ip" {
10+
value = "${aws_eip.clearos.public_ip}"
11+
}

modules/domain_controller/resources/centos-to-clearos.sh

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,7 @@ yum-config-manager --enable clearos-centos-extras
3838
yum-config-manager --enable clearos-centos
3939
yum-config-manager --enable clearos-centos-fasttrack clearos-centos-updates
4040

41-
yum install -y app-openvpn app-openldap-directory app-administrators app-dns app-storage
41+
yum install -y app-openvpn app-openldap-directory app-administrators app-dns app-storage app-firewall app-firewall-custom
4242

4343
# Default networking
4444
yum -y remove NetworkManager

modules/vpc_peering/README.MD

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
VPC Peering
2+
===========
3+
4+
This module allow to link to AWS 2 VPCs. Basically it creates peering connection and configures routes
5+
for VPC which initiates connection. It is important to understand that in order to have complete setup
6+
you might need to configure routes and security groups on the receiving side
7+

modules/vpc_peering/output.tf

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
output "remote_vpc_connection" {
2+
value = "${aws_vpc_peering_connection.remote_vpc_link.id}"
3+
}
4+
5+
output "remote_network_access_sg_id" {
6+
value = "${aws_security_group.allow_access_to_remote_vpc.id}"
7+
}

modules/vpc_peering/peering.tf

Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,44 @@
1+
resource "aws_vpc_peering_connection" "remote_vpc_link" {
2+
count = "${var.target_vpc_id != "" ? 1 : 0}"
3+
peer_vpc_id = "${var.target_vpc_id}"
4+
vpc_id = "${var.current_vpc_id}"
5+
auto_accept = "${var.peering_auto_accept}"
6+
7+
accepter {
8+
allow_remote_vpc_dns_resolution = true
9+
}
10+
11+
requester {
12+
allow_remote_vpc_dns_resolution = false
13+
}
14+
15+
tags {
16+
Env = "${var.env_name}"
17+
Name = "${var.env_name}: ${var.remote_vpc_name} Link"
18+
}
19+
}
20+
21+
resource "aws_route" "remote_vpc_routes" {
22+
count = "${var.target_vpc_id != "" ? length(var.local_route_tables_to_support_link) : 0 }"
23+
route_table_id = "${element(var.local_route_tables_to_support_link, count.index)}"
24+
vpc_peering_connection_id = "${aws_vpc_peering_connection.remote_vpc_link.id}"
25+
destination_cidr_block = "${var.target_vpc_network}"
26+
}
27+
28+
resource "aws_security_group" "allow_access_to_remote_vpc" {
29+
count = "${var.target_vpc_id != "" ? 1 : 0}"
30+
name = "${lower(var.env_name)}-access-${lower(var.remote_vpc_name)}-lan"
31+
vpc_id = "${var.current_vpc_id}"
32+
33+
egress {
34+
from_port = 0
35+
to_port = 0
36+
protocol = "-1"
37+
cidr_blocks = ["${var.allow_access_to_remote_vpc_cidrs}"]
38+
}
39+
40+
tags {
41+
Env = "${var.env_name}"
42+
Name = "${var.env_name}: Allow Access to ${var.remote_vpc_name} LAN"
43+
}
44+
}

modules/vpc_peering/variables.tf

Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
1+
variable "env_name" {
2+
type = "string"
3+
}
4+
5+
variable "remote_vpc_name" {
6+
description = "Name of the remote VPC to be used in resources names. E.g. Production"
7+
type = "string"
8+
}
9+
10+
variable "current_vpc_id" {
11+
type = "string"
12+
}
13+
14+
variable "target_vpc_id" {
15+
type = "string"
16+
}
17+
18+
variable "target_vpc_network" {
19+
type = "string"
20+
default = ""
21+
}
22+
23+
variable "peering_auto_accept" {
24+
type = "string"
25+
default = true
26+
}
27+
28+
variable "local_route_tables_to_support_link" {
29+
description = "Traffic from given networks will be routed to remote VPC. Expects the list of route table IDs"
30+
type = "list"
31+
default = []
32+
}
33+
34+
variable "vpc_availability_zones" {
35+
type = "list"
36+
default = []
37+
}
38+
39+
variable "allow_access_to_remote_vpc_cidrs" {
40+
type = "list"
41+
}

0 commit comments

Comments
 (0)