Skip to content

Instantly share code, notes, and snippets.

@neurogenesis
neurogenesis / terraform-import-loop.md
Last active September 28, 2019 01:23
Terraform TDD Import Loop

Start with terraforming:

This has become my defacto choice for generating terraform resources from existing infrastructure.

A little more details on what this workflow might look like, assuming you're on Amazon (applies to others). It's more or less an iterative TDD process for terraform. I've even used "guard" with "terraform apply" on file changes to speed things up a bit.

Break your infrastructure into app services vs core / shared components. Shared components might be network scaffolding like VPCs and all of the related networking that (a) rarely ever changes and (b) is incredibly risky if it does (i.e. replacing a subnet might cause servers to be re-created).

@neurogenesis
neurogenesis / terraforming-import-all
Created September 27, 2019 22:28
generate terraform templates from existing infrastructure (via terraforming)
#!/usr/bin/env ruby
# USAGE:
# gem install terraforming
# export AWS_PROFILE=xxx
# mkdir -p ~/projects/terraform
# cd ~/projects/terraform
# mkdir -p imports/[account]/[region]
# cd imports/[account]/[region]
# ../../../bin/terraforming-import-all
#!/usr/bin/env bash
#
# TODO:
# - allow setting custom green/yellow threshold via CLI options
# - allow profile selection via CLI options
# - fix issue with command argument position (must follow hostname)
#
## set defauts