0

I want to supply a template with a variable containing a list of strings. I would then like some way for the template to iterate the list of strings, and create a single string in the following format:

"-var-file=$(string1) -var-file=$(string2) -var-file=..."

How could this best be achieved?

Example code is below, I'd like the formatted string to be in where var_files is called within the bash task.

parameters:
  - name: plan_filename
    type: string
    default: plan.tfplan
  - name: var_files
    type: object
    default: 
      - config/file1.json
      - config/file2.json

steps:
  - bash: |
      terraform apply -input=false ${{ parameters.var_files }} -auto-approve ${{ parameters.plan_filename }}
    displayName: Apply Terraform changes
    env:
      ARM_CLIENT_ID: $(pipeline-sp-clientid)
      ARM_CLIENT_SECRET: $(pipeline-sp-secret)
      ARM_TENANT_ID: $(azure-tenant-id)
      ARM_SUBSCRIPTION_ID: $(azure-sub-id)

1 Answers1

0

This is easily achieved using the join expression function.

steps:
  - bash: |
      terraform apply -input=false -var-file=${{ join(' -var-file=', parameters.var_files) }} -auto-approve ${{ parameters.plan_filename }}