Skip to content

Instantly share code, notes, and snippets.

@stavxyz
Last active August 14, 2019 17:59
Show Gist options
  • Save stavxyz/ae997ea5cfe55882e55ce96cc9fa01a6 to your computer and use it in GitHub Desktop.
Save stavxyz/ae997ea5cfe55882e55ce96cc9fa01a6 to your computer and use it in GitHub Desktop.
build terraform plugins
#!/usr/bin/env bash
# Undefined variables are errors.
set -euo pipefail
errcho ()
{
echo "$@" 1>&2
}
errxit ()
{
errcho "$@"
exit 1
}
REPOSITORY="${1:-}"
if [[ -z ${REPOSITORY} ]]; then
errxit "Full plugin name required e.g. 'github.com/phillbaker/terraform-provider-mailgunv3'"
fi
function get_latest_version {
git fetch --tags --update-head-ok --progress https://${REPOSITORY}
VERSIONS=($(git tag --list --format='%(refname:lstrip=2)' | grep -e '^v.*[0-9]$' | sort -r))
>&2 echo "Available Versions: ${VERSIONS[*]} (selecting latest)"
echo "${VERSIONS[0]}"
}
VERSION="${2:-`get_latest_version`}"
PLUGIN="$(basename ${REPOSITORY})"
PLUGIN_SHORTNAME="${PLUGIN##*-}"
echo "Building ${PLUGIN} version ${VERSION}"
git checkout ${VERSION} --force
go build -o "${HOME}/.terraform.d/plugins/${PLUGIN}_${VERSION}"
echo "Installing ${PLUGIN} version ${VERSION}"
echo "Terraform provider ${PLUGIN_SHORTNAME} version ${VERSION} has been installed to ~/.terraform.d/"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment