# shellcheck shell=bash
# vim: ft=sh

export TF_CLI=tofu
export TF_DEBUG=1
alias tfa='tf apply tfplan'
alias tfaa='tf apply -auto-approve'
alias tfar='tf apply tfplan && tf plan -out tfplan -refresh-only && tf apply tfplan'
alias tfp='tf init -backend=false && tf plan -out tfplan'
alias tfr='tf apply -auto-approve -refresh-only'
alias tfvf='tf init -backend=false && tf validate && tf fmt -diff'

tf-next () {
    current="$(tf workspace show)"
    next="$(tf workspace list | cut -c3- | grep --line-regexp --after-context=1 "$current" | tail +2)"
    if [ -z "${next}" ]
    then
        red "Last workspace."
        return 1
    fi
    tf workspace select "$next"
}
