forked from DNXLabs/terraform-aws-client-vpn
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathvpn-endpoint.tf
50 lines (44 loc) · 2.03 KB
/
vpn-endpoint.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
resource "aws_ec2_client_vpn_endpoint" "default" {
description = "${var.name}-Client-VPN"
server_certificate_arn = aws_acm_certificate.server.arn
client_cidr_block = var.cidr
split_tunnel = var.split_tunnel
dns_servers = var.dns_servers
self_service_portal = local.self_service_portal
security_group_ids = [var.security_group_id == "" ? aws_security_group.default[0].id : var.security_group_id]
vpc_id = var.vpc_id
authentication_options {
type = var.authentication_type
root_certificate_chain_arn = var.authentication_type != "certificate-authentication" ? null : aws_acm_certificate.root.arn
saml_provider_arn = var.authentication_saml_provider_arn
}
connection_log_options {
enabled = true
cloudwatch_log_group = aws_cloudwatch_log_group.vpn.name
cloudwatch_log_stream = aws_cloudwatch_log_stream.vpn.name
}
tags = merge(
var.tags,
tomap({
"Name" = "${var.name}-Client-VPN",
"EnvName" = var.name
})
)
}
resource "aws_ec2_client_vpn_network_association" "default" {
count = length(var.subnet_ids)
client_vpn_endpoint_id = aws_ec2_client_vpn_endpoint.default.id
subnet_id = element(var.subnet_ids, count.index)
}
resource "aws_ec2_client_vpn_authorization_rule" "all_groups" {
count = length(var.allowed_access_groups) > 0 ? 0 : length(var.allowed_cidr_ranges)
client_vpn_endpoint_id = aws_ec2_client_vpn_endpoint.default.id
target_network_cidr = var.allowed_cidr_ranges[count.index]
authorize_all_groups = true
}
resource "aws_ec2_client_vpn_authorization_rule" "specific_groups" {
count = length(var.allowed_access_groups) * length(var.allowed_cidr_ranges)
client_vpn_endpoint_id = aws_ec2_client_vpn_endpoint.default.id
target_network_cidr = element(var.allowed_cidr_ranges, count.index)
access_group_id = var.allowed_access_groups[count.index % length(var.allowed_cidr_ranges)]
}