Skip to content

Pulumi stack autocompletion

Pulumi is one of the best Infrastructure as Code (IaC) tools available. It allows you to manage your infrastructure using general-purpose programming languages, such as Python or Go.

Using autocomplete can save you a lot of time because you don’t have to type the entire command manually. By default, you can generate autocomplete functionality for Pulumi with the following command:

pulumi gen-completion bash

While this command works well, it does not autocomplete stack names. For instance, if your project/stack structure looks like this:

-rw-r--r-- 1 user staff 58 14 Oct 2023 Pulumi.prod.yaml
-rw-r--r-- 1 user staff 58 14 Oct 2023 Pulumi.staging.yaml
-rw-r--r-- 1 user staff 58 14 Oct 2023 Pulumi.development.yaml
-rw-r--r-- 1 user staff 65 14 Oct 2023 Pulumi.yaml
-rw-r--r-- 1 user staff 4119 14 Oct 2023 go.mod
-rw-r--r-- 1 user staff 29527 14 Oct 2023 go.sum
-rw-r--r-- 1 user staff 2039 14 Oct 2023 main.go

When you run Pulumi with an explicitly defined stack name using the -s STACK_NAME option, you must manually enter the stack name. However, you can easily add autocompletion for stack names by adding the following code to your shell profile:

~/.bash_profile
__my_init_completion()
{
COMPREPLY=()
_get_comp_words_by_ref "$@" cur prev words cword
}
_pulumi_custom_stack_completion() {
local cur prev words cword
if declare -F _init_completion >/dev/null 2>&1; then
_init_completion -s || return
else
__my_init_completion -n "=" || return
fi
if [[ ${prev} == "-s" || ${prev} == "--stack" ]]; then
COMPREPLY=( $(compgen -W "$(ls Pulumi.*.yaml 2>/dev/null | sed -E 's/Pulumi\.(.*)\.yaml/\1/')" -- "$cur") )
# If there's only one completion, remove the 'nospace' option
if [[ ${#COMPREPLY[@]} -eq 1 ]]; then
compopt +o nospace 2>/dev/null
fi
else
__start_pulumi
fi
}
complete -o default -F _pulumi_custom_stack_completion pulumi

After updating your profile, the shell will suggest the correct stack name after you type -s, rather than offering a file name.

Last updated:

© 2025 Aleksandr Aksenov. All Rights Reserved.