-
Notifications
You must be signed in to change notification settings - Fork 9.3k
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
Get Private IP of instance launched by autoscaling group #511
Comments
I just had a need for this today. I would love for this to be a real thing. |
I ran into a need for this today. I'd love this to exist. Any updates on the request? |
Hello – Can you describe the use case here? I'm curious why you would want the direct IP of any instance that's in an autoscaling group, as opposed to connecting via a Load Balancer. If I'm not mistaken a specific advantage of an ASG is ensuring you have a certain number of instances available and running, not that any given one of them exists at a certain IP. If the ASG resource were to export a private IP, and on AWS side the ASG were to change instances for any reason, that IP could become stale until your next plan and apply, right? In which case there could be a window of time when your A record routes you to a bad IP, correct? Where as if the A record pointed to an IP that's assigned to a load balance, the roll over would happen automatically. I'm curious how exposing this would be used in a reliable, stable way. Thanks! |
@catsby You are correct in saying that IP would be stale and Terraform would need to run in order to update the A record attached to the Route53 record. We have use case that we have a set of servers that run different jobs. Everything is controlled in puppet and Terraform. Right now we have a module that builds off a count (normally). What we wanted to do was put them into an ASG in order to have self healing in case a node would fail. However we cant move forward with testing due to there is no output of private ips or a node list. We started an effect sometime ago to remove IP Address from configs and swap to DNS names. It would be icing on the cake if we can build a way to self heal these servers in case of aws instance failure using ASG. |
+1 |
Another use case This sets up a bastion in an autoscaling group min=max=desired=1. The reasoning behind this is to autorelaunch the bastion if it goes down. W/o this however I have to do a check after to see what ip the bastion actually got. |
It would be very useful to have this feature. Users can run types of one off workloads with a list of known IPs for the ASG within a null_resource. +1 for me as well. |
@catsby Look at my comment in the closed issue migrated here: hashicorp/terraform#11713 To repeat:
Also no one says that ASG has to be related to an ELB, in our case we have the instances behind HAProxy so we need to know their IP's. This has been opened since February, is it really that difficult to resolve? |
@catsby Another example, I want to create Route53 DNS records and health checks after launching instances:
When instances are launched via ASG there is no way to do this. We are forced to move this code into user-data instead which is big PITA. |
+1 |
Any update on this? |
I'm not opposed to this feature in general but I do have opinions on how it should be implemented. I'll also be upfront and say that we (HashiCorp) are unlikely to get to this feature soon, but gladly welcome contributions if someone can pick it up. As for how to implement:
So the problem here in short is that the IP Addresses are not returned by default and you need to do a handful of additional API calls to get them. For large setups, these extra API calls add up quickly, so by default, we should not include Instance IP Addresses in the state of AutoScaling Groups. I recognize it's a useful feature but also think it will not be an often used one, so by default we shouldn't consume all these API calls. That said, I believe/propose we can support this functionality with a data source:
Alternatively we could expand the To get the IP address(es) for the Instance(s) we need to call DescribeInstances for each one. Fortunately we can use an EC2Filter and filter by I believe this new data source would keep this instance information in a So in the end the out put of this data source would be like this:
How does this sound? resource "autoscaling_group" "example" {
[...]
}
data "autoscaling_group" "example_ips" {
autoscaling_id = "${aws_autoscaling_group.example.id}"
# Fetch Instance information
# Retrieves instance information
# Retrieves public_ip's
# Retrieves private_ip's
get_instance_properties = true
}
resource "aws_route53_record" "service-record" {
zone_id = "<my-zone-id>"
count = 2
name = "service-lb-${format("%03d", count.index + 1)}.mydomain.com"
type = "A"
ttl = "60"
records = ["${element(data.aws_autoscaling_group.example_ips.private_ips, count.index)}"]
} |
@catsby I love this and it would help a lot. |
@catsby beautiful! |
any update on this, in real need of this solution. |
Has this been looked at? a complete stopper on what im required to do. |
any update on this? |
This would be amazing to have! |
This would be glorious! Since Lambda triggered by CloudWatchEvent is a mess! |
Need this one too |
Anyone find workaround or solution for this issue? This is completely show stopper for what I need to do. |
+1 |
3 similar comments
+1 |
+1 |
+1 |
+1 |
3 similar comments
+1 |
+1 |
+1 |
Here are some solutions that I implement:
Hope this helps |
+1 |
1 similar comment
+1 |
Is there currently any workaround available? |
This way allowed me to get ips of worker nodes:
Sure, this workaround has the limitations, but worked for me. |
@catsby One use case is for cluster setup. In such a scenario we want to be able to only provide the SSH keys of the instances to people who want to test a cluster like kafka, zookeeper, elasticsearch etc without having to give them access to the AWS console. If terraform could simply output the private ip address then the troubleshooters would have a list of IP addresses to log into simply with their SSH keys and without requiring access to AWS Console. |
+1 |
@catsby Yeah another use case is when making a kubernetes cluster through an asg. you need the master's private ip to feed into the workers. Is there someone who knows a work around for this? |
+1 |
1 similar comment
+1 |
+1. My use case involves Hashicorp Vault, which needs to be initialised before being recognised as a healthy node by the load balancer. |
+1 |
Any workarounds for Google Cloud Platform? It has the same problem with |
@igoratencompass I do use I tag the instances in the template and use this tag to retrieve IPs in the |
I see was not aware of that feature of data module. |
#511 (comment) is a workaround but be carefull doc page
This note is other reason to implement this new data source |
you can pull all instance data with a round about lookup. ( example assuming some asg named aws_autoscaling_group.one is already defined )
but I would much prefer to have the instance data directly available in the asg attributes. |
@syncroswitch the problem I see with this is the |
@syncroswitch @igoratencompass it works to get the endpoints and private ips when you launch, which is what is mostly needed. Also, just set If people truly have need of dynamic ips then they should write it up in python, bash, go, etc and call it from terraform then use that instead of the desired capacity but I doubt it will really be necessary or desired in the long run. |
I started off with @syncroswitch's config and ended with a simpler workaround: data "aws_instances" "ecs_instances_meta" {
instance_tags = {
# Use whatever name you have given to your instances
Name = var.ecs_cluster_name
}
}
output "ecs-private-ips" {
value = data.aws_instances.ecs_instances_meta.private_ips
} |
5 yrs later - and still unresolved? |
A big no. |
Deep sigh, needed this. filter { instance_state_names = ["running", "stopped"] |
This issue was originally opened by @coolgooze as hashicorp/terraform#11713. It was migrated here as part of the provider split. The original body of the issue is below.
ASG
resource "aws_autoscaling_group" "REDIS_ASG" {
name = "${var.environment}-REDIS_ASG"
launch_configuration = "${aws_launch_configuration.redis_launch_conf.name}"
#availability_zones = ["us-west-2a", "us-west-2b", "us-west-2c"]
vpc_zone_identifier = ["${data.aws_subnet.PrivateDBSubnetAZ1.id}","${data.aws_subnet.PrivateDBSubnetAZ2.id}","${data.aws_subnet.PrivateDBSubnetAZ3.id}"]
min_size = 1
max_size = 1
desired_capacity = 1
health_check_grace_period = 600
health_check_type = "EC2"
force_delete = "false"
termination_policies = ["OldestInstance"]
tag {
key = "Name"
value = "${var.environment}-int-redis"
propagate_at_launch = true
}
}
i am trying to create a A Record
resource "aws_route53_record" "redis" {
zone_id = "${data.aws_route53_zone.dns.zone_id}"
name = "redis-${var.environment}.${data.aws_route53_zone.dns.name}"
type = "A"
ttl = "60"
records = ["${aws_autoscaling_group.REDIS_ASG.private_ip}"]
}
Output-
The text was updated successfully, but these errors were encountered: