【问题标题】:Terraform - Error creating NAT Gateway: InvalidElasticIpID.MalformedTerraform - 创建 NAT 网关时出错:InvalidElasticIpID.Malformed
【发布时间】:2022-01-18 10:29:19
【问题描述】:

我想使用 Terraform 创建一个具有固定公共 IP 地址的 VPN,我可以将其分配给我们的 Lambda 函数。

我找到了这篇博文和执行此操作的代码:

但是,当我运行脚本时,我得到了这个错误:

│ Error: Error creating NAT Gateway: InvalidElasticIpID.Malformed: The elastic-ip ID 'aws_eip.ip.id' is malformed
│       status code: 400, request id: 96b26796-931d-4470-85b5-5c46c39889a9
│ 
│   with aws_nat_gateway.natgateway,
│   on natgateway.tf line 1, in resource "aws_nat_gateway" "natgateway":
│    1: resource "aws_nat_gateway" "natgateway" {

这是natgateway.tf文件的内容:

resource "aws_nat_gateway" "natgateway" {
  allocation_id = "aws_eip.ip.id"
  subnet_id     = "aws_subnet.publicsubnet.id"
  tags = {
    name = "prod nategatway"
  }
  depends_on = [aws_eip.eip]
}

我尝试过的事情:

  • 在没有创建其他 VPC 的干净区域上运行脚本 - 仍然无法正常工作
  • 在 Github 上提出了一个问题:https://github.com/Jaffarterraform786/vpc/issues/2
  • 运行 Terraform 检查器以查看是否有任何错误,但未发现任何错误。

我需要更改脚本中的任何线索或内容?

【问题讨论】:

标签: amazon-web-services terraform terraform-provider-aws amazon-vpc elastic-ip


【解决方案1】:

natgateway.tf 中有错误的字符串。更正的版本是:

resource "aws_nat_gateway" "natgateway" {
  allocation_id = aws_eip.eip.id
  subnet_id     = aws_subnet.publicsubnet.id
  tags = {
    name = "prod nategatway"
  }
  depends_on = [aws_eip.eip]
}

请注意,我不检查 VPC 或其其他资源的有效性。我只是解决您报告的错误。

【讨论】:

  • 嗨@Marcin,如果可以的话,我想补充一点。我查看了 repo,使用depends_on 上的Internet Gateway 资源比使用EIP 更好。 Internet Gateway 可能由于多种原因而失败,但 EIP 很容易创建,并且可以为 Nat Gateway terraform 资源提供“误报”。
猜你喜欢
  • 2015-04-07
  • 2021-01-19
  • 2020-11-24
  • 2015-10-28
  • 2020-08-29
  • 2021-04-18
  • 2021-03-02
  • 2021-07-09
  • 2019-12-14
相关资源
最近更新 更多