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

igw.tf#L1
resource "aws_internet_gateway" "tappo-igw" {
    vpc_id = "vpc-0244d3fdc467a2783"

    tags {
        "Name" = "tappo-igw"
    }
main.tf#L10
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
}

5-igw.tf#L16
resource "aws_internet_gateway" "london_igw" {
  vpc_id = aws_vpc.london_vpc.id

  tags = {
    Name  = "salawu-live-demo"
    OWNER = "salawu"
igw.tf#L3
resource "aws_internet_gateway" "igw_a" {
  vpc_id = aws_vpc.infra_vpc_a.id
  tags = {
      Name = format("%s-vpc-a-igw", var.infra_name)
  }
}
igw.tf#L3
resource "aws_internet_gateway" "igw_a" {
  vpc_id = aws_vpc.infra_vpc_a.id
  tags = {
      Name = format("%s-vpc-a-igw", var.infra_name)
  }
}

Review your Terraform file for AWS best practices

Shisho Cloud, our free checker to make sure your Terraform configuration follows best practices, is available (beta).

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.

risk-label

aws_default_vpc

Ensure to avoid using default VPC

It is better to define the own VPC and use it.

risk-label

aws_network_acl_rule

Ensure your network ACL rule blocks unwanted inbound traffic

It is better to block unwanted inbound traffic.

risk-label

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).

risk-label

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.

risk-label

aws_security_group

Ensure your security group blocks unwanted inbound traffic

It is better to block unwanted inbound traffic.

Review your AWS Amazon EC2 settings

In addition to the above, there are other security points you should be aware of making sure that your .tf files are protected in Shisho Cloud.

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

template.yml#L97
    #   Type: AWS::EC2::InternetGateway
    #   Properties:
    #     Tags:
    #     - Key: Name
    #       Value: FirstVPC-IGW
    # Amazon Kinesis Data Firehose
2_Add_Internet_Gateway.yml#L92
    Type: AWS::EC2::InternetGateway
    Properties:
      Tags:
        - Key: Name
          Value: devigw
  IGWAttchDev:
peering.yml#L46
    Type: AWS::EC2::InternetGateway
    Condition: IfUSWestRegion
    Properties:
      Tags:
      - Key: Name
        Value: "IGWUSA"
InternetGateway.yml#L2
  Type: AWS::EC2::InternetGateway
  Properties:
    Tags:
      - Key: "Name"
        Value: ${self:custom.defaultProfile}-internet-gateway-${self:provider.stage}
stg:
ServerlessInternetGateway.yml#L1
Type: AWS::EC2::InternetGateway
Properties:
  Tags:
    -
      Key: "Name"
vpcbasic.json#L79
            "Type": "AWS::EC2::InternetGateway",
            "DependsOn": "VPC1",
            "Properties": {
                "Tags": [
                    {
                        "Key": "Name",
VPCprod.json#L73
            "Type": "AWS::EC2::InternetGateway",
            "DependsOn": "Vpc1",
            "Properties": {
                "Tags": [{ "Key": "Name", "Value": "Vpc1igw"}]
            }
        },
cfn-vpc-gateway-attachment-update-stack.json#L7
            "Type" : "AWS::EC2::InternetGateway",
            "Properties" : {
            }
        },

        "IG2" : {
cfn-vpc-gateway-attachment-initial-stack.json#L7
            "Type" : "AWS::EC2::InternetGateway",
            "Properties" : {
            }
        },

        "IG2" : {
resource_internet_gateway_output_1.json#L3
    "Type": "AWS::EC2::InternetGateway"
  }
}

Parameters

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.