Terraform - 创建 NAT 网关时出错:InvalidElasticIpID.Malformed

Terraform - Error creating NAT Gateway: InvalidElasticIpID.Malformed

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

我找到了这个博客 post 和执行此操作的代码:

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

│ 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]
}

我尝试过的事情:

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

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 或其其他资源的有效性。我只是在解决您报告的错误。