【问题标题】:How to assign an existing ElasticIP to a NAT in a VPC with Terraform如何使用 Terraform 将现有 ElasticIP 分配给 VPC 中的 NAT
【发布时间】:2021-05-30 13:26:28
【问题描述】:

我有一些列入白名单的 ElasticIP,我正尝试将它们用作我的 VPC 中 NAT 网关的 IP,用于 Lambda 函数。

我的 VPC 配置如下所示:

module "vpc" {
  source = "terraform-aws-modules/vpc/aws"

  name = "lambda-vpc"
  cidr = "11.0.0.0/16"

  azs                 = ["ap-southeast-2b", "ap-southeast-2c"]
  private_subnets     = ["11.0.1.0/24", "11.0.2.0/24"]
  public_subnets      = ["11.0.0.0/24"]
  enable_nat_gateway  = true
  external_nat_ip_ids = ["eipalloc-03092d9e4de71d859", "eipalloc-03092d9e4de71d859"]
}

但这会导致 NAT 网关创建自己的 ElasticIP,而不是使用已列入白名单的现有 ElasticIP。

【问题讨论】:

    标签: amazon-web-services terraform amazon-vpc nat


    【解决方案1】:

    基于模块docsreuse_nat_ips选项应与external_nat_ip_ids结合使用:

    reuse_nat_ips - 如果您不希望为您的 NAT 网关创建 EIP 并且将 改为通过“external_nat_ip_ids”变量传递它们,则应该为 true p>

    因此,假设您的代码中的其他所有内容都是正确的:

    module "vpc" {
      source = "terraform-aws-modules/vpc/aws"
    
      name = "lambda-vpc"
      cidr = "11.0.0.0/16"
    
      azs                 = ["ap-southeast-2b", "ap-southeast-2c"]
      private_subnets     = ["11.0.1.0/24", "11.0.2.0/24"]
      public_subnets      = ["11.0.0.0/24"]
      enable_nat_gateway  = true
    
      reuse_nat_ips       = true
      external_nat_ip_ids = ["eipalloc-03092d9e4de71d859", "eipalloc-03092d9e4de71d859"]
    }
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2018-05-19
      • 1970-01-01
      • 1970-01-01
      • 2017-04-16
      • 2018-03-19
      • 2022-11-14
      • 2020-05-29
      • 2020-05-29
      相关资源
      最近更新 更多