AWS Amazon EC2 Internet Gateway
This page shows how to write Terraform and CloudFormation for Amazon EC2 Internet Gateway and write them securely.
aws_internet_gateway (Terraform)
The Internet Gateway in Amazon EC2 can be configured in Terraform with the resource name aws_internet_gateway
. The following sections describe 5 examples of how to use the resource and its parameters.
Example Usage from GitHub
resource "aws_internet_gateway" "tappo-igw" {
vpc_id = "vpc-0244d3fdc467a2783"
tags {
"Name" = "tappo-igw"
}
resource "aws_internet_gateway" "igw_us-east-1" {
provider = aws.us-east-1
vpc_id = aws_vpc.symbol-mainnet_us-east-1.id
tags = var.vpc_tags
}
resource "aws_internet_gateway" "london_igw" {
vpc_id = aws_vpc.london_vpc.id
tags = {
Name = "salawu-live-demo"
OWNER = "salawu"
resource "aws_internet_gateway" "igw_a" {
vpc_id = aws_vpc.infra_vpc_a.id
tags = {
Name = format("%s-vpc-a-igw", var.infra_name)
}
}
resource "aws_internet_gateway" "igw_a" {
vpc_id = aws_vpc.infra_vpc_a.id
tags = {
Name = format("%s-vpc-a-igw", var.infra_name)
}
}
Parameters
-
arn
optional computed - string -
id
optional computed - string -
owner_id
optional computed - string -
tags
optional - map from string to string -
vpc_id
optional - string
Explanation in Terraform Registry
Provides a resource to create a VPC Internet Gateway.
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::InternetGateway (CloudFormation)
The InternetGateway in EC2 can be configured in CloudFormation with the resource name AWS::EC2::InternetGateway
. The following sections describe 10 examples of how to use the resource and its parameters.
Example Usage from GitHub
# Type: AWS::EC2::InternetGateway
# Properties:
# Tags:
# - Key: Name
# Value: FirstVPC-IGW
# Amazon Kinesis Data Firehose
Type: AWS::EC2::InternetGateway
Properties:
Tags:
- Key: Name
Value: devigw
IGWAttchDev:
Type: AWS::EC2::InternetGateway
Condition: IfUSWestRegion
Properties:
Tags:
- Key: Name
Value: "IGWUSA"
Type: AWS::EC2::InternetGateway
Properties:
Tags:
- Key: "Name"
Value: ${self:custom.defaultProfile}-internet-gateway-${self:provider.stage}
stg:
Type: AWS::EC2::InternetGateway
Properties:
Tags:
-
Key: "Name"
"Type": "AWS::EC2::InternetGateway",
"DependsOn": "VPC1",
"Properties": {
"Tags": [
{
"Key": "Name",
"Type": "AWS::EC2::InternetGateway",
"DependsOn": "Vpc1",
"Properties": {
"Tags": [{ "Key": "Name", "Value": "Vpc1igw"}]
}
},
"Type" : "AWS::EC2::InternetGateway",
"Properties" : {
}
},
"IG2" : {
"Type" : "AWS::EC2::InternetGateway",
"Properties" : {
}
},
"IG2" : {
"Type": "AWS::EC2::InternetGateway"
}
}
Parameters
-
Tags
optional - List of Tag
Explanation in CloudFormation Registry
Allocates an internet gateway for use with a VPC. After creating the Internet gateway, you then attach it to a VPC.
Frequently asked questions
What is AWS Amazon EC2 Internet Gateway?
AWS Amazon EC2 Internet Gateway 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 Internet Gateway?
For Terraform, the tappoflw/tappo1, symbol/symbol-infra and kaysal/cloud-networking source code examples are useful. See the Terraform Example section for further details.
For CloudFormation, the nukopy/aws-practice, Jagat45106/CloudFormation and elnurm/aws_cloudformation_templates source code examples are useful. See the CloudFormation Example section for further details.