【问题标题】:Attaching an AWS VPC to an IGW with Terraform使用 Terraform 将 AWS VPC 附加到 IGW
【发布时间】:2021-07-29 02:23:30
【问题描述】:

我正在尝试使用 Terraform 构建 VPC 资源以提供 MWAA 构建。在 AWS 文档中,我看到以下资源(除了子网等)被定义为创建一个完整的 VPC 环境。我已经使用 Terraform 定义了 aws_vpcaws_internet_gateway,但找不到 InternetGatewayAttachment 的 Terraform 模板 - 用于 aws_vpn_gateway_attachment

  1. 如何将 VPC 资源附加到带 Terraform 的 IGW?
  2. 我需要一个资源,还是 TF aws_internet_gateway 资源定义中隐含的 vpc_id?

P。 S. - 我来自 GCP,而不是超级熟悉 AWS 网络概念。

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

....

【问题讨论】:

  • 为什么在关于 Terraform 的问题中包含 CloudFormation 模板?

标签: amazon-web-services terraform terraform-provider-aws


【解决方案1】:

如果您查看the official documentation,您会看到 Internet 网关资源要求您指定 VPC ID。 Terraform 不支持在不立即将其附加到 VPC 的情况下创建 Internet 网关。

【讨论】:

    【解决方案2】:

    1 创建 VPC

    2 创建 Internet 网关

    资源“aws_vpc”“my_vpc”{ cidr_block = "10.0.0.0/16"}

    资源“aws_internet_gateway”“gw”{ vpc_id = aws_vpc.my_vpc.id}

    在互联网网关中,您可以提供 vpc 的名称。

    【讨论】:

      猜你喜欢
      • 2021-01-27
      • 1970-01-01
      • 2021-06-13
      • 2020-05-21
      • 2017-04-16
      • 2021-06-17
      • 2020-12-17
      • 2019-06-10
      • 1970-01-01
      相关资源
      最近更新 更多