Skip to content

Instantly share code, notes, and snippets.

@itsamenathan
itsamenathan / supported_workspaces.tf
Created May 29, 2018 20:21
Terraform workspace checking
variable "supported_workspaces" {
default = ["dev", "beta", "prod"]
}
resource "null_resource" "is_workspace_supported" {
count = "${contains(var.supported_workspaces, terraform.workspace) ? 0 : 1}"
"\n\n!!!! ERROR !!!!\nYou are getting this error because you are trying to use an unsupported workspace. \nSupported workspaces are: [${join(", ", var.supported_workspaces)}]. You are currently using the \"${terraform.workspace}\" workspace. \nPlease see the README file for information on how to configure a workspace." = true
}
@itsamenathan
itsamenathan / get_tags.sh
Created April 7, 2017 20:03
Get docker image tags from Gitlab Registry
#/bin/bash
set -e
AUTH_URL="https://gitlab.com/jwt/auth"
SERVICE="container_registry"
SCOPE="repository:group_name/image_name:pull"
AUTH="some_passowrd"
TOKEN=$(curl -s -H "Authorization: Basic ${AUTH}" "${AUTH_URL}?service=${SERVICE}&scope=${SCOPE}" | jq '.token' -r )
#!/bin/bash
set -x
set -e
case "$1" in
start)
echo "start"
USER="$2"
IP="$3"
@itsamenathan
itsamenathan / poorman.ntp
Created December 16, 2014 14:40
poor mans ntp
date -s "$(curl -s --head http://google.com | awk '/^Date/ {$1=""; print $0}')"
@itsamenathan
itsamenathan / logging
Last active August 29, 2015 14:10
bash logging functions
# Colors
ESC_SEQ="\x1b["
COL_RESET=$ESC_SEQ"39;49;00m"
COL_RED=$ESC_SEQ"31;01m"
COL_GREEN=$ESC_SEQ"32;01m"
COL_YELLOW=$ESC_SEQ"33;01m"
COL_BLUE=$ESC_SEQ"34;01m"
COL_MAGENTA=$ESC_SEQ"35;01m"
COL_CYAN=$ESC_SEQ"36;01m"
@itsamenathan
itsamenathan / git_commit
Last active August 29, 2015 14:08
Change git commit time
#!/bin/bash
if [ -z "$1" ]; then
echo "Didn't pass in option for date -d"
exit 1
fi
newdate=$(date -d "$1")
export GIT_AUTHOR_DATE=$newdate
export GIT_COMMITTER_DATE=$newdate
git commit
@itsamenathan
itsamenathan / grep -q
Created May 27, 2014 00:52
if with grep -q
word=Linux
letter_sequence=inu
if echo "$word" | grep -q "$letter_sequence"
# The "-q" option to grep suppresses output.
then
echo "$letter_sequence found in $word"
else
echo "$letter_sequence not found in $word"
fi
@itsamenathan
itsamenathan / keybase.md
Last active August 29, 2015 14:00
keybase.md

Keybase proof

I hereby claim:

  • I am itsamenathan on github.
  • I am nathan (https://keybase.io/nathan) on keybase.
  • I have a public key whose fingerprint is B256 11F7 868D 408F 451D 21CA 882A C17B 7EA7 3818

To claim this, I am signing this object:

@itsamenathan
itsamenathan / if_command_exists.sh
Created January 3, 2014 21:53
Check if command exists
if hash foo 2>/dev/null; then
echo "foo"
else
echo "no foo"
fi