How to stop/start running ec2 instance via terraform

Viewed 3092

I have EC2 instance running with web application and this is my POC environment machine. This instance is automated through terraform, But this is running all the time when I don't need it, I want to write the terraform script to poweroff this machine if I don't want to use it so that I can save the cost.

1 Answers

There are several ways to do this with Terraform. The first solution is to follow the guidance here. It is not the most elegant solution, but it works. You must also keep track of the current state yourself.

If you would like something that is more time-of-day based, like turning on the instance at 06:00 and turning it off at 17:30, then this solution is very good.

Related