enterprise-setup icon indicating copy to clipboard operation
enterprise-setup copied to clipboard

Add id as an output to the state file to make stopping instances easier

Open jkzilla opened this issue 6 years ago • 1 comments

https://groups.google.com/forum/#!topic/terraform-tool/hEESOVOgL_Q

Not with Terraform, but it's pretty easy to stop and start an instance with the CLI tools if you have them installed:

$ aws ec2 stop-instances --region us-east-2 --instance-ids i-0123456789abcdef

$ aws ec2 start-instances --region us-east-2 --instance-ids i-0123456789abcdef

If you need to fetch the instance ID quickly, you can define a TF output and get at it that way:

$ terraform output id
i-0123456789abcdef

Or if its buried in a module somewhere you can get it from the state:

$ terraform state show module.service.aws_instance.host |awk '$1=="id"{print $3}'
i-0123456789abcdef

Combine things and do:

$ aws ec2 stop-instances --region us-east-2 --instance-ids $( terraform output id )

Enjoy.

jkzilla avatar Apr 03 '19 21:04 jkzilla

Thanks for the feedback! I am not fully understanding what the ask is here. Can you please provide a little more detail about Add id as an output to the state file? What would the desired outcome be?

MikeyYeahYeah avatar Jun 03 '19 17:06 MikeyYeahYeah