Terraform: Feature Request: IDs & IPs for autoscaling group instances

Created on 23 Aug 2016  ยท  4Comments  ยท  Source: hashicorp/terraform

It would be useful for the aws_autoscaling_group to provide a list of instances and their IP addresses as an attribute, similar to the way aws_spot_workers provide the instance_id, private_ip, and public_ip attributes.

This would allow terraform-inventory and similar tools to display the resulting instances.

For example, it would be useful to have the following state for `aws_autoscaling_groups

aws_autoscaling_group.autoscaling_workers:
  id = mycluster-subnet-829bfbf4
  availability_zones.# = 1
  availability_zones.221770259 = us-west-2b
  default_cooldown = 300
  desired_capacity = 5
  force_delete = false
  health_check_grace_period = 300
  health_check_type = EC2
  instance_id.# = 2
  instance_id.0 = i-abcdef
  instance_id.1 = i-123456
  launch_configuration = mycluster-subnet-829bfbf4-atvlaiarrzhk5cwo5vpbs7mhxu
  load_balancers.# = 0
  max_size = 20
  metrics_granularity = 1Minute
  min_size = 5
  name = mycluster-subnet-829bfbf4
  placement_group =
  public_ip.# = 0
  private_ip.# = 2
  private_ip.0 = "172.16.0.1"
  private_ip.1 = "172.16.0.2"
  protect_from_scale_in = false
  tag.# = 0
  target_group_arns.# = 0
  termination_policies.# = 0
  vpc_zone_identifier.# = 1
  vpc_zone_identifier.1110689163 = subnet-829bfbf4
  wait_for_capacity_timeout = 10m

AWS does seem to provide an API for querying aws autoscaling instances:

aws autoscaling describe-auto-scaling-instances

{
    "AutoScalingInstances": [
        {
            "InstanceId": "i-80269c14",
            "HealthStatus": "HEALTHY",
            "AvailabilityZone": "us-west-2b",
            "AutoScalingGroupName": "mycluster-subnet-829bfbf4",
            "LifecycleState": "InService"
        }
    ]
}

A recursive lookup would be needed to determine the IP addresses.

enhancement provideaws

Most helpful comment

Hi @cbarbour! Thanks for this feature request.

This is not exported by Terraform because the set of instances is something that changes (by design) independently of any action Terraform takes. In normal operation the state for a resource is only updated (in persistent storage) when it is created or updated, so any instance list exposed would be very likely to be stale.

In general it is not a goal for the Terraform state to be used as an inventory system for this reason. While very static infrastructures can be represented in this way, Terraform isn't able to react to dynamic changes without non-standard usage patterns such as explicitly running terraform refresh periodically to resynchronize the persistent state.

So with all of this said, I'm going to close this. I agree that what you describe would be useful in principle, but it isn't really compatible with how Terraform works. Thanks again for opening this!

All 4 comments

For anyone looking for just extracting the IPs of autoscaling groups, I have created a temporary workaround (module extract): https://github.com/arehmandev/Terraform-ASGIP/blob/master/main.tf

Its a little complex but I've tried documenting it a little.

Very much needed feature, any news on its implementation?

Hi @cbarbour! Thanks for this feature request.

This is not exported by Terraform because the set of instances is something that changes (by design) independently of any action Terraform takes. In normal operation the state for a resource is only updated (in persistent storage) when it is created or updated, so any instance list exposed would be very likely to be stale.

In general it is not a goal for the Terraform state to be used as an inventory system for this reason. While very static infrastructures can be represented in this way, Terraform isn't able to react to dynamic changes without non-standard usage patterns such as explicitly running terraform refresh periodically to resynchronize the persistent state.

So with all of this said, I'm going to close this. I agree that what you describe would be useful in principle, but it isn't really compatible with how Terraform works. Thanks again for opening this!

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 have found a problem that seems similar to this, please open a new issue and complete the issue template so we can capture all the details necessary to investigate further.

Was this page helpful?
0 / 5 - 0 ratings

Related issues

rkulagowski picture rkulagowski  ยท  3Comments

jrnt30 picture jrnt30  ยท  3Comments

rjinski picture rjinski  ยท  3Comments

pawelsawicz picture pawelsawicz  ยท  3Comments

carl-youngblood picture carl-youngblood  ยท  3Comments