AWS Amazon EC2 VPN Gateway Attachment
This page shows how to write Terraform and CloudFormation for Amazon EC2 VPN Gateway Attachment and write them securely.
aws_vpn_gateway_attachment (Terraform)
The VPN Gateway Attachment in Amazon EC2 can be configured in Terraform with the resource name aws_vpn_gateway_attachment
. The following sections describe 2 examples of how to use the resource and its parameters.
Example Usage from GitHub
resource "aws_vpn_gateway_attachment" "ptl_vpn_gw_attachment" {
count = var.ptl_connected ? 1 : 0
vpc_id = aws_vpc.base_vpc.id
vpn_gateway_id = data.aws_vpn_gateway.ptl_gateway[0].id
}
resource "aws_vpn_gateway_attachment" "vpn_attachment_vpg_1" {
vpc_id = aws_vpc.vpc_1.id
vpn_gateway_id = aws_vpn_gateway.virtual_private_gateway_1.id
depends_on = [
aws_vpc.vpc_1,
aws_vpn_gateway.virtual_private_gateway_1
Parameters
-
id
optional computed - string -
vpc_id
required - string -
vpn_gateway_id
required - string
Explanation in Terraform Registry
Provides a Virtual Private Gateway attachment resource, allowing for an existing hardware VPN gateway to be attached and/or detached from a VPC. -> Note: The
aws_vpn_gateway
resource can also automatically attach the Virtual Private Gateway it creates to an existing VPC by setting thevpc_id
attribute accordingly.
Tips: Best Practices for The Other AWS Amazon EC2 Resources
In addition to the aws_default_vpc, AWS Amazon EC2 has the other resources that should be configured for security reasons. Please check some examples of those resources and precautions.
aws_default_vpc
Ensure to avoid using default VPC
It is better to define the own VPC and use it.
aws_network_acl_rule
Ensure your network ACL rule blocks unwanted inbound traffic
It is better to block unwanted inbound traffic.
aws_ebs_volume
Ensure to use a customer-managed key for EBS volume encryption
It is better to use a customer-managed key for EBS volume encryption. It can be gain more control over the encryption by using customer-managed keys (CMK).
aws_instance
Ensure to avoid storing AWS access keys in user data
It is better to avoid storing AWS access keys in user data. `aws_iam_instance_profile` could be used instead.
aws_security_group
Ensure your security group blocks unwanted inbound traffic
It is better to block unwanted inbound traffic.
AWS::EC2::VPNGateway (CloudFormation)
The VPNGateway in EC2 can be configured in CloudFormation with the resource name AWS::EC2::VPNGateway
. The following sections describe 10 examples of how to use the resource and its parameters.
Example Usage from GitHub
Type: AWS::EC2::VPNGateway
Properties:
Type: ipsec.1
Tags:
- Key: Name
Value:
Type: "AWS::EC2::VPNGateway"
Properties:
Type: ipsec.1
VPCGatewayAttachment:
Type: "AWS::EC2::VPCGatewayAttachment"
Type: "AWS::EC2::VPNGateway"
Properties:
Type: "ipsec.1"
VpnConnection:
Type: "AWS::EC2::VPNConnection"
Type: "AWS::EC2::VPNGateway"
Properties:
Type: ipsec.1
VPNconnection:
Type: "AWS::EC2::VPNConnection"
Properties:
Type: "AWS::EC2::VPNGateway"
Properties:
Type: ipsec.1
VPNconnection:
Type: "AWS::EC2::VPNConnection"
Properties:
"Type": "AWS::EC2::VPNGateway",
"Properties": {
"Type": "ipsec.1",
"Tags": [
{
"Key": "Name",
"Type": "AWS::EC2::VPNGateway",
"Properties": {
"Type": "ipsec.1",
"Tags": [
{
"Key": "Name",
"Type": "AWS::EC2::VPNGatewayRoutePropagation"
},
"aclentry1": {
"Properties": {
"CidrBlock": "172.16.0.0/24",
"Egress": "true",
"Type" : "AWS::EC2::VPNGateway",
"Properties" : {
"Type" : "ipsec.1"
}
},
"VpnConnectionGreen" : {
"Type" : "AWS::EC2::VPNGateway",
"Properties" : {
"Type" : "ipsec.1",
"Tags" : [ { "Key" : "Name", "Value" : "Production" } ]
}
},
Parameters
-
AmazonSideAsn
optional - Long -
Tags
optional - List of Tag -
Type
required - String
Explanation in CloudFormation Registry
Specifies a virtual private gateway. A virtual private gateway is the endpoint on the VPC side of your VPN connection. You can create a virtual private gateway before creating the VPC itself.
For more information, see AWS Site-to-Site VPN in the AWS Site-to-Site VPN User Guide.
Frequently asked questions
What is AWS Amazon EC2 VPN Gateway Attachment?
AWS Amazon EC2 VPN Gateway Attachment is a resource for Amazon EC2 of Amazon Web Service. Settings can be wrote in Terraform and CloudFormation.
Where can I find the example code for the AWS Amazon EC2 VPN Gateway Attachment?
For Terraform, the nhsconnect/integration-adaptors and juliocesarscheidt/vpn-site-to-site-aws source code examples are useful. See the Terraform Example section for further details.
For CloudFormation, the librannk/AWS-CloudFormation-tmplte, djoreilly/aws-vpn-testing and anri-c/my-aws-cf-templates source code examples are useful. See the CloudFormation Example section for further details.