vpn.tf 2.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263
  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. # Could not get UDP working on OSX
  33. transport_protocol = "tcp"
  34. }
  35. resource "aws_ec2_client_vpn_network_association" "vpn_subnets" {
  36. count = local.redundancy_count
  37. client_vpn_endpoint_id = aws_ec2_client_vpn_endpoint.vpn.id
  38. subnet_id = var.public_subnets[count.index]
  39. security_groups = [aws_security_group.vpn_access.id]
  40. lifecycle {
  41. // The issue why we are ignoring changes is that on every change
  42. // terraform screws up most of the vpn assosciations
  43. // see: https://github.com/hashicorp/terraform-provider-aws/issues/14717
  44. ignore_changes = [subnet_id]
  45. }
  46. }
  47. resource "aws_ec2_client_vpn_route" "default" {
  48. count = local.redundancy_count
  49. client_vpn_endpoint_id = aws_ec2_client_vpn_endpoint.vpn.id
  50. #destination_cidr_block = "10.0.0.0/8"
  51. destination_cidr_block = "0.0.0.0/0"
  52. target_vpc_subnet_id = aws_ec2_client_vpn_network_association.vpn_subnets[count.index].subnet_id
  53. }