vpn.tf 2.2 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162
  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 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. # TODO: Specify DNS Servers
  16. dns_servers = var.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. # Possible required with zscalar?
  33. transport_protocol = "udp"
  34. resource "aws_ec2_client_vpn_network_association" "vpn_subnets" {
  35. count = local.redundancy_count
  36. client_vpn_endpoint_id = aws_ec2_client_vpn_endpoint.vpn.id
  37. subnet_id = var.public_subnets[count.index]
  38. security_groups = [aws_security_group.vpn_access.id]
  39. lifecycle {
  40. // The issue why we are ignoring changes is that on every change
  41. // terraform screws up most of the vpn assosciations
  42. // see: https://github.com/hashicorp/terraform-provider-aws/issues/14717
  43. ignore_changes = [subnet_id]
  44. }
  45. }
  46. resource "aws_ec2_client_vpn_route" "default" {
  47. count = local.redundancy_count
  48. client_vpn_endpoint_id = aws_ec2_client_vpn_endpoint.vpn.id
  49. destination_cidr_block = "10.0.0.0/8"
  50. target_vpc_subnet_id = aws_ec2_client_vpn_network_association.vpn_subnets[count.index].subnet_id
  51. }