Skip to content

Instantly share code, notes, and snippets.

View apparentlymart's full-sized avatar
⌨️
I may be slow to respond.

Martin Atkins apparentlymart

⌨️
I may be slow to respond.
View GitHub Profile
@apparentlymart
apparentlymart / Terraform-State-Ideas.md
Last active December 24, 2022 17:10
Terraform State Integrity Issues

Issues with Terraform State Management

The idea of "state" is the lynchpin of Terraform, and yet Terraform's workflow is fraught with gotchas that can lead to the loss or destruction of state. This doc is a set of notes about issues I've encountered, what caused them, and in many cases ideas about how to improve Terraform to avoid or reduce the chances of them.

Each of these scenarios has occured at least within my team. Each time one of these occurs it erodes people's confidence in Terraform, giving it a reputation for being fragile and unforgiving of errors. This this document is not written just to criticize but rather to identify ways in which the situation could be improved.

@apparentlymart
apparentlymart / index.html
Created May 15, 2016 19:48
Golang and Terminal.js web terminal
<html>
<head>
<script src="/terminal.js/dist/terminal.js"></script>
<style>
#terminal {
background: #000000;
color: #ffffff;
display: inline-block;
padding: 10px;
}
@apparentlymart
apparentlymart / NOTES.md
Last active July 26, 2016 16:57
AWS Describe/Get actions as Terraform Data Sources

AWS Describe and Get actions as Terraform Data Sources

Beyond the read-only resources that existed in Terraform before data resources were an official feature, I'd like to make room for a new pattern for re-usable modules where they accept only the minimum set of ids they need as variables and look up other data via data sources.

Here's a motivating example:

variable "aws_subnet_id" {
    description = "Id of the subnet where the EC2 instance will be created"
}
@apparentlymart
apparentlymart / .padstone.hcl
Last active May 23, 2016 03:38
Padstone v2: Multiple targets, like a Makefile
# Variables are set on the command line:
# padstone build version=v0.0.1 ami
variable "version" {
default = "dev"
}
provider "aws" {
region = "us-west-2"
}
@apparentlymart
apparentlymart / extract-certs.py
Created September 12, 2016 00:48
Python script to extract generated TLS certificates and keys from a Terraform state
import errno
import json
import os
import os.path
tf_state_path = os.path.join(os.path.dirname(__file__), "..", "terraform.tfstate")
tf_state_file = open(tf_state_path, 'rb')
tf_state = json.load(tf_state_file)
tf_state_file.close()
@apparentlymart
apparentlymart / keybase.md
Created September 21, 2016 23:40
Keybase Claim

Keybase proof

I hereby claim:

  • I am apparentlymart on github.
  • I am apparentlymart (https://keybase.io/apparentlymart) on keybase.
  • I have a public key whose fingerprint is BBE3 1AF5 8D12 1501 A495 FE10 6D98 B19B CF7A CB7A

To claim this, I am signing this object:

@apparentlymart
apparentlymart / diverge.js
Last active October 19, 2016 04:33
Highland Diverge Stream, pull edition
var _ = require('highland');
var items = [
'a',
'b',
'c',
'd',
'e',
'f',
@apparentlymart
apparentlymart / go-here.sh
Created April 1, 2017 15:46
Helper bash script for creating and activating GOPATHs
# Note: this is written for and tested only in bash
function _go-here {
DIR="$1"
export GOPATH="$DIR"
export PATH="$GOPATH/bin":$PATH
echo Activating GOPATH="$GOPATH"
}
function go-here {
@apparentlymart
apparentlymart / terraform-pr-migrate.go
Created June 14, 2017 19:16
Terraform Provider PR migration helper
//
// This is a helper program to do some of the more tedious steps of migrating
// Terraform provider commits from an older PR in the main Terraform repo to
// a new PR in the new provider repo.
//
// Specifically it:
// - Retrieves the PR commits from the Terraform repo
// - Computes the diff for each commit that the PR introduced
// - Does basic rewriting of paths in the diff for conventions in the new repos
// - Tries to apply the rewritten diff, creating new commits in the current repo
@apparentlymart
apparentlymart / generic_set.go
Created July 27, 2019 17:11
A prototype Set implementation using the second round of Go Generics proposal with contracts
// Package set is an adaptation of an existing Set implementation I wrote (that
// originally used interface{} as its underlying type) to the current Go 2
// Generics proposal at the time of this writing:
// https://go.googlesource.com/proposal/+/4a54a00950b56dd0096482d0edae46969d7432a6/design/go2draft-contracts.md
//
// This adaptation retains the existing feature that a set can be of any type,
// without that type needing to be extended with any additional methods, as long
// as the caller can provide a separate Rules type that provides the necessary
// additional operations. Generics allows the compiler to check the requirement
// that only sets with the same rules can be used together, which was previously