vpn.tf 3.2 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677
  1. locals {
  2. # Redundancy count determines how many redundant paths we have in different AZ's.
  3. # 1 is good for testing
  4. # 2 is probably good enough for all other cases
  5. # length(var.public_subnets) is the max
  6. redundancy_count = 1
  7. #redundancy_count = length(var.public_subnets)
  8. }
  9. resource "aws_ec2_client_vpn_endpoint" "vpn" {
  10. description = "VPN for XDR Employee Access"
  11. client_cidr_block = "172.16.0.0/22"
  12. split_tunnel = var.split_tunnel
  13. server_certificate_arn = aws_acm_certificate.cert.arn
  14. self_service_portal = "enabled" # requires a self_service_saml_provider in authentication_options
  15. security_group_ids = [aws_security_group.vpn_access.id]
  16. dns_servers = local.dns_servers
  17. # Certificate based authenticaiton requires the certificate be in the same account
  18. #authentication_options {
  19. # type = "certificate-authentication"
  20. # root_certificate_chain_arn = "arn:aws-us-gov:acm-pca:us-gov-east-1:701290387780:certificate-authority/cb0ea325-a347-4297-9cb8-2134410c3889"
  21. #}
  22. authentication_options {
  23. type = "federated-authentication"
  24. saml_provider_arn = aws_iam_saml_provider.okta.arn
  25. self_service_saml_provider_arn = aws_iam_saml_provider.okta-self-service.arn
  26. }
  27. connection_log_options {
  28. enabled = true
  29. cloudwatch_log_group = aws_cloudwatch_log_group.vpn.name
  30. cloudwatch_log_stream = aws_cloudwatch_log_stream.vpn.name
  31. }
  32. # Could not get UDP working on OSX
  33. transport_protocol = var.protocol
  34. #transport_protocol = "tcp"
  35. vpn_port = 443
  36. session_timeout_hours = 12
  37. client_login_banner_options {
  38. banner_text = "--- NOTICE TO USERS ---\n\nAccenture Federal Services AUTHORIZED USE ONLY\n\nThis system is the property of Accenture Federal Services. You are accessing a U.S. Government certified information system. By using this system you consent to monitoring for unauthorized access or activity where legally permitted and agree to use the system in accordance to Accenture Federal Services policies, local laws and regulations.\n\nUnauthorized use of this system is prohibited and subject to reprimand, dismissal, financial penalties, criminal penalties, and civil penalties. By signing in, you are agreeing to these terms."
  39. enabled = true
  40. }
  41. client_connect_options {
  42. enabled = true
  43. lambda_function_arn = aws_lambda_function.lambda_connection_authorization.arn
  44. }
  45. }
  46. resource "aws_ec2_client_vpn_network_association" "vpn_subnets" {
  47. count = local.redundancy_count
  48. client_vpn_endpoint_id = aws_ec2_client_vpn_endpoint.vpn.id
  49. subnet_id = var.public_subnets[count.index]
  50. lifecycle {
  51. // The issue why we are ignoring changes is that on every change
  52. // terraform screws up most of the vpn assosciations
  53. // see: https://github.com/hashicorp/terraform-provider-aws/issues/14717
  54. ignore_changes = [subnet_id]
  55. }
  56. }
  57. resource "aws_ec2_client_vpn_route" "default" {
  58. count = local.redundancy_count
  59. client_vpn_endpoint_id = aws_ec2_client_vpn_endpoint.vpn.id
  60. #destination_cidr_block = "10.0.0.0/8"
  61. destination_cidr_block = "0.0.0.0/0"
  62. target_vpc_subnet_id = aws_ec2_client_vpn_network_association.vpn_subnets[count.index].subnet_id
  63. }