All Projects â†’ heap â†’ Terraform Ebs Attachmentizer

heap / Terraform Ebs Attachmentizer

Convert ebs_block_device blocks in aws_instance resource to aws_ebs_volume and aws_volume_attachment resources

Programming Languages

go
31211 projects - #10 most used programming language

Projects that are alternatives of or similar to Terraform Ebs Attachmentizer

Elastic Beanstalk Terraform Setup
🎬 Playbook for setting up & deploying AWS Beanstalk Applications on Docker with 1 command
Stars: ✭ 69 (-12.66%)
Mutual labels:  aws, terraform
Terrastack
This project is archived, but the idea of Terrastack lives on in the Terraform CDK. - https://github.com/hashicorp/terraform-cdk
Stars: ✭ 71 (-10.13%)
Mutual labels:  aws, terraform
Terraform Aws Airflow
Terraform module to deploy an Apache Airflow cluster on AWS, backed by RDS PostgreSQL for metadata, S3 for logs and SQS as message broker with CeleryExecutor
Stars: ✭ 69 (-12.66%)
Mutual labels:  aws, terraform
Terraform Aws S3 Log Storage
This module creates an S3 bucket suitable for receiving logs from other AWS services such as S3, CloudFront, and CloudTrail
Stars: ✭ 65 (-17.72%)
Mutual labels:  aws, terraform
Terraform Aws Couchbase
Reusable infrastructure modules for running Couchbase on AWS
Stars: ✭ 73 (-7.59%)
Mutual labels:  aws, terraform
Module Security Public
The public documentation for the gruntwork-io/module-security repo, which contains packages for setting up best practices for managing secrets, credentials, and servers
Stars: ✭ 67 (-15.19%)
Mutual labels:  aws, terraform
Terraform Aws Vpc Peering
Terraform module to create a peering connection between two VPCs in the same AWS account.
Stars: ✭ 70 (-11.39%)
Mutual labels:  aws, terraform
Curso Aws Com Terraform
🎦 🇧🇷 Arquivos do curso "DevOps: AWS com Terraform Automatizando sua infraestrutura" publicado na Udemy. Você pode me ajudar comprando o curso utilizando o link abaixo.
Stars: ✭ 62 (-21.52%)
Mutual labels:  aws, terraform
Gitops Terraform Jenkins
GitOps Workflow with Jenkins and Terraform
Stars: ✭ 73 (-7.59%)
Mutual labels:  aws, terraform
Tf Jitsi
5-minute self-hosted Jitsi on AWS
Stars: ✭ 73 (-7.59%)
Mutual labels:  aws, terraform
Terraform Security Scan
Run a security scan on your terraform with the very nice https://github.com/liamg/tfsec
Stars: ✭ 64 (-18.99%)
Mutual labels:  aws, terraform
Tf aws elasticsearch
Terraform module which creates AWS Elasticsearch resources
Stars: ✭ 73 (-7.59%)
Mutual labels:  aws, terraform
Binaryalert
BinaryAlert: Serverless, Real-time & Retroactive Malware Detection.
Stars: ✭ 1,125 (+1324.05%)
Mutual labels:  aws, terraform
Awsconsolerecorder
Records actions made in the AWS Management Console and outputs the equivalent CLI/SDK commands and CloudFormation/Terraform templates.
Stars: ✭ 1,152 (+1358.23%)
Mutual labels:  aws, terraform
Terraform Modules
Reusable Terraform modules
Stars: ✭ 63 (-20.25%)
Mutual labels:  aws, terraform
Terraform Infra As Code Coverage Badges
Terraform / infrastructure-as-code coverage badges - how much of your AWS infrastructure is managed by Terraform?
Stars: ✭ 69 (-12.66%)
Mutual labels:  aws, terraform
Terraform Aws Waf Owasp Top 10 Rules
A Terraform module to create AWF WAF Rules for OWASP Top 10 security risks protection.
Stars: ✭ 62 (-21.52%)
Mutual labels:  aws, terraform
Ha Sap Terraform Deployments
Automated SAP/HA Deployments in Public/Private Clouds
Stars: ✭ 61 (-22.78%)
Mutual labels:  aws, terraform
Terraform Aws Wireguard
Terraform module to deploy WireGuard on AWS
Stars: ✭ 72 (-8.86%)
Mutual labels:  aws, terraform
Terraform Aws Elasticache Redis
Terraform module to provision an ElastiCache Redis Cluster
Stars: ✭ 73 (-7.59%)
Mutual labels:  aws, terraform

terraform-ebs-attachmentizer

Convert ebs_block_device blocks in aws_instance resource to aws_ebs_volume and aws_volume_attachment resources.

(I'm bad at names.)

Usage

terraform-ebs-attachmentizer INSTANCE REGION STATEFILE
  • INSTANCE is the value of the Name tag in EC2 for the instance to act on. It may be a pattern like something-*, in which case all matching instances will be modified.
  • REGION is the AWS availability zone your infrastructure exists in, e.g., us-east-1.
  • STATEFILE is the path of a terraform.tfstate file.

Why

Terraform lets you represent the EBS volumes attached to an instance in two ways. The first is as ebs_block_device blocks directly in the instance resource:

resource "aws_instance" "my_instance" {
    ...
    ebs_block_device {
        size = 100
        type = "gp2"
        device_name = "/dev/xvdb"
    }

    ebs_block_device {
        size = 500
        type = "gp2"
        device_name = "/dev/xvdc"
    }
    ...
}

The second is as aws_ebs_volume resources, with an aws_volume_attachment each to attach them to an instance:

resource "aws_instance" "my_instance" {
    ...
}

resource "aws_ebs_volume" "vol1" {
    size = 100
    type = "gp2"
    availability_zone = "${aws_instance.my_instance.availability_zone}"
}

resource "aws_ebs_volume" "vol2" {
    size = 500
    type = "gp2"
    availability_zone = "${aws_instance.my_instance.availability_zone}"
}

resource "aws_volume_attachment" "vol1" {
    instance_id = "${aws_instance.my_instance.id}"
    volume_id = "${aws_ebs_volume.vol1.id}"
    device_name = "/dev/xvdb"
}

resource "aws_volume_attachment" "vol2" {
    instance_id = "${aws_instance.my_instance.id}"
    volume_id = "${aws_ebs_volume.vol2.id}"
    device_name = "/dev/xvdc"
}

The first is obviously less verbose, but has the drawback of making it impossible to add or remove EBS volumes via Terraform. With the second, it's easy: just delete the aws_volume_attachment resource.

How

The tl;dr is:

  1. gather volume and instance data from AWS
  2. read the Terraform state file
  3. remove the ebs_block_device blocks from the state file, and add the new resources

Ideally we could do this without access to AWS, but the Terraform state doesn't include the volume IDs when you use ebs_block_device blocks. So read-only access to EC2 is required.

Development

The files have some doc comments explaining what's in each, but the high level view is

  • terraform.go handles reading of Terraform state
  • ec2.go handles reading from the AWS API
  • common.go has some common things like a utilty for dealing with the fact that either Terraform or AWS lets you call a device either /dev/xvdb or xvdb and "does the right thing".

This project uses Terraform as a library, and uses the official AWS Go SDK. The godoc for these will be handy:

It's also really instructive to look at some tfstate files and compare to the corresponding Terraform config.

Building

You'll need to place this in the right place in your GOPATH. After that, it should build with

go build -i

Running tests

Run

go test

Dependencies

Using dep despite its non-production status because it's the first one I tried that I could make work.

To add a dependency:

dep ensure [email protected]
Note that the project description data, including the texts, logos, images, and/or trademarks, for each open source project belongs to its rightful owner. If you wish to add or remove any projects, please contact us at [email protected].