Terraform获取vpc端点子网的IP

时间:2020-01-20 11:38:10

标签: amazon-web-services terraform

我正在尝试以vpc终端节点模式设置AWS SFTP传输,但是有一种我认为无法处理的问题。 我的问题是如何获取NLB目标组的目标IP。 我发现的唯一输出是:

output "vpc_endpoint_transferserver_network_interface_ids" {
  description = "One or more network interfaces for the VPC Endpoint for transferserver"
  value       = flatten(aws_vpc_endpoint.transfer_server.*.network_interface_ids)
}

提供不能用作目标的网络接口ID:

Outputs:

api_url = https://12345.execute-api.eu-west-1.amazonaws.com/prod
vpc_endpoint_transferserver_network_interface_ids = [
  "eni-12345",
  "eni-67890",
  "eni-abcde",
]

我经历了:

terraform get subnet integration ips from vpc endpoint subnets tabTerraform how to get IP address of aws_lb

但它们似乎都没有起作用。后者说:

  on modules/sftp/main.tf line 134, in data "aws_network_interface" "ifs":
 134:   count = "${length(local.nlb_interface_ids)}"

The "count" value depends on resource attributes that cannot be determined
until apply, so Terraform cannot predict how many instances will be created.
To work around this, use the -target argument to first apply only the
resources that the count depends on.

1 个答案:

答案 0 :(得分:2)

您可以创建一个弹性IP

resource "aws_eip" "lb" {
  instance = "${aws_instance.web.id}"
  vpc      = true
}

然后在创建网络LB时指定弹性IP

resource "aws_lb" "example" {
  name               = "example"
  load_balancer_type = "network"

  subnet_mapping {
    subnet_id     = "${aws_subnet.example1.id}"
    allocation_id = "${aws_eip.example1.id}"
  }

  subnet_mapping {
    subnet_id     = "${aws_subnet.example2.id}"
    allocation_id = "${aws_eip.example2.id}"
  }
}