Coder Social home page Coder Social logo

julb / terraform-aws-lambda-auto-start-stop-ec2-autoscalinggroups Goto Github PK

View Code? Open in Web Editor NEW
0.0 2.0 0.0 18 KB

License: MIT License

Makefile 18.94% Python 44.64% HCL 36.42%
terraform terraform-module aws lambda ec2 ec2-autoscaling cost-optimization

terraform-aws-lambda-auto-start-stop-ec2-autoscalinggroups's Introduction

terraform-aws-lambda-auto-start-stop-ec2-autoscalinggroups

A terraform module to start or stop EC2 instances part of an Auto Scaling Group on a periodic basis.

In order to save some AWS costs, it is usual to stop Non-Production assets out of business hours. This module enables to stop or start EC2 instances part of an Auto Scaling Group at the time you need. Please note that EC2 instances not managed by an Auto Scaling Group are excluded. See julb/terraform-aws-lambda-auto-start-stop-ec2-instances module to manage these ones.

See related modules:

Usage

  • Stop EC2 Auto Scaling Groups
module "stop_ec2_auto_scaling_groups" {
  source              = "github.com/julb/terraform-aws-lambda-auto-start-stop-ec2-autoscalinggroups"
  name                = "StopEc2AutoScalingGroups"
  schedule_expression = "cron(0 0 ? * FRI *)"
  action              = "stop"
  tags                = { "custom:tag" : "someValue" }
  lookup_resource_tag = {
    key   = "ops:env"
    value = "non-prod"
  }
}
  • Start EC2 Auto Scaling Groups
module "start_ec2_auto_scaling_groups" {
  source              = "github.com/julb/terraform-aws-lambda-auto-start-stop-ec2-autoscalinggroups"
  name                = "StartEc2AutoScalingGroups"
  schedule_expression = "cron(0 8 ? * MON *)"
  action              = "start"
  tags                = { "custom:tag" : "someValue" }
  lookup_resource_tag = {
    key   = "ops:env"
    value = "non-prod"
  }
}

Module Input Variables

Name Type Default Description
schedule_expression string  Not Set  The CloudWatch Schedule Expression to trigger the Lambda. Can be a CRON expression for example. Required.
name string  Not Set  The name of the lambda to create. Required.
tags map(string)  {}  The tags to assign to the created resources.
custom_iam_role_arn string  Not Set  The IAM role to assign to the Lambda. If not specified, a role with appropriate permissions will be created.
action string  Not Set  The action to perform. Valid values are enable,disable. (start, stop are supported aliases as well). Required.
lookup_resource_tag object{key=string, value=string}  Not Set  The tags to filter on to look for EC2 instances within the regions. Required.
lookup_resource_regions list(string)  Not Set Look for EC2 instances in the specified regions. By default, it uses the region in which the lambda is deployed.

Outputs

Name Type Description
lambda_function_name  string  The Lambda function name.
lambda_arn ARN  The Lambda Amazon Resource Identifier.
lambda_iam_role_arn ARN  The IAM Role Amazon Resource Identifier assigned to the Lambda.
lambda_log_group_name string  The CloudWatch Log Group name in which the Lambda push logs.
lambda_log_group_arn ARN  The CloudWatch Log Group Amazon Resource Identifier assigned in which the Lambda push logs.

Contributing

This project is totally open source and contributors are welcome.

When you submit a PR, please ensure that the python code is well formatted and linted.

$ make format
$ make lint
$ make test

terraform-aws-lambda-auto-start-stop-ec2-autoscalinggroups's People

Contributors

github-actions[bot] avatar julb avatar

Watchers

 avatar  avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.