Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Support listing all modules/providers in the current directory #46

Open
nitrocode opened this issue Jul 5, 2021 · 3 comments
Open

Support listing all modules/providers in the current directory #46

nitrocode opened this issue Jul 5, 2021 · 3 comments

Comments

@nitrocode
Copy link

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

$ tfupdate release latest --current
module xyz 1.3.3
module abc 1.4.0
$ tfupdate release list --current
module xyz 1.3.1
module abc 1.2.1
@minamijoyo
Copy link
Owner

Sounds good. It's a missing feature.

@nitrocode
Copy link
Author

Seems like this has been implemented by a separate tool

https://github.com/keilerkonzept/terraform-module-versions

@awoimbee
Copy link

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).

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants