Skip to content

Instantly share code, notes, and snippets.

@vancluever
vancluever / terraform-switch-env.sh
Last active April 15, 2017 16:48
Switch env for TF v0.9.0 and higher (composite env w/region)
if ! env_list="$(terraform env list)"; then
exit 1
fi
if [[ "${env_list}" == *"${ENV}_${REGION}"* ]]; then
terraform env select "${ENV}_${REGION}"
else
terraform env new "${ENV}_${REGION}"
fi
@vancluever
vancluever / _remote_config.tf
Created April 15, 2017 16:29
New v0.9.0 remote config
terraform {
backend "s3" {
bucket = "tfstate.foobar.local"
key = "FE/web-frontend"
region = "your-buckets-region"
}
}
@vancluever
vancluever / old-env-config.tf
Created April 15, 2017 16:14
Using the old names module
variable "env" {
type = "string"
}
variable "region" {
type = "string"
}
module "names" {
source = "./names"
@vancluever
vancluever / old-names-module.tf
Created April 15, 2017 16:14
Naming module (old form)
variable "env" {
type = "string"
}
variable "region" {
type = "string"
}
variable "endpoint_name" {
type = "string"
@vancluever
vancluever / old-tf-run-env.sh
Created April 15, 2017 16:02
Invoking terraform with env and region params (old way)
TF_VAR_env=${ENV} TF_VAR_region=${REGION} \
terraform apply
@vancluever
vancluever / terraform-old-remote-config.sh
Last active April 15, 2017 16:01
A paraphrasing of Terraform's old remote config command
terraform remote config \
-backend=s3
-backend-config="bucket=tfstate.foobar.local" \
-backend-config="key=FE/app-frontend/${ENV}/${REGION}/terraform.tfstate"
@vancluever
vancluever / terraform-remote-config.sh
Last active May 31, 2017 02:52
Effectively emulating the old "terraform remote config" command (TF >= v0.9.0)
#!/usr/bin/env bash
# Say you have a S3 state with KMS on, with the appropriate variables
# configured below (these could also be parameterized but I wanted to
# make this gist as easy as possible to digest). Using this script
# (or a reasonable facsimile thereof), you can emulate the old
# "terraform remote config" command that existed in TF pre-v0.9
# by creating a file with your config in your Terraform directory.
# This file should be ignored in source control!
@vancluever
vancluever / wrap.go
Last active March 22, 2017 17:41
GoLang Kata WordWrap (Non-Unicode) - https://play.golang.org/p/zu9k0qjUzU
package main
import (
"bytes"
"fmt"
)
const in = "Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat. Duis aute irure dolor in reprehenderit in voluptate velit esse cillum dolore eu fugiat nulla pariatur. Excepteur sint occaecat cupidatat non proident, sunt in culpa qui officia deserunt mollit anim id est laborum."
func wrap(old string, ll int) string {
@vancluever
vancluever / rndpass.rb
Created February 21, 2017 21:58
Ruby random password generation - classic example
PW_RANGE = [*'0'..'9', *'A'..'Z', *'a'..'z'].freeze
password = Array.new(16) { PW_RANGE.sample }.join
puts password
@vancluever
vancluever / dectoipv4.js
Created February 17, 2017 19:25
IPv4 decimal to dotted quad conversion - https://jsfiddle.net/t7fu2fgy/ - works in Google Apps Script too
function decimalToIPv4(decIpAddr) {
ipBytes = [];
for (i=0;i<=3;i++) {
ipBytes.push((decIpAddr >> 8 * 3 - 8 * i) & 255);
}
return ipBytes.join(".");
}