Skip to content

Instantly share code, notes, and snippets.


Dirk Avery YakDriver

View GitHub Profile
YakDriver /
Created Feb 14, 2018
Bash Basics: A Robust try/catch/finally for shell scripts
# This script uses traps to create try/catch/finally functionality in shell scripts.
# Hello! We're reporting live from script
# ./ line 23: badcommand: command not found
# ./ line 23: exiting with status 127
# It's the end of the line
YakDriver /
Created Feb 22, 2018
Manage security groups (shell script) from AWS CLI
# Errors are thrown if Terraform is given the name of an existing security group.
# One solution is to find the existing security group and delete it. (That will fail if any instances are associated.)
# This installs jq, finds security group id, deletes security group.
# 1. Install jq
curl -L "" -o jq.dms && chmod +x jq.dms
YakDriver /
Last active Feb 22, 2018
Generate keys
echo "Usage: $0 [organization] [name]"
create_date=$(date +'%Y%m%d')
if [ -n "${org}" ] ; then org="$org " ; fi
YakDriver /
Created Feb 22, 2018
Extract node portion of UUID, bash
$uuid = 'some-name-or-urn:8754258d-506d-e094-d51d-e0a0d891fe08' #16 octets, 10-15 are the node
$node = $(echo $uuid | cut -d':' -f 2 | cut -d'-' -f 5)
echo $node
YakDriver /
Last active Mar 1, 2018
Linux/bash to display date in UTC format
# Many things want UTC time as input, so here it is. As 14 days ago. Like for a query to AWS spot instance history:
# aws ec2 describe-spot-price-history --instance-types t2.micro --start-time $(date -v-14d -u '+%FT%TZ') --product-description "Linux/UNIX"
# Output (of command below, not the aws cli command):
# 2018-02-13T15:24:46Z
date -v-14d -u '+%FT%TZ'
YakDriver /
Created Mar 1, 2018
Set the name tag of an AWS instance from the AWS instance (e.g., in userdata)
# terraform locals (in a .tf file)
locals {
name_prefix = "terrafirm"
full_build_id = format("notcb:%s", uuid()) #128-bit rfc 4122 v4 UUID
build_id = "${substr(element(split(":",local.full_build_id),1), 0, 8)}${substr(element(split(":",local.full_build_id),1), 9, 4)}"
resource_name = "${local.name_prefix}-${local.build_id}"
# terraform template declaration (in a .tf file)
data "template_file" "lx_userdata" {
YakDriver / building.misc
Created Mar 2, 2018
adventures in RPM builds
View building.misc
pip install --index-url="" --upgrade virtualenv
sudo yum groupinstall -y development
sudo yum install -y zlib-dev openssl-devel sqlite-devel bzip2-devel
sudo yum install xz-libs
xz -d Python-2.7.14.tar.xz
tar -xvf Python-2.7.14.tar
YakDriver / running-terraform-providers-acceptance-test.txt
Last active Mar 7, 2018
Running acceptance tests for Terraform Providers in go
View running-terraform-providers-acceptance-test.txt
# Hashicorp documentation is a bit out of date so it took a minute to figure this out...
# 1. Install go
# 2. Make a go workspace
$ mkdir ~/go # or wherever you want
$ export GOPATH=~/go # could add to .bash_profile
YakDriver / userdata.ps1
Created Mar 16, 2018
Userdata PowerShell to set Admin Password
View userdata.ps1
$Admin = [adsi]("WinNT://./Administrator, user")
$Admin.psbase.invoke("SetPassword", "<password>")
View terraform_debug.log
2018-03-22T15:09:41.743Z [DEBUG] plugin.terraform: file-provisioner (internal) 2018/03/22 15:09:41 Uploading file to 'C:\scripts\check_build.ps1'
2018-03-22T15:09:42.378Z [DEBUG] plugin.terraform: remote-exec-provisioner (internal) 2018/03/22 15:09:42 connecting to remote shell using WinRM
2018-03-22T15:09:42.408Z [DEBUG] plugin.terraform: remote-exec-provisioner (internal) 2018/03/22 15:09:42 Uploading file to 'C:/Temp/terraform_1217694552.cmd'
2018-03-22T15:09:43.054Z [DEBUG] plugin.terraform: remote-exec-provisioner (internal) 2018/03/22 15:09:43 starting remote command: C:/Temp/terraform_1217694552.cmd
2018-03-22T15:10:52.390Z [DEBUG] plugin.terraform: remote-exec-provisioner (internal) 2018/03/22 15:10:52 Uploading file to 'C:/Temp/terraform_1217694552.cmd'
2018/03/22 15:10:53 [DEBUG] plugin: waiting for all plugin processes to complete...
2018-03-22T15:10:53.201Z [DEBUG] plugin.terraform: remote-exec-provisioner (internal) 2018/03/22 15:10:53 [ERR] plugin: plugin server: accept unix /tmp/plugin522209802