2
votes

I am trying to setup AWS SFTP transfer in vpc endpoint mode but there is one think I can't manage with. The problem I have is how to get target IPs for NLB target group. The only output I found:

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)
}

gives network interface ids which cannot be used as targets:

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",
]

I went through:

terraform get subnet integration ips from vpc endpoint subnets tab and Terraform how to get IP address of aws_lb

but none of them seems to be working. The latter says:

  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
There seems to be something missing in your question: the error message refers to a local value named nlb_interface_ids. Could you please add the source code for that local value to your question as well, to show the full context? Ideally, it would help to have a minimal reproducible example. - Martin Atkins
@MartinAtkins: If this is not a problem, this is my ticket in Github with source code: github.com/terraform-providers/terraform-provider-aws/issues/… - localsystemuser

1 Answers

2
votes

You can create an Elastic IP

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

Then specify the Elastic IPs while creating Network LB

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}"
  }
}