Skip to content
This repository has been archived by the owner on Oct 14, 2022. It is now read-only.

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

Open
jkzilla opened this issue Apr 3, 2019 · 1 comment
Open

Comments

@jkzilla
Copy link

jkzilla commented Apr 3, 2019

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.

@MikeyYeahYeah
Copy link
Contributor

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?

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants