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

TF_VAR_ is already defined #252

Open
iondrugalea opened this issue Oct 22, 2024 · 1 comment
Open

TF_VAR_ is already defined #252

iondrugalea opened this issue Oct 22, 2024 · 1 comment

Comments

@iondrugalea
Copy link

I want to have multiple TF_VAR_<var.name> env Variables.
For this i've update my tf template

- task: TerraformTaskV4@4
  inputs:
    provider: 'azurerm'
    command: 'init'
    backendServiceArm: ${{ parameters.SERVICE_CONNECTION }}
    backendAzureRmResourceGroupName: ${{ parameters.TF_STATE_BLOB_ACCOUNT_RESOURCE_GROUP_NAME }}
    backendAzureRmStorageAccountName: ${{ parameters.TF_STATE_BLOB_ACCOUNT_NAME }}
    backendAzureRmContainerName: ${{ parameters.TF_STATE_BLOB_CONTAINER_NAME }}
    backendAzureRmKey: ${{ parameters.TF_STATE_BLOB_FILE }}
    workingDirectory: '${{ parameters.RELATIVE_WORKING_DIR }}'
    backendAzureRmUseEnvironmentVariablesForAuthentication: true
    backendAzureRmUseEntraIdForAuthentication: true
  displayName: 'Terraform Init'
    # ${{ each item in parameters.envVars }}:
    #   ${{ item.name }}: ${{ item.value }}
    # ${{ each item in parameters.tfVars }}:
    #   TF_VAR_${{ item.name }}: ${{ item.value }}

And this is how I call the template

  - template: terraform/tf-plan.yml@pipeline-templates
      parameters:
        SERVICE_CONNECTION: ${{ variables.service_connection }}
        TF_VERSION: $(TF_VERSION)
        TF_STATE_BLOB_ACCOUNT_NAME: $(tf_state_blob_account_name)
        TF_STATE_BLOB_CONTAINER_NAME: $(tf_state_blob_container_name)
        TF_STATE_BLOB_FILE: $(tf_state_blob_file)
        TF_STATE_BLOB_ACCOUNT_RESOURCE_GROUP_NAME: $(tf_state_blob_account_resource_group_name)
        RELATIVE_WORKING_DIR: $(tf_working_dir)
        tfVars:
            var1: $(va1)
            var2: $(var2)
        tfvarsFile: "../tf/vars/$(environment)/$(environment).tfvars"

and i got

(Line: 61, Col: 7): 'TF_VAR_' is already defined

Any assistance is appreciated
Thanks!

@mericstam
Copy link
Collaborator

Hi, this is not related to the Terraform extension. I would suggest you check MS Learn site for YAML syntax and how Azure Pipelines work.

more on templates: https://learn.microsoft.com/en-us/azure/devops/pipelines/process/templates?view=azure-devops&pivots=templates-includes

Br
Manuel

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants