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

Unable to pass in CLI variable override unless default is set for variable #136

Open
ntwkninja opened this issue Sep 6, 2024 · 4 comments
Labels
possible-bug 🐛 Something may not be working

Comments

@ntwkninja
Copy link
Member

ntwkninja commented Sep 6, 2024

Given the following task.yaml referenced elsewhere with an includes: ./path/to/local/file, the subsequent issue is encountered.

  - name: plan-tofu
    inputs:
      env:
        description: "Environment to apply to"
        required: true
        type: string
        # default: "please-set-your-env-variable"
    actions:
      - cmd: |
          tofu init -backend-config="./config/${ENV}/backend.tfconfig"
          tofu plan       -var-file="./config/${ENV}/vars.tfvars"
        description: "Initialize & Plan Terraform for Environment"
        mute: false

uds run local:plan-tofu --set=ENV=blah

     ERROR:  Failed to run action: task local:plan-tofu is missing required inputs: env

If I uncomment the default and run the same command, I am able to override it with the CLI flag

     Initializing the backend...                                                                                                                                   
     Initializing modules...    
@ntwkninja ntwkninja added the possible-bug 🐛 Something may not be working label Sep 6, 2024
@ericwyles
Copy link
Contributor

@zachariahmiller I think this is similar to / in the same part of the code as the issue where you can't call tasks with inputs from the cli at all (unless they are wrapped in another task). Wondering if your pr #135 might actually fix this too?

@zachariahmiller
Copy link
Contributor

zachariahmiller commented Sep 6, 2024

I have a wip pr to enable calling tasks with inputs directly in addition to the work to allow conditionals, however I don't think that will resolve this issue as inputs and set vars are still distinctly different.

However, I think in the example if the default was ${ENV} then it would work once those changes are finished and merged in.

@Racer159
Copy link
Contributor

Racer159 commented Sep 19, 2024

@ntwkninja does this work?

variables:
  - name: ENV

tasks:
 - name: plan-tofu
    inputs:
      env:
        description: "Environment to apply to"
        required: true
        type: string
        default: "${ENV}"
    actions:
      - cmd: |
          tofu init -backend-config="./config/${{ .inputs.env }}/backend.tfconfig"
          tofu plan       -var-file="./config/${{ .inputs.env }}/vars.tfvars"
        description: "Initialize & Plan Terraform for Environment"
        mute: false

@ntwkninja
Copy link
Member Author

ntwkninja commented Sep 20, 2024

This is what I've been testing against. Regardless if there are variables in either file / no variables defined (in the variables top level key), as well as, if I use ${{ .inputs.env }} or ${ENV} in the cmd: everything seems to behave the same.

# ../tasks.yaml

# yaml-language-server: $schema=https://github.com/defenseunicorns/maru-runner/blob/main/tasks.schema.json

tasks:
  - name: plan-tofu
    inputs:
      env:
        description: "Environment to apply to"
        required: true
        type: string
        default: "${ENV}"
    actions:
      - cmd: |
          tofu init -backend-config="./config/${{ .inputs.env }}/backend.tfconfig"
          tofu plan       -var-file="./config/${{ .inputs.env }}/vars.tfvars"
        description: "Initialize & Plan Terraform for Environment"
        mute: false
#  tasks.yaml

# yaml-language-server: $schema=https://github.com/defenseunicorns/maru-runner/blob/main/tasks.schema.json

variables:
  - name: "ENV"

includes:
  - local: ../tasks.yaml

tasks:
  - name: plan-tofu
    actions:
      - task: local:plan-tofu

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
possible-bug 🐛 Something may not be working
Projects
None yet
Development

No branches or pull requests

4 participants