Git Product home page Git Product logo

terraform-aws-vpn-gateway's Introduction

AWS VPN Gateway Terraform module

Terraform module which creates VPN gateway resources on AWS.

Features

This module creates:

  • a VPN Connection unless create_vpn_connection = false
  • a VPN Gateway Attachment
  • one or more VPN Gateway Route Propagation depending on how many routing tables exists in a VPC
  • one or more VPN Connection Route if create_vpn_connection = true and vpn_connection_static_routes_only = true, and depending on the number of destinations provided in variable vpn_connection_static_routes_destinations (which must be inline with vpc_subnet_route_table_count)

This module does not create a VPN Gateway resource because it is meant to be used in combination with the VPC module that will create that resource (when enable_vpn_gateway = true). This module also does not create a Customer Gateway resource. This module will create static routes for the VPN Connection if configured to create a VPN Connection resource with static routes and destinations for the routes have been provided. The static routes will then be automatically propagated to the VPC subnet routing tables (provided in private_route_table_ids) once a VPN tunnel status is UP. When static routes are disabled, the appliance behind the Customer Gateway needs to support BGP routing protocol in order for routes to be automatically discovered, and subsequently propagated to the VPC subnet routing tables. This module supports optional parameters for tunnel inside cidr and preshared keys. They can be supplied individually, too.

If you want to use the Transit Gateway support you are responsible for creating the transit gateway resources (eg, using terraform-aws-transit-gateway module).

Usage

module "vpn_gateway" {
  source  = "terraform-aws-modules/vpn-gateway/aws"
  version = "~> 3.0"

  vpc_id                  = module.vpc.vpc_id
  vpn_gateway_id          = module.vpc.vgw_id
  customer_gateway_id     = module.vpc.cgw_ids[0]

  # precalculated length of module variable vpc_subnet_route_table_ids
  vpc_subnet_route_table_count = 3
  vpc_subnet_route_table_ids   = module.vpc.private_route_table_ids

  # tunnel inside cidr & preshared keys (optional)
  tunnel1_inside_cidr   = var.custom_tunnel1_inside_cidr
  tunnel2_inside_cidr   = var.custom_tunnel2_inside_cidr
  tunnel1_preshared_key = var.custom_tunnel1_preshared_key
  tunnel2_preshared_key = var.custom_tunnel2_preshared_key
}

module "vpc" {
  source  = "terraform-aws-modules/vpc/aws"
  version = "~> 5.0"

  enable_vpn_gateway = true
  amazon_side_asn    = 64620

  customer_gateways = {
    IP1 = {
      bgp_asn    = 65220
      ip_address = "172.83.124.10"
    },
    IP2 = {
      bgp_asn    = 65220
      ip_address = "172.83.124.11"
    }
  }

  # ...
}

Without VPC module

module "vpn_gateway" {
  source  = "terraform-aws-modules/vpn-gateway/aws"
  version = "~> 3.0"

  vpn_gateway_id      = aws_vpn_gateway.vpn_gateway.id
  customer_gateway_id = aws_customer_gateway.main.id
  vpc_id              = aws_vpc.vpc.vpc_id

  vpc_subnet_route_table_count = 3
  vpc_subnet_route_table_ids   = ["rt-12322456", "rt-43433343", "rt-11223344"]

  # tunnel inside cidr & preshared keys (optional)
  tunnel1_inside_cidr   = var.custom_tunnel1_inside_cidr
  tunnel2_inside_cidr   = var.custom_tunnel2_inside_cidr
  tunnel1_preshared_key = var.custom_tunnel1_preshared_key
  tunnel2_preshared_key = var.custom_tunnel2_preshared_key
}

resource "aws_customer_gateway" "main" {
  bgp_asn    = 65000
  ip_address = "172.83.124.10"
  type       = "ipsec.1"

  tags {
    Name = "main-customer-gateway"
  }
}

resource "aws_vpc" "vpc" {
  # ...
}

resource "aws_vpn_gateway" "vpn_gateway" {
  vpc_id = aws_vpc.vpc.vpc_id

  # ...
}

With VPC module and Transit Gateway resources

module "vpn_gateway" {
  source  = "terraform-aws-modules/vpn-gateway/aws"
  version = "~> 3.0"

  create_vpn_gateway_attachment = false
  connect_to_transit_gateway    = true

  vpc_id                     = module.vpc.vpc_id
  transit_gateway_id         = aws_ec2_transit_gateway.this.id
  customer_gateway_id        = module.vpc.cgw_ids[0]

  # tunnel inside cidr & preshared keys (optional)
  tunnel1_inside_cidr   = var.custom_tunnel1_inside_cidr
  tunnel2_inside_cidr   = var.custom_tunnel2_inside_cidr
  tunnel1_preshared_key = var.custom_tunnel1_preshared_key
  tunnel2_preshared_key = var.custom_tunnel2_preshared_key
}

module "vpc" {
  source  = "terraform-aws-modules/vpc/aws"
  version = "~> 5.0"

  enable_vpn_gateway = false
  amazon_side_asn    = 64620

  customer_gateways = {
    IP1 = {
      bgp_asn    = 65220
      ip_address = "172.83.124.10"
    },
    IP2 = {
      bgp_asn    = 65220
      ip_address = "172.83.124.11"
    }
  }

  # ...
}

resource "aws_ec2_transit_gateway" "this" {
  description = "My TGW"
}

resource "aws_ec2_transit_gateway_vpc_attachment" "this" {
  subnet_ids         = module.vpc.private_subnets
  vpc_id             = module.vpc.vpc_id
  transit_gateway_id = aws_ec2_transit_gateway.this.id
}

With VPC and Transit Gateway modules

module "vpn_gateway" {
  source  = "terraform-aws-modules/vpn-gateway/aws"
  version = "~> 3.0"

  create_vpn_gateway_attachment = false
  connect_to_transit_gateway    = true

  vpc_id                     = module.vpc.vpc_id
  transit_gateway_id         = module.tgw.ec2_transit_gateway_id
  customer_gateway_id        = module.vpc.cgw_ids[0]

  # tunnel inside cidr & preshared keys (optional)
  tunnel1_inside_cidr   = var.custom_tunnel1_inside_cidr
  tunnel2_inside_cidr   = var.custom_tunnel2_inside_cidr
  tunnel1_preshared_key = var.custom_tunnel1_preshared_key
  tunnel2_preshared_key = var.custom_tunnel2_preshared_key
}

module "vpc" {
  source  = "terraform-aws-modules/vpc/aws"
  version = "~> 5.0"

  enable_vpn_gateway = false
  amazon_side_asn    = 64620

  customer_gateways = {
    IP1 = {
      bgp_asn    = 65220
      ip_address = "172.83.124.10"
    },
    IP2 = {
      bgp_asn    = 65220
      ip_address = "172.83.124.11"
    }
  }

  # ...
}

module "tgw" {
  source  = "terraform-aws-modules/transit-gateway/aws"
  version = "~> 2.0"

  name            = "my-tgw"
  description     = "My TGW shared with several other AWS accounts"
  amazon_side_asn = 64532

  vpc_attachments = {
    vpc1 = {
      vpc_id      = "vpc-12345678" # module.vpc.vpc_id <- will not work since computed values can't be used in `count`
      subnet_ids  = ["subnet-123456", "subnet-111222233"] # module.vpc.public_subnets <- will not work since computed values can't be used in `count`
      dns_support = true

      tgw_routes = [
        {
          destination_cidr_block = "30.0.0.0/16"
        },
        {
          blackhole              = true
          destination_cidr_block = "0.0.0.0/0"
        }
      ]
    }
  }
}

Examples

Requirements

Name Version
terraform >= 1.0
aws >= 4.66

Providers

Name Version
aws >= 4.66

Modules

No modules.

Resources

Name Type
aws_ec2_tag.tags resource
aws_vpn_connection.default resource
aws_vpn_connection.preshared resource
aws_vpn_connection.tunnel resource
aws_vpn_connection.tunnel_preshared resource
aws_vpn_connection_route.default resource
aws_vpn_gateway_attachment.default resource
aws_vpn_gateway_route_propagation.private_subnets_vpn_routing resource

Inputs

Name Description Type Default Required
connect_to_transit_gateway Set to false to disable attachment of the VPN connection route to the VPN connection (TGW uses another resource for that) bool false no
create_vpn_connection Set to false to prevent the creation of a VPN Connection. bool true no
create_vpn_gateway_attachment Set to false to prevent attachment of the VGW to the VPC bool true no
customer_gateway_id The id of the Customer Gateway. string n/a yes
local_ipv4_network_cidr (Optional) The IPv4 CIDR on the customer gateway (on-premises) side of the VPN connection. string null no
local_ipv6_network_cidr (Optional) The IPv6 CIDR on the customer gateway (on-premises) side of the VPN connection. string null no
remote_ipv4_network_cidr (Optional) The IPv4 CIDR on the AWS side of the VPN connection. string null no
remote_ipv6_network_cidr (Optional) The IPv6 CIDR on AWS side of the VPN connection. string null no
tags Set of tags to be added to the VPN Connection resource (only if create_vpn_connection = true). map(string) {} no
transit_gateway_id The ID of the Transit Gateway. string null no
tunnel1_dpd_timeout_action (Optional, Default clear) The action to take after DPD timeout occurs for the first VPN tunnel. Specify restart to restart the IKE initiation. Specify clear to end the IKE session. Valid values are clear | none | restart string null no
tunnel1_dpd_timeout_seconds (Optional, Default 30) The number of seconds after which a DPD timeout occurs for the first VPN tunnel. Valid value is equal or higher than 30 number null no
tunnel1_enable_tunnel_lifecycle_control (Optional) Turn on or off tunnel endpoint lifecycle control feature for the first VPN tunnel. Valid values are true | false bool null no
tunnel1_ike_versions (Optional) The IKE versions that are permitted for the first VPN tunnel. Valid values are ikev1 | ikev2 list(string) null no
tunnel1_inside_cidr The CIDR block of the inside IP addresses for the first VPN tunnel. string "" no
tunnel1_log_options (Optional) Options for sending VPN tunnel logs to CloudWatch. any {} no
tunnel1_phase1_dh_group_numbers (Optional) List of one or more Diffie-Hellman group numbers that are permitted for the first VPN tunnel for phase 1 IKE negotiations. Valid values are 2 | 14 | 15 | 16 | 17 | 18 | 19 | 20 | 21 | 22 | 23 | 24 list(number) null no
tunnel1_phase1_encryption_algorithms (Optional) List of one or more encryption algorithms that are permitted for the first VPN tunnel for phase 1 IKE negotiations. Valid values are AES128 | AES256 | AES128-GCM-16 | AES256-GCM-16 list(string) null no
tunnel1_phase1_integrity_algorithms (Optional) One or more integrity algorithms that are permitted for the first VPN tunnel for phase 1 IKE negotiations. Valid values are SHA1 | SHA2-256 | SHA2-384 | SHA2-512 list(string) null no
tunnel1_phase1_lifetime_seconds (Optional, Default 28800) The lifetime for phase 1 of the IKE negotiation for the first VPN tunnel, in seconds. Valid value is between 900 and 28800 number null no
tunnel1_phase2_dh_group_numbers (Optional) List of one or more Diffie-Hellman group numbers that are permitted for the first VPN tunnel for phase 2 IKE negotiations. Valid values are 2 | 5 | 14 | 15 | 16 | 17 | 18 | 19 | 20 | 21 | 22 | 23 | 24 list(number) null no
tunnel1_phase2_encryption_algorithms (Optional) List of one or more encryption algorithms that are permitted for the first VPN tunnel for phase 2 IKE negotiations. Valid values are AES128 | AES256 | AES128-GCM-16 | AES256-GCM-16 list(string) null no
tunnel1_phase2_integrity_algorithms (Optional) List of one or more integrity algorithms that are permitted for the first VPN tunnel for phase 2 IKE negotiations. Valid values are SHA1 | SHA2-256 | SHA2-384 | SHA2-512 list(string) null no
tunnel1_phase2_lifetime_seconds (Optional, Default 3600) The lifetime for phase 2 of the IKE negotiation for the first VPN tunnel, in seconds. Valid value is between 900 and 3600 number null no
tunnel1_preshared_key The preshared key of the first VPN tunnel. string "" no
tunnel1_rekey_fuzz_percentage (Optional, Default 100) The percentage of the rekey window for the first VPN tunnel (determined by tunnel1_rekey_margin_time_seconds) during which the rekey time is randomly selected. Valid value is between 0 and 100 number null no
tunnel1_rekey_margin_time_seconds (Optional, Default 540) The margin time, in seconds, before the phase 2 lifetime expires, during which the AWS side of the first VPN connection performs an IKE rekey. The exact time of the rekey is randomly selected based on the value for tunnel1_rekey_fuzz_percentage. Valid value is between 60 and half of tunnel1_phase2_lifetime_seconds number null no
tunnel1_replay_window_size (Optional, Default 1024) The number of packets in an IKE replay window for the first VPN tunnel. Valid value is between 64 and 2048. number null no
tunnel1_startup_action (Optional, Default add) The action to take when the establishing the tunnel for the first VPN connection. By default, your customer gateway device must initiate the IKE negotiation and bring up the tunnel. Specify start for AWS to initiate the IKE negotiation. Valid values are add | start string null no
tunnel2_dpd_timeout_action (Optional, Default clear) The action to take after DPD timeout occurs for the second VPN tunnel. Specify restart to restart the IKE initiation. Specify clear to end the IKE session. Valid values are clear | none | restart string null no
tunnel2_dpd_timeout_seconds (Optional, Default 30) The number of seconds after which a DPD timeout occurs for the second VPN tunnel. Valid value is equal or higher than 30 number null no
tunnel2_enable_tunnel_lifecycle_control (Optional) Turn on or off tunnel endpoint lifecycle control feature for the second VPN tunnel. Valid values are true | false bool null no
tunnel2_ike_versions (Optional) The IKE versions that are permitted for the second VPN tunnel. Valid values are ikev1 | ikev2 list(string) null no
tunnel2_inside_cidr The CIDR block of the inside IP addresses for the second VPN tunnel. string "" no
tunnel2_log_options (Optional) Options for sending VPN tunnel logs to CloudWatch. any {} no
tunnel2_phase1_dh_group_numbers (Optional) List of one or more Diffie-Hellman group numbers that are permitted for the second VPN tunnel for phase 1 IKE negotiations. Valid values are 2 | 14 | 15 | 16 | 17 | 18 | 19 | 20 | 21 | 22 | 23 | 24 list(number) null no
tunnel2_phase1_encryption_algorithms (Optional) List of one or more encryption algorithms that are permitted for the second VPN tunnel for phase 1 IKE negotiations. Valid values are AES128 | AES256 | AES128-GCM-16 | AES256-GCM-16 list(string) null no
tunnel2_phase1_integrity_algorithms (Optional) One or more integrity algorithms that are permitted for the second VPN tunnel for phase 1 IKE negotiations. Valid values are SHA1 | SHA2-256 | SHA2-384 | SHA2-512 list(string) null no
tunnel2_phase1_lifetime_seconds (Optional, Default 28800) The lifetime for phase 1 of the IKE negotiation for the second VPN tunnel, in seconds. Valid value is between 900 and 28800 number null no
tunnel2_phase2_dh_group_numbers (Optional) List of one or more Diffie-Hellman group numbers that are permitted for the second VPN tunnel for phase 2 IKE negotiations. Valid values are 2 | 5 | 14 | 15 | 16 | 17 | 18 | 19 | 20 | 21 | 22 | 23 | 24 list(number) null no
tunnel2_phase2_encryption_algorithms (Optional) List of one or more encryption algorithms that are permitted for the second VPN tunnel for phase 2 IKE negotiations. Valid values are AES128 | AES256 | AES128-GCM-16 | AES256-GCM-16 list(string) null no
tunnel2_phase2_integrity_algorithms (Optional) List of one or more integrity algorithms that are permitted for the second VPN tunnel for phase 2 IKE negotiations. Valid values are SHA1 | SHA2-256 | SHA2-384 | SHA2-512 list(string) null no
tunnel2_phase2_lifetime_seconds (Optional, Default 3600) The lifetime for phase 2 of the IKE negotiation for the second VPN tunnel, in seconds. Valid value is between 900 and 3600 number null no
tunnel2_preshared_key The preshared key of the second VPN tunnel. string "" no
tunnel2_rekey_fuzz_percentage (Optional, Default 100) The percentage of the rekey window for the second VPN tunnel (determined by tunnel1_rekey_margin_time_seconds) during which the rekey time is randomly selected. Valid value is between 0 and 100 number null no
tunnel2_rekey_margin_time_seconds (Optional, Default 540) The margin time, in seconds, before the phase 2 lifetime expires, during which the AWS side of the second VPN connection performs an IKE rekey. The exact time of the rekey is randomly selected based on the value for tunnel2_rekey_fuzz_percentage. Valid value is between 60 and half of tunnel2_phase2_lifetime_seconds number null no
tunnel2_replay_window_size (Optional, Default 1024) The number of packets in an IKE replay window for the second VPN tunnel. Valid value is between 64 and 2048. number null no
tunnel2_startup_action (Optional, Default add) The action to take when the establishing the tunnel for the second VPN connection. By default, your customer gateway device must initiate the IKE negotiation and bring up the tunnel. Specify start for AWS to initiate the IKE negotiation. Valid values are add | start string null no
tunnel_inside_ip_version (Optional) Indicate whether the VPN tunnels process IPv4 or IPv6 traffic. Valid values are ipv4 | ipv6. ipv6 Supports only EC2 Transit Gateway. string "ipv4" no
vpc_id The id of the VPC where the VPN Gateway lives. string null no
vpc_subnet_route_table_count The number of subnet route table ids being passed in via vpc_subnet_route_table_ids. number 0 no
vpc_subnet_route_table_ids The ids of the VPC subnets for which routes from the VPN Gateway will be propagated. list(string) [] no
vpn_connection_static_routes_destinations List of CIDRs to be used as destination for static routes (used with vpn_connection_static_routes_only = true). Routes to destinations set here will be propagated to the routing tables of the subnets defined in vpc_subnet_route_table_ids. list(string) [] no
vpn_connection_static_routes_only Set to true for the created VPN connection to use static routes exclusively (only if create_vpn_connection = true). Static routes must be used for devices that don't support BGP. bool false no
vpn_gateway_id The id of the VPN Gateway. string null no

Outputs

Name Description
tunnel1_preshared_key The preshared key of the first VPN tunnel.
tunnel2_preshared_key The preshared key of the second VPN tunnel.
vpn_connection_customer_gateway_configuration The configuration information for the VPN connection's customer gateway (in the native XML format) if create_vpn_connection = true, or empty otherwise
vpn_connection_id A list with the VPN Connection ID if create_vpn_connection = true, or empty otherwise
vpn_connection_transit_gateway_attachment_id The transit gateway attachment ID that was generated when attaching this VPN connection.
vpn_connection_tunnel1_address A list with the the public IP address of the first VPN tunnel if create_vpn_connection = true, or empty otherwise
vpn_connection_tunnel1_cgw_inside_address A list with the the RFC 6890 link-local address of the first VPN tunnel (Customer Gateway Side) if create_vpn_connection = true, or empty otherwise
vpn_connection_tunnel1_vgw_inside_address A list with the the RFC 6890 link-local address of the first VPN tunnel (VPN Gateway Side) if create_vpn_connection = true, or empty otherwise
vpn_connection_tunnel2_address A list with the the public IP address of the second VPN tunnel if create_vpn_connection = true, or empty otherwise
vpn_connection_tunnel2_cgw_inside_address A list with the the RFC 6890 link-local address of the second VPN tunnel (Customer Gateway Side) if create_vpn_connection = true, or empty otherwise
vpn_connection_tunnel2_vgw_inside_address A list with the the RFC 6890 link-local address of the second VPN tunnel (VPN Gateway Side) if create_vpn_connection = true, or empty otherwise

Authors

Module is maintained by Anton Babenko with help from these awesome contributors.

License

Apache 2 Licensed. See LICENSE for full details.

terraform-aws-vpn-gateway's People

Contributors

antonbabenko avatar aramatev avatar bequiet88 avatar betajobot avatar bryantbiggs avatar cdsre avatar christian-vdz avatar danielgadd avatar dev-slatto avatar diego-ojeda-binbash avatar dkravetz avatar enieuw avatar jmahowald avatar jrkalf-cambrian avatar juho9000 avatar lsc avatar maartenvanderhoef avatar mhvelplund avatar miguelaferreira avatar ppieprzycki avatar sc250024 avatar semantic-release-bot avatar stefan-matic avatar stevie- avatar tomoatki avatar visit1985 avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

terraform-aws-vpn-gateway's Issues

Migration from 2.8.0 to 3.0.0 fails

inputs = {
transit_gateway_id = local.transit_gateway_id
customer_gateway_id = local.customer_gateway_id
connect_to_transit_gateway = true
vpn_connection_static_routes_only = true
vpn_connection_static_routes_destinations = local.vpn_static_routes
}

Note - no tunnel cidrs and tunnel preshared keys set.

The errors are in the output, all place where "try(coalesce...." is used.

β”‚ Error: Error in function call
β”‚
β”‚ on outputs.tf line 3, in output "vpn_connection_id":
β”‚ 3: value = try(coalesce(
β”‚ 4: aws_vpn_connection.default[0].id,
β”‚ 5: aws_vpn_connection.tunnel[0].id,
β”‚ 6: aws_vpn_connection.preshared[0].id,
β”‚ 7: aws_vpn_connection.tunnel_preshared[0].id,
β”‚ 8: "")
β”‚ 9: )
β”‚ β”œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€
β”‚ β”‚ while calling try(expressions...)
β”‚ β”‚ aws_vpn_connection.default[0].id is "vpn-1234567890"
β”‚ β”‚ aws_vpn_connection.preshared is empty tuple
β”‚ β”‚ aws_vpn_connection.tunnel is empty tuple
β”‚ β”‚ aws_vpn_connection.tunnel_preshared is empty tuple
β”‚
β”‚ Call to function "try" failed: no expression succeeded:
β”‚ - Invalid index (at outputs.tf:5,30-33)
β”‚ The given key does not identify an element in this collection value: the collection has no elements.
β”‚ - Invalid index (at outputs.tf:6,33-36)
β”‚ The given key does not identify an element in this collection value: the collection has no elements.
β”‚ - Invalid index (at outputs.tf:7,40-43)
β”‚ The given key does not identify an element in this collection value: the collection has no elements.
β”‚
β”‚ At least one expression must produce a successful result.

$ tf --version
Terraform v1.3.4
on darwin_amd64

  • provider registry.terraform.io/hashicorp/aws v4.39.0

Support accelerator for tgw connections

Is your request related to a new offering from AWS?

Is this functionality available in the AWS provider for Terraform? See CHANGELOG.md, too.

See: https://registry.terraform.io/providers/hashicorp/aws/latest/docs/resources/vpn_connection#enable_acceleration

Is your request related to a problem? Please describe.

To use Global Accelerator for low latency and high throughput, you can enable acceleration on site-to-site VPN connections.

Describe the solution you'd like.

An option enable_acceleration would be great that, maybe in combination with a check if connect_to_transit_gateway is set as this is only usable with tgw.

Describe alternatives you've considered.

Can't see any.

Additional context

https://docs.aws.amazon.com/vpn/latest/s2svpn/accelerated-vpn.html

Make examples to work as expected

@miguelaferreira I hope you don't mind finishing this as soon as possible.

The instructions described in README.md in each example directory should work (terraform init => plan => apply => destroy). It is one of the requirements for any good module, especially in terraform-aws-modules :)

Now there are 2 main problems with them:

Thanks!

Enable acceleration flag when use TGW

Is your request related to a new offering from AWS?

Is this functionality available in the AWS provider for Terraform?

Is your request related to a problem? Please describe.

To use Global Accelerator for low latency and high throughput, you can enable acceleration on site-to-site VPN connections.

Describe the solution you'd like.

An option enable_acceleration would be great that, maybe in combination with a check if connect_to_transit_gateway is set as this is only usable with tgw.

Describe alternatives you've considered.

Can't see any.

Additional context

I have seen same issues and feat requests for adding this flag. Why is the requests was ingnored? It's very useful flag

Add variable for Name tag

Is your request related to a new offering from AWS?

Is this functionality available in the AWS provider for Terraform? See CHANGELOG.md, too.

  • Yes βœ…: please list the AWS provider version which introduced this functionality

Describe the solution you'd like.

I have multiple VPN connections and name "VPN Connection between VPC vpc-zyx and Customer Gateway cgw-xyz" doesn't tell much.
Do you think you can variablize it with default option set as it is right now?

Describe alternatives you've considered.

Additional context

Support static Tunnel CIDR in module

Hey,
First of all, thanks for this great module. Appreciate it!

Can you please support the following parameters of TF resource aws_vpn_connection:
tunnel1_inside_cidr - (Optional) The CIDR block of the inside IP addresses for the first VPN tunnel.
tunnel2_inside_cidr - (Optional) The CIDR block of the second IP addresses for the first VPN tunnel.
tunnel1_preshared_key - (Optional) The preshared key of the first VPN tunnel.
tunnel2_preshared_key - (Optional) The preshared key of the second VPN tunnel.

They have been added in TF 0.11.3 and AWS module 1.8.0 - if you are too busy, I can open a Pull Request as well. Just let me know.

Thanks and cheers,
Jochen

Please add preshared keys to output

If I want to use this module as part of establishing fx a VPN tunnel between GCP and AWS, I need access to the preshared keys from the AWS VPN connection.

These are part of the vpn_customer_gateway_configuration output from the module, but the content is in XML.
This requires parsing, to be able to use just the PSKs.So far, I have worked around this with a data source of type external, which calls a small Python script, that extracts and returns the preshared keys.

This is obviously sub optimal, so it would be great if the tunnel1_preshared_key and tunnel2_preshared_key attributes from the vpn_gateway.aws_vpn_connection.default[0] resource could be added as outputs.

Variable `dpd_timeout_seconds` not set

Description

Is there a reason why dpd_timeout_seconds is not set (for both tunnels) in the preshared and tunnel_preshared resources?

⚠️ Note

The 2 variables are set in the default and tunnel resources:

  tunnel1_dpd_timeout_seconds = var.tunnel1_dpd_timeout_seconds
  tunnel2_dpd_timeout_seconds = var.tunnel2_dpd_timeout_seconds

Versions

  • Terraform: 1.0.2
  • Provider(s):
  • Module:

Reproduction

Code Snippet to Reproduce

Expected behavior

The 2 variable are set in all the 4 resources.

Actual behavior

Cannot set the DPD timeout for the preshared and tunnel_preshared

Terminal Output Screenshot(s)

Additional context

Confusion over public/private subnets for route table propagation

I have a question about the labeling in the examples. It's unclear to me what is supposed to be public and private, and whether or not the public subnets also need to be included in vpc_subnet_route_table_ids

This variable seems to define a list of private subnets:

variable "vpc_private_subnets" {
  type    = "list"
  default = ["10.10.11.0/24", "10.10.12.0/24", "10.10.13.0/24"]
}

But it is actually being used as public subnets:

module "vpc" {
...
  private_subnets = ["10.10.1.0/24", "10.10.2.0/24", "10.10.3.0/24"]
  public_subnets  = ["${var.vpc_private_subnets}"]

And, where I'm most confused, the only route tables with propagation added are the private subnets, but the count is the public subnet variable.

module "vpn_gateway" {
...
  vpc_subnet_route_table_ids   = ["${module.vpc.private_route_table_ids}"]
  vpc_subnet_route_table_count = "${length(var.vpc_private_subnets)}"

My questions are:

  1. is this naming accidental or intentional? (perhaps I'm missing something!)
  2. do public subnets also need to be added to vpc_subnet_route_table_ids?
  3. why are propagate_public_route_tables_vgw and propagate_private_route_tables_vgw not set in the VPC module?

Thanks for your time!

Importing unrelated resource causes an Error

I have this module being called 4 times to create different vpn connections with VPC ID, VGW and CGW being pased to the module.

When I try to import a resource, while it's preparing it throws the following error:

Error: Invalid template interpolation value

  on .terraform/modules/vpn-connection/terraform-aws-modules-terraform-aws-vpn-gateway-051039a/main.tf line 13, in locals:
  13:   connection_identifier = var.connect_to_transit_gateway ? "TGW ${var.transit_gateway_id}" : "VPC ${var.vpc_id}"
    |----------------
    | var.vpc_id is null

The expression result is null. It cannot include a null value in a string
template.

Only way around this for now is having to comment out the VPN module and import.

Create branch terraform011

Can a maintainer please create a branch terraform011 from tag v0.6.1?

Users that haven't yet upgraded to terraform 0.12 would still appreciate support for 0.11.

Remove hard requirement for Customer Gateway

I'm requesting a review of the required argument: customer_gateway_id.

Description:
I have use cases where I would be working with a virtual gateway (vpn gateway) but not setting up a VPN connection or would require a customer_gateway_id, i.e., working with direct connect virtual interfaces.

Expected Behavior:
If the create_vpn_connection argument is set to false, it should remove the required argument customer_gateway_id

Please reach out if additional feedback is required.

Feature Request - Add inputs to configure local_ipv4_network_cidr and remote_ipv4_network_cidr

Some statically-routed policy-based VPNs, like Cisco Meraki, require you to configure the local_ipv4_network_cidr and remote_ipv4_network_cidr VPN connection parameters. These parameters cannot be configured using the current terraform-aws-vpn-gateway module and they are required to create a functional policy-based VPN in scenarios when you are not tunneling all traffic to AWS.

Note: There is presently an issue hashicorp/terraform-provider-aws#16879 with the aws provider that prevents you from configuring any CIDR prefix with less than 32 network bits. The issue will need to be resolved before this feature can be added to this module.

VPN Connection Id missing when creating static routes for gateway

I'm trying to create a VPN connection in my VPC w/ static routes, but when the routes are attempted to be made, the vpnConnectionId is missing

terraform.tfvars

  vpc_cidr         = "172.23.0.0/16"
  azs              = ["us-west-1a", "us-west-1c"]
  public_subnets   = ["172.23.1.0/24", "172.23.4.0/24"]
  private_subnets  = ["172.23.2.0/24", "172.23.5.0/24"]
  database_subnets = ["172.23.3.0/24", "172.23.6.0/24"]
  create_database_subnet_route_table = "false"

  static_private_routes = [
    "10.4.0.0/16",
    "172.16.3.0/24",
    "172.17.0.0/24",
    "192.168.200.0/22"
  ]

  create_gateway = "true"

  enable_vpn_gateway = "true"

  propagate_private_route_tables_vgw = "true"

  ###########################
  # PROD_GW3 Customer Gateway
  ###########################
  prod_gw3_ip_address = "x.x.x.x"
  
  #############
  # VPN1 Tunnel
  #############
  vpn1_tunnel1_inside_cidr = "x.x.x.x/30"
  vpn1_tunnel2_inside_cidr = "x.x.x.x/30"

Modules

  terraform {
    backend "s3" {}
  }

  provider "aws" {
    version = "~> 1.31.0"
    region  = "${var.region}"
    profile = "${var.profile}"
  }

  ###########
  # VPC setup
  ###########
  module "vpc" {
    source  = "terraform-aws-modules/vpc/aws"
    version = "1.44.0"

    enable_vpn_gateway                 = "${var.enable_vpn_gateway}"
    propagate_private_route_tables_vgw = "${var.propagate_private_route_tables_vgw}"

    ...
  }

 ###############
 # VPN 1 Gateway
 ###############
 module "vpn1_gateway" {
    source  = "terraform-aws-modules/vpn-gateway/aws"
    version = "1.5.0"

    vpc_id                       = "${module.vpc.vpc_id}"
    vpn_gateway_id               = "${module.vpc.vgw_id}"
    customer_gateway_id          = "${aws_customer_gateway.prod_gw3.id}"
    vpc_subnet_route_table_ids   = ["${module.vpc.private_route_table_ids}"]
    vpc_subnet_route_table_count = "${length(var.private_subnets)}"

    vpn_connection_static_routes_destinations = "${var.static_private_routes}"
    vpn_connection_static_routes_only         = "true"

    create_vpn_connection         = "${var.create_gateway}"
    create_vpn_gateway_attachment = "${var.create_gateway}"

    tunnel1_inside_cidr = "${var.vpn1_tunnel1_inside_cidr}"
    tunnel2_inside_cidr = "${var.vpn1_tunnel2_inside_cidr}"
  }

 ##########
 # PROD GW3
 ##########
 resource "aws_customer_gateway" "prod_gw3" {
   count = "${var.create_gateway? 1 : 0}"

    bgp_asn    = 65000
    ip_address = "${var.prod_gw3_ip_address}"
    type       = "ipsec.1"
  }

Error / output

module.vpn1_gateway.aws_vpn_connection_route.default[2]: Creating...
  destination_cidr_block: "" => "172.17.0.0/24"
module.vpn1_gateway.aws_vpn_connection_route.default[0]: Creating...
  destination_cidr_block: "" => "10.4.0.0/16"
module.vpn1_gateway.aws_vpn_connection_route.default[3]: Creating...
  destination_cidr_block: "" => "192.168.200.0/22"
module.vpn1_gateway.aws_vpn_connection_route.default[1]: Creating...
  destination_cidr_block: "" => "172.16.3.0/24"
Releasing state lock. This may take a few moments...

Error: Error applying plan:

4 error(s) occurred:

* module.vpn1_gateway.aws_vpn_connection_route.default[1]: 1 error(s) occurred:

* aws_vpn_connection_route.default.1: Error creating VPN connection route: MissingParameter: The request must contain the parameter vpnConnectionId
	status code: 400, request id: ecabe556-90bc-4405-b455-1b8328d82efd
* module.vpn1_gateway.aws_vpn_connection_route.default[2]: 1 error(s) occurred:

* aws_vpn_connection_route.default.2: Error creating VPN connection route: MissingParameter: The request must contain the parameter vpnConnectionId
	status code: 400, request id: fff15287-b3e9-483f-a9ab-ed69183a16f4
* module.vpn1_gateway.aws_vpn_connection_route.default[3]: 1 error(s) occurred:

* aws_vpn_connection_route.default.3: Error creating VPN connection route: MissingParameter: The request must contain the parameter vpnConnectionId
	status code: 400, request id: 99aa694f-e42a-4224-b784-e5481780eb55
* module.vpn1_gateway.aws_vpn_connection_route.default[0]: 1 error(s) occurred:

* aws_vpn_connection_route.default.0: Error creating VPN connection route: MissingParameter: The request must contain the parameter vpnConnectionId
	status code: 400, request id: e9bd7aa6-eb69-4900-994d-f7c53f73516a

It looks like its failing right here, but I'm not sure yet why the connection is not being found?

Add create_before_destroy for Customer Gateway resources

Description

When you try to change the IP for a customer gateway resource, following error is encountered:

Error: error deleting EC2 Customer Gateway (cgw-abcde): IncorrectState: The customer gateway is in use. status code: 400, request id: 1234xyz

I think adding a create_before_destroy to the customer gateway resource should fix it.

Clean up repeated aws_vpn_connection

Is your request related to a new offering from AWS?

No

Is your request related to a problem? Please describe.

No

Describe the solution you'd like.

The module has 4 implementations of aws_vpn_connection however 95% of the code in each resource is identical. With only a few differing lines. These seem to center around 4 differnt variables creating several flavours tunnel1_preshared_key, tunnel2_preshared_key, tunnel1_inside_cidr, tunnel2_inside_cidr. These variables are then used to form 4 flavours

  • default - No preshared keys or inside cidrs
  • tunnel - no preshared keys but inside cidrs
  • preshared - preshared keys but no inside cidrs
  • preshared_tunnel - preshared keys and inside cidrs.

This issue is raised to consider reducing the complexity of the flavours and module and make the code DRY to reduce having to make new changes in several places in the code. My general idea is to always pass these variables however with a conditional that checks the value and if its an empty string then pass a null value. However this functionality would only work for versions of terraform V0.12.0 onwards as documented in https://github.com/hashicorp/terraform/releases/tag/v0.12.0

Nullable argument values: It is now possible to use a conditional expression like var.foo != "" ? var.foo : null to conditionally leave an argument value unset, whereas before Terraform required the configuration author to provide a specific default value in this case. Assigning null to an argument is equivalent to omitting that argument entirely.

An example might look like:

  tunnel1_inside_cidr = var.tunnel1_inside_cidr != "" ? var.tunnel1_inside_cidr : null
  tunnel2_inside_cidr = var.tunnel2_inside_cidr != "" ? var.tunnel2_inside_cidr : null

  tunnel1_preshared_key = var.tunnel1_preshared_key != "" ? var.tunnel1_preshared_key : null
  tunnel2_preshared_key = var.tunnel2_preshared_key != "" ? var.tunnel2_preshared_key : null

This could mean we only need to define aws_vpn_connection resource and remove a lot of the repeated code and the local variables. I have not tested any of this. I wanted to float the idea here first before refactoring any of the code. By testing the variables against an empty string we keep the interface of the module intact. This should keep the module backwards compatible with any calling code.

Describe alternatives you've considered.

If we wanted to remove the empty string ternary check when setting the attribute in the resource we could change the default from "" to null but this would not be backwards compatible.

Additional context

If the community feels there is value in this I am happy to pick up the work and refactor and submit a PR for it.

VPN Connection Preshared forces new resource each run

module.vpn_gateway.aws_vpn_connection.preshared Attempts to compute a new ID each run, and also also forces new resource based on preshared keys. Is this expected behaviour? The state objects looks perfectly fine to me.

Variable dpd_timeout_seconds cannot be set for preshared and tunnel_preshared

Description

Is there a reason why dpd_timeout_seconds is not set (for both tunnels) in the preshared and tunnel_preshared resources?

⚠️ Note

The 2 variables are set in the default and tunnel resources:

  tunnel1_dpd_timeout_seconds = var.tunnel1_dpd_timeout_seconds
  tunnel2_dpd_timeout_seconds = var.tunnel2_dpd_timeout_seconds

Versions

  • Module version: 2.12.1
  • Terraform version: 1.2.2
  • Provider version(s): aws 3.7.3

Expected behavior

The 2 variable are set in all the 4 resources.

Actual behavior

Cannot set the DPD timeout for the preshared and tunnel_preshared

More info

Related to unresolved issue - #59

Output refers to sensitive values

Version of module 3.0.1
❯ terraform --version
Terraform v1.3.4
on darwin_amd64

  • provider registry.terraform.io/hashicorp/aws v4.39.0

Error message after apply

β”‚ Error: Output refers to sensitive values
β”‚
β”‚ on outputs.tf line 81:
β”‚ 81: output "vpn_connection_customer_gateway_configuration" {
β”‚
β”‚ To reduce the risk of accidentally exporting sensitive data that was
β”‚ intended to be only internal, Terraform requires that any root module
β”‚ output containing sensitive data be explicitly marked as sensitive, to
β”‚ confirm your intent.
β”‚
β”‚ If you do intend to export this data, annotate the output value as
β”‚ sensitive by adding the following argument:
β”‚ sensitive = true

Can you import an existing VPN?

We use this module and also have manual assets, can I use this module with the older assets by importing them? I'm not sure how to map them?

v2.12 breaks for IPv4 only setup

Description

I was using this module earlier and it was working perfectly however upgrading to v2.12 adds an error related to IPv6 configuration, which I am not using.

Rolling back to v2.11.1 solves the issue.

Error

Error: Missing required argument
β”‚
β”‚ with module.aws-gcp-vpn-tunnels.module.vpn_gateway.aws_vpn_connection.tunnel_preshared[0],
β”‚ on .terraform/modules/aws-gcp-vpn-tunnels.vpn_gateway/main.tf line 304, in resource "aws_vpn_connection" "tunnel_preshared":
β”‚ 304: local_ipv6_network_cidr = var.local_ipv6_network_cidr
β”‚
β”‚ "local_ipv6_network_cidr": all of
β”‚ local_ipv6_network_cidr,transit_gateway_id must be specified

Unable to override name of VPN connection with "tags".

When creating the VPN Connection, the "Name" tag is pre-configured to be:
"VPN Connection between VPC vpc-xxxxxx and Customer Gateway cgw-xxxx"

If a "Name" tag is provided in the tags variable for the module, the error:

β•·
β”‚ Error: Provider produced inconsistent final plan
β”‚
β”‚ When expanding the plan for module.infra.module.vpn_gateway[0].aws_vpn_connection.default[0] to include new values learned so far during apply,
β”‚ provider "registry.terraform.io/hashicorp/aws" produced an invalid new value for .tags_all: new element "Name" has appeared.
β”‚
β”‚ This is a bug in the provider, which should be reported in the provider's own issue tracker.
β•΅
β•·

Versions

  • Terraform: 1.0.11
  • Provider(s):
  • provider registry.terraform.io/hashicorp/aws v3.65.0
  • provider registry.terraform.io/hashicorp/random v3.1.0
  • provider registry.terraform.io/hashicorp/tls v3.1.0
  • provider registry.terraform.io/vancluever/acme v2.6.0
  • Module:
  • terraform-aws-modules/vpn-gateway/aws version 2.11.0

Expected behavior

The "Name" tag for the VPN connection should use the tags.Name provided instead of defining its own.

Actual behavior

An error was produced as above.

Error when using example <complete-vpn-connection-transit-gateway>

Terraform v0.12.20
provider.aws v2.47.0

if i do:

i get the error message down below.

terraform plan
Refreshing Terraform state in-memory prior to plan...
The refreshed state will be used to calculate this plan, but will not be
persisted to local or remote state storage.

Error: Invalid template interpolation value

  on ../../main.tf line 13, in locals:
  13:   connection_identifier = var.connect_to_transit_gateway ? "TGW ${var.transit_gateway_id}" : "VPC ${var.vpc_id}"
    |----------------
    | var.vpc_id is null

The expression result is null. Cannot include a null value in a string
template.```

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    πŸ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. πŸ“ŠπŸ“ˆπŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❀️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.