-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathmain.tf
71 lines (67 loc) · 1.74 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
/**
* tf_vpn_corp Terraform Module
* =====================
*
* Setup VPN connection to Corporate
*
* Usage:
* ------
*
* module "tf_vpn_corp" {
* source = "../tf_vpn_corp"
* name = ""
* environment = "dev"
* vpc_id = ""
* dest_cidrs = ""
* }
**/
# TODO: remove code fom tf_gateway, elsewhere
# TODO: create gateway per AZ
resource "aws_vpn_gateway" "vpn_gw_corp" {
vpc_id = "${var.vpc_id}"
lifecycle {
create_before_destroy = true
}
tags {
Name = "${var.environment}-vpn-gw-corp"
Environment = "${var.environment}"
Terraform = "true"
}
}
/*
resource "aws_customer_gateway" "cgw_corp" {
bgp_asn = "12345"
ip_address = "x.x.x.x"
type = "ipsec.1"
lifecycle {
create_before_destroy = true
}
tags {
Name = "${var.environment}-cgw-corp"
Environment = "${var.environment}"
}
}
*/
resource "aws_vpn_connection" "vpn_corp" {
vpn_gateway_id = "${aws_vpn_gateway.vpn_gw_corp.id}"
#customer_gateway_id = "${aws_customer_gateway.cgw_corp.id}"
customer_gateway_id = "${var.corp_customer_gateway_id}"
type = "ipsec.1"
static_routes_only = true
lifecycle {
create_before_destroy = true
#prevent_destroy = true
}
tags = "${ merge(
var.tags,
map("Name", var.namespaced ?
format("%s-%s-vpn", var.environment, var.name) :
format("%s-vpn", var.name) ),
map("Environment", var.environment),
map("Terraform", "true") )}"
}
resource "aws_vpn_connection_route" "vpn_route_corp" {
count = "${length(var.dest_cidrs)}"
destination_cidr_block = "${element(var.dest_cidrs, count.index)}"
vpn_connection_id = "${aws_vpn_connection.vpn_corp.id}"
}