#!/bin/bash WORKDIR="./terraform" TERRA="terraform" PACKER_ROOT="./packer" # FIXME function needGitPull() { br=$(git branch --show-current) diff=$(git rev-list HEAD...origin/master --count) return ${diff} } function trun() { #needGitPull cd ${WORKDIR} if [[ ${?} -ne 0 ]] then echo "Branch is not up 2 date !" echo "--> Git pull needed !" return 1 fi VAR_FILES=$(ls *.tfvars) OPTS="" for fl in ${VAR_FILES} do OPTS="${OPTS} -var-file ${fl}" done ${TERRA} ${1} ${OPTS} res=${?} cd - return ${res} } function plan() { trun plan return $? } function apply() { trun apply return $? } function destroy() { trun destroy return $? } function taint() { target=$1 resource=$2 cd ${WORKDIR} $TERRA taint module.${resource}.opennebula_template.vm_template $TERRA taint module.${resource}.opennebula_virtual_machine.vm $TERRA taint module.${resource}.opennebula_image.system cd - } function taint_all() { target=$1 resource=$2 cd ${WORKDIR} $TERRA taint module.${resource}.opennebula_template.vm_template $TERRA taint module.${resource}.opennebula_virtual_machine.vm $TERRA taint module.${resource}.opennebula_image.system $TERRA taint module.${resource}.opennebula_image.data cd - } function init() { trun init return ${?} } function build() { target=$2 cd ${PACKER_ROOT} echo "Building ${target}" make ${target} return ${?} } function publish() { target=$2 echo "FIXME for publish" } $1 $@ exit ${?}