Skip to content

Instantly share code, notes, and snippets.

@abihf
Created April 6, 2018 12:04
Show Gist options
  • Save abihf/b8c628e89445a82a0e6e8a696d124281 to your computer and use it in GitHub Desktop.
Save abihf/b8c628e89445a82a0e6e8a696d124281 to your computer and use it in GitHub Desktop.
Terraform Provider Update

Why?

When you run terraform init terraform will download required providers from its server, unless you have cached providers in your directory.

How

create folder .terraform.d/plugins in your home directory, then create file update-providers.sh

#!/bin/sh
# place this script in ~/.terraform.d/plugins/update-providers.sh
# List of providers that want to be updated
providers=(
"archive"
"aws"
"local"
"random"
"template"
)
base_url="https://releases.hashicorp.com"
for name in "${providers[@]}"; do
provider_url="${base_url}/terraform-provider-${name}"
echo -n "Updating terraform-provider-${name}... "
version=$(curl -s "${provider_url}/" | grep "href=\"/terraform-provider-${name}/" | head -1 | sed -E 's#^.*([0-9]+\.[0-9]+\.[0-9]+).*$#\1#')
plugin_file="terraform-provider-${name}_v${version}_x4"
if [ ! -f "${plugin_file}" ]; then
zip_file="terraform-provider-${name}_${version}_linux_amd64.zip"
download_url="${provider_url}/${version}/terraform-provider-${name}_${version}_linux_amd64.zip"
echo -n "Downloading ${zip_file}... "
curl -sL -o "${zip_file}" "${download_url}"
unzip "${zip_file}" > /dev/null
rm "${zip_file}"
echo "Done."
else
echo "Up to date."
fi
done
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment