CloudWiki
Resource

Site-to-Site VPN Connection

Amazon Web Services
Network
Amazon Site-to-Site VPN is a fully managed service that creates a secure connection between an on-premises network and a VPC using an Internet Protocol security (IPsec) connection.
Terraform Name
terraform
aws_vpn_connection
Site-to-Site VPN Connection
attributes:

The following arguments are required:

  • customer_gateway_id - (Required) The ID of the customer gateway.
  • type - (Required) The type of VPN connection. The only type AWS supports at this time is "ipsec.1".

One of the following arguments is required:

  • transit_gateway_id - (Optional) The ID of the EC2 Transit Gateway.
  • vpn_gateway_id - (Optional) The ID of the Virtual Private Gateway.

Other arguments:

  • static_routes_only - (Optional, Default false) Whether the VPN connection uses static routes exclusively. Static routes must be used for devices that don't support BGP.
  • enable_acceleration - (Optional, Default false) Indicate whether to enable acceleration for the VPN connection. Supports only EC2 Transit Gateway.
  • tags - (Optional) Tags to apply to the connection. If configured with a provider default_tags configuration block present, tags with matching keys will overwrite those defined at the provider-level.
  • local_ipv4_network_cidr - (Optional, Default 0.0.0.0/0) The IPv4 CIDR on the customer gateway (on-premises) side of the VPN connection.
  • local_ipv6_network_cidr - (Optional, Default ::/0) The IPv6 CIDR on the customer gateway (on-premises) side of the VPN connection.
  • outside_ip_address_type - (Optional, Default PublicIpv4) Indicates if a Public S2S VPN or Private S2S VPN over AWS Direct Connect. Valid values are PublicIpv4 | PrivateIpv4
  • remote_ipv4_network_cidr - (Optional, Default 0.0.0.0/0) The IPv4 CIDR on the AWS side of the VPN connection.
  • remote_ipv6_network_cidr - (Optional, Default ::/0) The IPv6 CIDR on the customer gateway (on-premises) side of the VPN connection.
  • transport_transit_gateway_attachment_id - (Required when outside_ip_address_type is set to PrivateIpv4). The attachment ID of the Transit Gateway attachment to Direct Connect Gateway. The ID is obtained through a data source only.
  • tunnel_inside_ip_version - (Optional, Default ipv4) Indicate whether the VPN tunnels process IPv4 or IPv6 traffic. Valid values are ipv4 | ipv6. ipv6 Supports only EC2 Transit Gateway.
  • tunnel1_inside_cidr - (Optional) The CIDR block of the inside IP addresses for the first VPN tunnel. Valid value is a size /30 CIDR block from the 169.254.0.0/16 range.
  • tunnel2_inside_cidr - (Optional) The CIDR block of the inside IP addresses for the second VPN tunnel. Valid value is a size /30 CIDR block from the 169.254.0.0/16 range.
  • tunnel1_inside_ipv6_cidr - (Optional) The range of inside IPv6 addresses for the first VPN tunnel. Supports only EC2 Transit Gateway. Valid value is a size /126 CIDR block from the local fd00::/8 range.
  • tunnel2_inside_ipv6_cidr - (Optional) The range of inside IPv6 addresses for the second VPN tunnel. Supports only EC2 Transit Gateway. Valid value is a size /126 CIDR block from the local fd00::/8 range.
  • tunnel1_preshared_key - (Optional) The preshared key of the first VPN tunnel. The preshared key must be between 8 and 64 characters in length and cannot start with zero(0). Allowed characters are alphanumeric characters, periods(.) and underscores(_).
  • tunnel2_preshared_key - (Optional) The preshared key of the second VPN tunnel. The preshared key must be between 8 and 64 characters in length and cannot start with zero(0). Allowed characters are alphanumeric characters, periods(.) and underscores(_).
  • 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.
  • 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.
  • 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.
  • 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.
  • tunnel1_ike_versions - (Optional) The IKE versions that are permitted for the first VPN tunnel. Valid values are ikev1 | ikev2.
  • tunnel2_ike_versions - (Optional) The IKE versions that are permitted for the second VPN tunnel. Valid values are ikev1 | ikev2.
  • tunnel1_log_options - (Optional) Options for logging VPN tunnel activity. See Log Options below for more details.
  • tunnel2_log_options - (Optional) Options for logging VPN tunnel activity. See Log Options below for more details.
  • 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.
  • 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.
  • 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.
  • 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.
  • 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.
  • 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.
  • 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.
  • 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.
  • 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.
  • 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.
  • 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.
  • 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.
  • 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.
  • 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.
  • 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.
  • 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.
  • 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.
  • tunnel2_rekey_fuzz_percentage - (Optional, Default 100) The percentage of the rekey window for the second VPN tunnel (determined by tunnel2_rekey_margin_time_seconds) during which the rekey time is randomly selected. Valid value is between 0 and 100.
  • 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.
  • 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.
  • 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.
  • 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.
  • 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.
  • 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.

Log Options

The tunnel1_log_options and tunnel2_log_options block supports the following arguments:

  • cloudwatch_log_options - (Optional) Options for sending VPN tunnel logs to CloudWatch. See CloudWatch Log Options below for more details.

CloudWatch Log Options

The cloudwatch_log_options blocks supports the following arguments:

  • log_enabled - (Optional) Enable or disable VPN tunnel logging feature. The default is false.
  • log_group_arn - (Optional) The Amazon Resource Name (ARN) of the CloudWatch log group to send logs to.
  • log_output_format - (Optional) Set log format. Default format is json. Possible values are: json and text. The default is json.

Associating resources with a
Site-to-Site VPN Connection
Resources do not "belong" to a
Site-to-Site VPN Connection
Rather, one or more Security Groups are associated to a resource.
Create
Site-to-Site VPN Connection
via Terraform:
The following HCL creates a VPN connection between the specified transit gateway and specified customer gateway
Syntax:

resource "aws_ec2_transit_gateway" "example" {}

resource "aws_customer_gateway" "example" {
 bgp_asn    = 65000
 ip_address = "172.0.0.1"
 type       = "ipsec.1"
}

resource "aws_vpn_connection" "example" {
 customer_gateway_id = aws_customer_gateway.example.id
 transit_gateway_id  = aws_ec2_transit_gateway.example.id
 type                = aws_customer_gateway.example.type
}

Create
Site-to-Site VPN Connection
via CLI:
Parameters:

create-vpn-connection
--customer-gateway-id <value>
--type <value>
[--vpn-gateway-id <value>]
[--transit-gateway-id <value>]
[--dry-run | --no-dry-run]
[--options <value>]
[--tag-specifications <value>]
[--cli-input-json | --cli-input-yaml]
[--generate-cli-skeleton <value>]
[--debug]
[--endpoint-url <value>]
[--no-verify-ssl]
[--no-paginate]
[--output <value>]
[--query <value>]
[--profile <value>]
[--region <value>]
[--version <value>]
[--color <value>]
[--no-sign-request]
[--ca-bundle <value>]
[--cli-read-timeout <value>]
[--cli-connect-timeout <value>]
[--cli-binary-format <value>]
[--no-cli-pager]
[--cli-auto-prompt]
[--no-cli-auto-prompt]

Example:

aws ec2 create-vpn-connection \
   --type ipsec.1 \
   --customer-gateway-id cgw-001122334455aabbc \
   --vpn-gateway-id vgw-1a1a1a1a1a1a2b2b2 \
   --tag-specification 'ResourceType=vpn-connection,Tags=[{Key=Name,Value=BGP-VPN}]'

aws cost
Costs
VPN connection costs include the cost of the VPN Gateway, data transfer fees, and charges for the number of VPN connections. The cost of an AWS VPN connection depends on the type of VPN Gateway and the amount of data transfer. To minimize costs, it's important to choose the right type of VPN Gateway and to optimize data transfer by using Direct Connect or a VPN over the AWS Global Network instead of the public internet.
Direct Cost

VPN-Usage-Hours:ipsec.1

DataTransfer-Out-Bytes

<Region>-<Region>-AWS-Out-Bytes

Best Practices for
Site-to-Site VPN Connection

Categorized by Availability, Security & Compliance and Cost

Low
Access allowed from VPN
No items found.
Low
Auto Scaling Group not in use
No items found.
Medium
Connections towards DynamoDB should be via VPC endpoints
No items found.
Medium
Container in CrashLoopBackOff state
No items found.
Low
EC2 with GPU capabilities
No items found.
Medium
EC2 with high privileged policies
No items found.
Medium
ECS cluster delete alarm
No items found.
Critical
ECS task with Admin access (*:*)
Medium
ECS task with high privileged policies
No items found.
Critical
EKS cluster delete alarm
No items found.
Medium
ElastiCache cluster delete alarm
No items found.
Medium
Ensure Container liveness probe is configured
No items found.
Medium
Ensure ECS task definition has memory limit
No items found.
Critical
Ensure EMR cluster master nodes are not publicly accessible
No items found.
More from
Amazon Web Services