Commit 43d91425 authored by Pierre Smeyers's avatar Pierre Smeyers
Browse files

feat: add var-file option on terraform init

add support of tfvars files on init needed for example with OpenTofu [provider for_each](https://opentofu.org/docs/language/meta-arguments/module-providers/#module-instances-with-differing-provider-instances) syntax
parent 9f7f40c6
Loading
Loading
Loading
Loading
+10 −1
Original line number Diff line number Diff line
@@ -851,8 +851,17 @@ stages:
      fi
    fi

    # implicit tfvars
    env_vars=$(ls -1 "${environment_type}.env.tfvars" 2>/dev/null || ls -1 "${environment_type}.env.tfvars.json" 2>/dev/null || echo "")
    if [[ -f "$env_vars" ]]
    then
      log_info "--- environment-specific tfvars file (\\e[33;1m${env_vars}\\e[0m) found: use"
    else
      log_info "--- no environment-specific tfvars file found: ignore"
    fi

    # shellcheck disable=SC2154,SC2086,SC2046
    terraform init $tf_backend_opts $(echo "$extra_opts" | envsubst_cli) $(echo "$opts" | envsubst_cli)
    terraform init $tf_backend_opts ${env_vars:+-var-file=${env_vars}} $(echo "$extra_opts" | envsubst_cli) $(echo "$opts" | envsubst_cli)
  }

  function tf_workspace_select() {