Created
December 7, 2022 13:21
-
-
Save alces/a460b00302c918e5ad90d2c4690997a1 to your computer and use it in GitHub Desktop.
Install a Terraform provider to a cache (tested on alpine Docker image)
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/sh -e | |
# Install a Terraform provider | |
OS=linux | |
ARCH=amd64 | |
OPTS=`getopt -l dont-unzip,full-url:,group:,provider:,site:,url:,version: -- df:g:p:u:s:v: "$@"` || exit 1 | |
eval set -- "$OPTS" | |
while true; do | |
case "$1" in | |
-d|--dont-unzip) unzip=no; shift;; | |
-f|--full-url) full_url=$2; shift 2;; | |
-g|--group) group=$2; shift 2;; | |
-p|--provider) provider=$2; shift 2;; | |
-u|--url) url=$2; shift 2;; | |
-s|--site) site=$2; shift 2;; | |
-v|--version) version=$2; shift 2;; | |
--) shift; break;; | |
*) echo "Unknown option: $1"; exit 2;; | |
esac | |
done | |
if [ "$provider" = "" ]; then | |
echo "--provider is required" | |
exit 2 | |
fi | |
if [ "$version" = "" ]; then | |
echo "--version is required" | |
exit 2 | |
fi | |
provider_full="terraform-provider-${provider}" | |
if [ "$unzip" = "no" ]; then | |
file="${provider_full}_${version}" | |
else | |
file="${provider_full}_${version}_${OS}_${ARCH}.zip" | |
fi | |
[ "$group" = "" ] && group=hashicorp | |
[ "$site" = "" ] && site=registry.terraform.io | |
[ "$unzip" = "" ] && unzip=yes | |
[ "$url" = "" ] && url="https://releases.hashicorp.com/${provider_full}/${version}" | |
[ "$full_url" = "" ] && full_url="${url}/${file}" | |
cache_dir="/cache/${site}/${group}/${provider}/${version}/${OS}_${ARCH}" | |
file_full="${cache_dir}/${file}" | |
echo "**** Install terraform provider $provider v${version} to cache ****" | |
mkdir -p "$cache_dir" | |
if [ "$unzip" = "yes" ]; then | |
wget -qO- "$full_url" | bsdtar -xvf- -C "$cache_dir" | |
else | |
wget "$full_url" -O "$file_full" | |
chmod +x "$file_full" | |
fi |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment