When you run terraform init
terraform will download required providers from its server,
unless you have cached providers in your directory.
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 |