forked from cloudposse/terraform-aws-vpn-connection
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmain.tf
48 lines (43 loc) · 2.04 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
locals {
enabled = module.this.enabled
}
# https://www.terraform.io/docs/providers/aws/r/vpn_gateway.html
resource "aws_vpn_gateway" "default" {
count = local.enabled ? 1 : 0
vpc_id = var.vpc_id
amazon_side_asn = var.vpn_gateway_amazon_side_asn
tags = module.this.tags
}
# https://www.terraform.io/docs/providers/aws/r/customer_gateway.html
resource "aws_customer_gateway" "default" {
count = local.enabled ? 1 : 0
bgp_asn = var.customer_gateway_bgp_asn
ip_address = var.customer_gateway_ip_address
type = "ipsec.1"
tags = module.this.tags
}
# https://www.terraform.io/docs/providers/aws/r/vpn_connection.html
resource "aws_vpn_connection" "default" {
count = local.enabled ? 1 : 0
vpn_gateway_id = join("", aws_vpn_gateway.default.*.id)
customer_gateway_id = join("", aws_customer_gateway.default.*.id)
type = "ipsec.1"
static_routes_only = var.vpn_connection_static_routes_only
tunnel1_inside_cidr = var.vpn_connection_tunnel1_inside_cidr
tunnel2_inside_cidr = var.vpn_connection_tunnel2_inside_cidr
tunnel1_preshared_key = var.vpn_connection_tunnel1_preshared_key
tunnel2_preshared_key = var.vpn_connection_tunnel2_preshared_key
tags = module.this.tags
}
# https://www.terraform.io/docs/providers/aws/r/vpn_gateway_route_propagation.html
resource "aws_vpn_gateway_route_propagation" "default" {
count = local.enabled ? length(var.route_table_ids) : 0
vpn_gateway_id = join("", aws_vpn_gateway.default.*.id)
route_table_id = element(var.route_table_ids, count.index)
}
# https://www.terraform.io/docs/providers/aws/r/vpn_connection_route.html
resource "aws_vpn_connection_route" "default" {
count = local.enabled && var.vpn_connection_static_routes_only == "true" ? length(var.vpn_connection_static_routes_destinations) : 0
vpn_connection_id = join("", aws_vpn_connection.default.*.id)
destination_cidr_block = element(var.vpn_connection_static_routes_destinations, count.index)
}