GithubHelp home page GithubHelp logo

ebs_bckup's Introduction

tf_ebs_bckup

a Lambda-powered EBS Snapshot Terraform Module

A Terraform module for creating a Lambda Function that takes automatic snapshots of of all connected EBS volumes of correspondingly tagged instances. The function is triggered via a CloudWatch event that watches for an instance changing to the stopped state. Its purpose is to capture EBS volumes from COB the previous day, for multiple timezones. It works in the basis that we stop instances overnight (outside of production obviously) to reduce costs, but we don't terminate them.

Input Variables:

  • EC2_INSTANCE_TAG - All instances with this tag name be backed up. Default is "PreviousEbsBackup" with a value of never. Will be overwritten after 1st EBS snapshot is taken, showing the date of the current backup.
  • RETENTION_DAYS - Number of day the created EBS Snapshots will be stored, defaults to 7
  • unique_name - Just a marker for the Terraform stack. Default is "v1"`
  • stack_prefix - Prefix for resource generation. Default is ebs_bckup
  • regions - List of regions in which the Lambda function should run. Requires at least one entry (eg. ["eu-west-1", "us-west-1"])

Outputs

Default outputs are aws_iam_role_arn with the value of the created IAM role for the Lambda function and the lambda_function_name

Example usage

In your Terrafom main.tf call the module with the required variables.

module "ebs_bckup" {
  source = "github.com/mistawes/ebs_bckup"
  EC2_INSTANCE_TAG = "PreviousEbsBackup"
  RETENTION_DAYS   = 7
  unique_name      = "v1"
  stack_prefix     = "ebs_snapshot"
  regions          = ["eu-west-1"]
  instance_state   = "stopped"
  #TAGS_TO_COPY    = ["Name", "CostCentre"]
}

ToDo

Confirm the new tagging method to trigger using Key instead of Value works 100%

Confirm tags are still being included on EBS snapshots.

Fix using tags in variables, instead of hard-coded in main.tf.

Credits

Thanks to kgorskowski for the base ebs_bckup solution.

Thanks to rastandy for adding more tags to EBS snapshot.

Mistawes Changed this to allow for multiple timezones, using an instance changing state as a trigger. Also prevents duplicate backups, thanks to the modified tagging method.

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.