vpn.tf 2.0 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556
  1. resource "aws_ec2_client_vpn_endpoint" "vpn" {
  2. description = "VPN for Employee Access"
  3. client_cidr_block = "172.16.0.0/22"
  4. split_tunnel = true
  5. server_certificate_arn = aws_acm_certificate.cert.arn
  6. self_service_portal = "disabled" # requires a self_service_saml_provider in authentication_options
  7. # TODO: Specify DNS Servers
  8. dns_servers = var.dns_servers
  9. # Certificate based authenticaiton requires the certificate be in the same account
  10. #authentication_options {
  11. # type = "certificate-authentication"
  12. # root_certificate_chain_arn = "arn:aws-us-gov:acm-pca:us-gov-east-1:701290387780:certificate-authority/cb0ea325-a347-4297-9cb8-2134410c3889"
  13. #}
  14. authentication_options {
  15. type = "federated-authentication"
  16. saml_provider_arn = aws_iam_saml_provider.okta.arn
  17. }
  18. connection_log_options {
  19. enabled = true
  20. cloudwatch_log_group = aws_cloudwatch_log_group.vpn.name
  21. cloudwatch_log_stream = aws_cloudwatch_log_stream.vpn.name
  22. }
  23. # Possible required with zscalar?
  24. transport_protocol = "udp"
  25. tags = merge(var.standard_tags, var.tags)
  26. }
  27. resource "aws_ec2_client_vpn_network_association" "vpn_subnets" {
  28. count = length(var.public_subnets)
  29. #count = 1 # we don't need the redundancy for now
  30. client_vpn_endpoint_id = aws_ec2_client_vpn_endpoint.vpn.id
  31. subnet_id = var.public_subnets[count.index]
  32. security_groups = [aws_security_group.vpn_access.id]
  33. lifecycle {
  34. // The issue why we are ignoring changes is that on every change
  35. // terraform screws up most of the vpn assosciations
  36. // see: https://github.com/hashicorp/terraform-provider-aws/issues/14717
  37. ignore_changes = [subnet_id]
  38. }
  39. }
  40. resource "aws_ec2_client_vpn_route" "default" {
  41. count = length(var.public_subnets)
  42. #count = 1 # we don't need the redundancy for now
  43. client_vpn_endpoint_id = aws_ec2_client_vpn_endpoint.vpn.id
  44. destination_cidr_block = "10.0.0.0/8"
  45. target_vpc_subnet_id = aws_ec2_client_vpn_network_association.vpn_subnets[count.index].subnet_id
  46. }