Skip to content

Overriding A Task Variable From Within A Task #731

Discussion options

You must be logged in to vote

Vars cannot be updated per se, they can only be overwritten. Unfortunately, the way vars currently work is that you don't actually get access to the value as it is declared in a higher scope, if you declare a var in a child scope with the same name.

The recommended approach is to declare a new var (different name) and then reference the global var.

Here's an example:

vars:
  PARAMETER_NAME: "/{{.SYSTEM_NAME}}/${TERRAFORM_VARIABLE}"

tasks:
   example:
      vars:
        DERIVED_PARAMETER: |
           {{if (eq .TERRAFORM_VARIABLE "")}}{{.OTHER_PARAMETER_NAME}}{{else}}{{.PARAMETER_NAME}}{{end}}
      cmds:
      - echo '{{.DERIVED_PARAMETER}}'

Replies: 1 comment 4 replies

Comment options

You must be logged in to vote
4 replies
@prodigy-byron-jones
Comment options

@ghostsquad
Comment options

@ghostsquad
Comment options

@prodigy-byron-jones
Comment options

Answer selected by prodigy-byron-jones
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Q&A
Labels
None yet
2 participants