fabrica/fabrica

102 lines
1.5 KiB
Bash
Executable File

#!/bin/bash
WORKDIR="./terraform"
TERRA="terraform"
VAR_FILE="main.tfvars"
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
${TERRA} ${1} -var-file ${VAR_FILE}
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 ${?}