Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

aws_eip_association data source #4551

Closed
alexrudd opened this issue May 16, 2018 · 5 comments · Fixed by #6518
Closed

aws_eip_association data source #4551

alexrudd opened this issue May 16, 2018 · 5 comments · Fixed by #6518
Labels
enhancement Requests to existing resources that expand the functionality or scope. service/ec2 Issues and PRs that pertain to the ec2 service. service/elbv2 Issues and PRs that pertain to the elbv2 service.
Milestone

Comments

@alexrudd
Copy link
Contributor

alexrudd commented May 16, 2018

Community Note

  • Please vote on this issue by adding a 👍 reaction to the original issue to help the community and maintainers prioritize this request
  • Please do not leave "+1" or "me too" comments, they generate extra noise for issue followers and do not help prioritize the request
  • If you are interested in working on this issue or have submitted a pull request, please leave a comment

Description

Currently there's no way to find information about an existing EIP association. Whether these be ones created manually outside of terraform, or ones created implicitly during provisioning of other resources.

The use case I have specifically for this is to get the private IP addresses of an NLB created using subnet mappings. It is very useful to be able to find out the private IP addresses used by the load balancing nodes as these need to be whitelisted for health checking purposes. Looking up the known EIPs association would be one way to determine an NLB's private IP addresses.

New or Affected Resource(s)

  • aws_eip_association (data source)

Potential Terraform Configuration

resource "aws_lb" "example" {
  name               = "example-lb-tf"
  load_balancer_type = "network"

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

data "aws_eip_association" "nlb_ip1" {
  allocation_id = "${aws_eip.example1.id}"
  depends_on    = ["aws_lb.example"]
}
data "aws_eip_association" "nlb_ip2" {
  allocation_id = "${aws_eip.example2.id}"
  depends_on    = ["aws_lb.example"]
}
data "aws_eip_association" "nlb_ip3" {
  allocation_id = "${aws_eip.example3.id}"
  depends_on    = ["aws_lb.example"]
}

resource "aws_security_group_rule" "allow_nlb_healthcheck" {
  type        = "ingress"
  from_port   = 8080
  to_port     = 8080
  protocol    = "tcp"
  cidr_blocks = [
    "${data.aws_eip_association.nlb_ip1.private_ip}"
    "${data.aws_eip_association.nlb_ip2.private_ip}"
    "${data.aws_eip_association.nlb_ip3.private_ip}"
  ]
  
  security_group_id = "sg-123456"
}

References

@bflad bflad added enhancement Requests to existing resources that expand the functionality or scope. service/elbv2 Issues and PRs that pertain to the elbv2 service. service/ec2 Issues and PRs that pertain to the ec2 service. labels May 18, 2018
@kl4w
Copy link
Contributor

kl4w commented Jul 9, 2018

@alexrudd can this be solved by adding extra attributes to the aws_eip data source: see attached PR?

@lholman
Copy link

lholman commented Aug 29, 2018

I have worked around this by using the aws_network_interface data source to get the private ip by description or tag as follows:

By description. Description is auto-populated during NLB creation and includes the NLB name and ID, e.g. ELB net/ecs-0123-load-balancer/c1da50b4bb396db4

data "aws_network_interface" "network-load-balancer-interface" {
  filter {
    name   = "description"
    values = ["*ecs-${var.cluster-number}-load-balancer*"]
  }
}

OR by tag

data "aws_network_interface" "network-load-balancer-interface" {
  filter {
    name   = "tag:YourTagKeyName"
    values = ["YourTagKeyValue"]
  }
}

When capturing as an output...

output "network-load-balancer-private-ip" {
  value = "${data.aws_network_interface.network-load-balancer-interface.private_ips}"
}

It is then yielded with a plan/apply like so

network-load-balancer-private-ip = [
    10.21.44.110
]

@bflad
Copy link
Contributor

bflad commented Nov 19, 2018

Support for the following attributes has been merged into to the aws_eip data source and will release with version 1.46.0 of the AWS provider, likely later tonight or tomorrow:

  • association_id
  • domain
  • instance_id
  • network_interface_id
  • network_interface_owner_id
  • private_ip
  • public_ipv4_pool

If there is a specific use case not solved by providing these new attributes in that data source, please feel free to open a new feature request issue. Thanks.

@bflad
Copy link
Contributor

bflad commented Nov 20, 2018

The above has been released in version 1.46.0 of the AWS provider. Please see the Terraform documentation on provider versioning or reach out if you need any assistance upgrading.

@ghost
Copy link

ghost commented Apr 2, 2020

I'm going to lock this issue because it has been closed for 30 days ⏳. This helps our maintainers find and focus on the active issues.

If you feel this issue should be reopened, we encourage creating a new issue linking back to this one for added context. Thanks!

@ghost ghost locked and limited conversation to collaborators Apr 2, 2020
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
enhancement Requests to existing resources that expand the functionality or scope. service/ec2 Issues and PRs that pertain to the ec2 service. service/elbv2 Issues and PRs that pertain to the elbv2 service.
Projects
None yet
4 participants