0
votes

I am trying to build a VPC resource with Terraform to provide for an MWAA build. In the AWS documentation, I see the below resources (in addition to subnets, etc.) are defined to create a whole VPC environment. I have defined aws_vpc & aws_internet_gateway with Terraform, but cannot find a Terraform template for InternetGatewayAttachment - only for aws_vpn_gateway_attachment.

  1. How do I go about attaching the VPC resource to the IGW w/Terraform?
  2. Do I need an resource, or is that implied w/the vpc_id in the TF aws_internet_gateway resource definition?

P. S. - I am coming from GCP & not super familiar w/AWS Networking concepts.

Resources:
  VPC:
    Type: AWS::EC2::VPC
    Properties:
      CidrBlock: !Ref VpcCIDR
      EnableDnsSupport: true
      EnableDnsHostnames: true
      Tags:
        - Key: Name
          Value: !Ref EnvironmentName

  InternetGateway:
    Type: AWS::EC2::InternetGateway
    Properties:
      Tags:
        - Key: Name
          Value: !Ref EnvironmentName

  InternetGatewayAttachment:
    Type: AWS::EC2::VPCGatewayAttachment
    Properties:
      InternetGatewayId: !Ref InternetGateway
      VpcId: !Ref VPC

....
2
Why are you including a CloudFormation template in a question about Terraform?Mark B

2 Answers

1
votes

1 Create VPC

2 Create an Internet Gateway

resource "aws_vpc" "my_vpc" { cidr_block = "10.0.0.0/16"}

resource "aws_internet_gateway" "gw" { vpc_id = aws_vpc.my_vpc.id}

in the internet gateway you can give the name of the vpc.

0
votes

If you look at the official documentation you will see that the Internet Gateway resource requires you to specify the VPC ID. Terraform doesn't support creating internet gateways without immediately attaching them to a VPC.