Skip to content

Instantly share code, notes, and snippets.

@rquadling
Last active May 7, 2020 22:34
Show Gist options
  • Save rquadling/c2ee7f38ccac229673c1e7aabe1ad926 to your computer and use it in GitHub Desktop.
Save rquadling/c2ee7f38ccac229673c1e7aabe1ad926 to your computer and use it in GitHub Desktop.
Get autoscaling group desired capacity within Terraform

My use case is to get the current desired capacity of an autoscaling group so that I can use that in the replacement autoscaling group. I've seen a Cloudformation solution, but that required more understanding than I have at the time.

Initially, I had thought that just returning the JSON from awscli would have been enough, but unfortunately, the result for the data_source.external.result is a list of strings. No numbers, arrays, maps, lists.

So inspired by a comment made by Marin Salinas, I found that Terraform can access local files!

In addition, I am using an assumed role to do the work.

So, my second version of this gist is now documenting the module that wraps things up quite nicely I feel!

https://registry.terraform.io/modules/digitickets/cli/aws/1.1.0

If there is any feedback, please let me know.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment