Open nitrocode opened 3 years ago
Sounds good. It's a missing feature.
Seems like this has been implemented by a separate tool
This would save us from having to ripgrep through the code
For anyone else around here that wants maximum automation, I made a little script:
set -euo pipefail
arg=${1:-}
if [ "$arg" = "modules" ]; then
# grep the module source, extract the unquoted name, sort and uniq
modules="$(rg --no-heading "^ source *= \"[^.]" | awk -F '"| *' '{print $5}' | sort | uniq)"
for m in $modules; do
# some modules are submodules of other modules
root_module="$(echo "$m" | awk -F'//' '{print $1}')"
latest_version=$(curl "https://registry.terraform.io/v2/modules/$root_module?include=latest-version" | jq -r '.included[0].attributes.tag')
latest_version=${latest_version#v}
tfupdate module "$m" . -r -v "~> $latest_version"
done
elif [ "$arg" = "providers" ]; then
providers="$(rg --no-heading "^ source *= \"[^.]" | awk -F '"| *' '{print $5}' | sort | uniq)"
for p in $providers; do
latest_version=$(curl "https://registry.terraform.io/v2/providers/$p?include=latest-version" | jq -r '.included[0].attributes.tag')
latest_version=${latest_version#v}
tfupdate provider "$p" . -r -v "~> $latest_version"
done
else
echo "$0: automation script around tfupdate (https://github.com/minamijoyo/tfupdate)"
echo ""
echo "Usage: $0 [modules|providers]"
echo " modules: update all modules to latest version"
echo " providers: update all providers to latest version"
exit 1
fi
Note that my ripgrep search strings (to differentiate modules from providers) are based on indentation (I use 2 spaces indentation).
It would be nice to list all the modules/providers in the current directory
This would save us from having to ripgrep through the code to see which modules are used in order to see which modules can be updated.
Perhaps something like this