Skip to content

Instantly share code, notes, and snippets.

View jamtur01's full-sized avatar
💭
I may be slow to respond.

James Turnbull jamtur01

💭
I may be slow to respond.
View GitHub Profile

S3 Bucket

Terraform can also store modules in an S3 bucket. To access the bucket you must have appropriate AWS credentials in your configuration or available via shared credentials or environment variables.

There are a variety of S3 bucket addressing schemes, most are documented in the S3 configuration. Here are a couple of examples:

@jamtur01
jamtur01 / pre-commit
Created October 18, 2016 21:54
A Terraform validation and formatting pre-commit hook
#!/usr/bin/env bash
set -e
# Formats any *.tf files according to the hashicorp convention
files=$(git diff --cached --name-only)
for f in $files
do
if [ -e "$f" ] && [[ $f == *.tf ]]; then
#terraform validate `dirname $f`
terraform fmt $f
env TF_LOG=DEBUG terraform get -update
2016/10/15 05:59:20 [INFO] Terraform version: 0.7.6 754bdda8a78b24efab62f1dc24d97c1c02d89fe9
2016/10/15 05:59:20 [INFO] CLI args: []string{"/usr/local/bin/terraform", "get", "-update"}
2016/10/15 05:59:20 [DEBUG] Detected home directory from env var: /Users/james
2016/10/15 05:59:20 [DEBUG] Detected home directory from env var: /Users/james
2016/10/15 05:59:20 [DEBUG] Attempting to open CLI config file: /Users/james/.terraformrc
2016/10/15 05:59:20 [DEBUG] File doesn't exist, but doesn't need to. Ignoring.
2016/10/15 05:59:20 [DEBUG] Detected home directory from env var: /Users/james
Get: git::https://github.com/turnbullpublishing/tf_api.git (update)
Get: git::ssh://[email protected]/turnbullpublishing/tf_vpc.git?ref=v0.0.2 (update)
2016/09/30 14:45:10 [INFO] Terraform version: 0.7.4 84592f5967490d118aae0b61a25d589d269fd0b6
2016/09/30 14:45:10 [INFO] CLI args: []string{"/usr/local/bin/terraform", "plan"}
2016/09/30 14:45:10 [DEBUG] Detected home directory from env var: /Users/james
2016/09/30 14:45:10 [DEBUG] Detected home directory from env var: /Users/james
2016/09/30 14:45:10 [DEBUG] Attempting to open CLI config file: /Users/james/.terraformrc
2016/09/30 14:45:10 [DEBUG] File doesn't exist, but doesn't need to. Ignoring.
2016/09/30 14:45:10 [DEBUG] Detected home directory from env var: /Users/james
2016/09/30 14:45:10 [DEBUG] DestroyEdgeInclude: Checking: aws_instance.base
2016/09/30 14:45:10 [DEBUG] DestroyEdgeInclude: Checking: aws_instance.base
2016/09/30 14:45:10 [TRACE] Graph after step *terraform.DestroyTransformer:
  1. Do a commit bumping the version from x.y.z-SNAPSHOT to x.y.z
  2. lein deploy clojars or mvn deploy
  3. git tag x.y.z
  4. git push --tags
  5. Another commit for x.y.whatever-SNAPSHOT.
@jamtur01
jamtur01 / check_ratio.clj
Created April 12, 2016 13:10
Check Ratio stream
(defn check_ratio [srv1 srv2 newsrv warning critical & children]
(project [(service srv1)
(service srv2)]
(smap folds/quotient
(fn [event] (let [percenta (* (float (:metric event)) 100)
new-event (assoc event :metric percenta
:service (str newsrv)
:type_instance nil
:state (condp < percenta
critical "critical"
@jamtur01
jamtur01 / minipages.hs
Created March 23, 2016 15:51
Minipages filter for Pandoc
import Text.Pandoc
import Text.Pandoc.JSON
main = toJSONFilter addMinipages'
addMinipages' :: Pandoc -> Pandoc
addMinipages' = bottomUp addMinipages
addMinipages :: [Block] -> [Block]
addMinipages (CodeBlock attr code : xs)
defn foo [] ....)
(def pusher (pushover "asdaasd" "asdasdas"))
(streams
(where (service "somecriticalservice")
(changed-state { :init "ok" }
pusher)))
(def hc (hipchat {:server "..."
:room 12345
:token "..."
:notify 0}))
(streams
(where (...)
hc))