Skip to content

Using {{.USER_WORKING_DIR}} causes failure "no such file or directory" #1293

@gberenice

Description

@gberenice

Hey!
We're working on reusable tasks to be able to run the same tasks from different Terraform configuration directories.

The content of my root Taskfile is:

version: "3"

includes:
  terraform:
    taskfile: ./taskfiles/terraform
    aliases: [tf]

My terraform taskfile looks like:

  init:
    silent: true
    # dir: "{{.USER_WORKING_DIR}}"
    vars:
      ENV:
        sh: echo "{{.CLI_ARGS}}" | cut -d ' ' -f1 | xargs
      TF_ARGS:
        sh: echo "{{.CLI_ARGS}}" | cut -s -d ' ' -f2- | xargs
      BACKEND_CONFIG_FILE:
        sh: echo "./backend-configurations/{{.ENV}}.backend.tf"
    preconditions:
      - sh: test -f {{.BACKEND_CONFIG_FILE}}
        msg: "Backend configuration file does not exist: {{.BACKEND_CONFIG_FILE}}"
    cmds:
      - terraform init -backend-config {{.BACKEND_CONFIG_FILE}} {{.TF_ARGS}}

When uncommenting and enabling dir: "{{.USER_WORKING_DIR}}", task run fails with a weird error:

task: Command "echo "automation" | cut -d ' ' -f1 | xargs" failed: chdir /Users/gberenice/work/mp/infra/Users/gberenice/work/mp/infra/components/network: no such file or directory

I run this task from /Users/gberenice/work/mp/infra/components/network, while /Users/gberenice/work/mp/infra/ is a directory where my root Taskfile.yaml is located.

If I set dir equal to a specific directory, everything works as expected. Please advise.

  • Task version: 3.28.0
  • Operating system: macOS 13.4
  • Experiments enabled: no

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No fields configured for bug.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions