Code Monkey home page Code Monkey logo

terraform-aws-autospotting's Introduction

AutoSpotting

Automatically convert your existing Auto Scaling groups to significantly cheaper spot instances with minimal (often zero) configuration changes.

See https://github.com/autospotting/autospotting for details.

Using the terraform-aws-autospotting module

Sources

This module can be used from the Terraform Registry or directly from this repository. The AutoSpotting binary defaults to the latest nightly build hosted on S3.

Using from the Terraform Registry:

module "autospotting" {
  source  = "AutoSpotting/autospotting/aws"
  # version = "0.1.2"
}

Using from this repository:

module "autospotting" {
  source = "github.com/autospotting/terraform-aws-autospotting?ref=master" # or ref=0.1.2, etc.
}

Notes:

  • The official (nightly) AutoSpotting binary is hosted in the cloudprowess S3 bucket in AWS region us-east-1. When the source of the Lambda function is an S3 bucket, both the function and the bucket must be in the same region.

    • If you are already using the AWS provider in the us-east-1 region, no additional configuration is required:

      provider "aws" {
        region  = "us-east-1"
        profile = "default"
      }
      
      module "autospotting" {
        source = "github.com/autospotting/terraform-aws-autospotting"
      }
    • If you are using the AWS provider in another region, you must either (1) alias another AWS provider in the us-east-1 region, (2) copy the binary into an S3 bucket in the region you are already using, or (3) provide a local binary. Here, we demonstrate using an alias:

      provider "aws" {
        region  = "eu-central-1"
        profile = "default"
      }
      
      provider "aws" {
        alias   = "us"
        region  = "us-east-1"
        profile = "default"
      }
      
      module "autospotting" {
        source = "github.com/autospotting/terraform-aws-autospotting"
        providers = {
          aws = aws.us
        }
      }
    • The Lambda function can run in any supported region

  • New releases of this module only work with Terraform 0.12 or newer.

Setting variables

Available variables are defined in the variables file. To change the defaults, just pass in the relevant variables:

module "autospotting" {
  source                                = "github.com/autospotting/terraform-aws-autospotting"
  autospotting_regions_enabled          = "eu*,us*"
  autospotting_min_on_demand_percentage = "33.3"
  lambda_memory_size                    = 1024
}

Or you can pass them in on the command line:

 terraform apply \
   -var autospotting_regions_enabled="eu*,us*" \
   -var autospotting_min_on_demand_percentage="33.3" \
   -var lambda_memory_size=1024

Using custom binaries

The lambda.zip file can be generated by building it locally. Further instructions are available in the AutoSpotting repo.

You can also download the latest official nightly build available here.

From local file

If you store the file locally:

module "autospotting" {
  source         = "github.com/autospotting/terraform-aws-autospotting"
  lambda_zipname = "lambda.zip"
}

From S3

Instead of using a local ZIP file you can refer to the Lambda code in a location in S3:

module "autospotting" {
  source           = "github.com/autospotting/terraform-aws-autospotting"
  lambda_s3_bucket = "lambda-releases"
  lambda_s3_key    = "lambda.zip"
}

Multiple instances

You can change the names of the resources terraform will create โ€“ or run multiple instances of autospotting that target different ASGs โ€“ by using the label variables:

module "autospotting_storage" {
  source                              = "github.com/autospotting/terraform-aws-autospotting"
  label_name                          = "autospotting_storage"
  autospotting_allowed_instance_types = "i3.*"
  autospotting_tag_filters            = "spot-enabled=true,storage-optimized=true,"
}

module "autospotting_dev_memory" {
  source                              = "github.com/autospotting/terraform-aws-autospotting"
  label_name                          = "autospotting_memory"
  label_environment                   = "dev"
  autospotting_allowed_instance_types = "r5*"
  autospotting_tag_filters            = "spot-enabled=true,memory-optimized=true,environment=dev,"
}

Logs or Troubleshooting

To check logs and troubleshoot issues, you can go to the /aws/lambda/<your_lambda_function_name> CloudWatch Log group.

terraform-aws-autospotting's People

Contributors

neillturner avatar bfin avatar lazzurs avatar cristim avatar richardj-bsquare avatar vikas027 avatar timboven avatar danielris avatar orong-pp avatar recurrence avatar

Watchers

 avatar James Cloos 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.