This Terraform will provision a scheduled Lambda function to shut down EC2s across all available regions (with the exception of regions you define to skip) that do not have a tag attached to them to keep running.
Variable | Description | Default |
---|---|---|
skip_regions | Comma-separated list of regions to skip. | '' |
running_tag | AWS Tag set to 'true' to indicate instances that should keep running. | KeepRunning |
cron_schedule | AWS cron schedule to execute the Lambda function (in UTC, defaults to 3AM). | 0 3 * * ? * |
-
(Optional but Recommended) If you want to store your Terraform state in a remote S3 bucket (highly recommended), copy the
backend.tf.template
file tobackend.tf
and update the values to a unique S3 bucket and the respective region you're using before moving ahead. -
On your first run, initialize Terraform:
terraform init
- In the root of this directory, run
terraform plan
with your any variables to overwrite and validate the output, for example:
terraform plan --set skip_regions=us-east-1,us-east-2
- If the output looks correct, run
terraform apply
with the same overwritten variables, typingyes
when prompted, for example:
terraform apply --set skip_regions=us-east-1,us-east-2