[Solved] Terraform does not find TF_VAR env variables to init

Hello,

I’ve got an issue with Terraform, trying to deploy Logic Apps in Azure using Azure DevOps pipelines. At the init step, Terraform doesn’t not find the TF_VAR needed by the main.tf.

I’ve added an extra debug step to display en environment variables available in the pipeline, they show up correctly with the right syntax (i’ve obviously replaced the values for security reasons…),

Generating script.
Script contents:
printenv | grep TF_VAR
========================== Starting Command Output ===========================
/usr/bin/bash --noprofile --norc /home/vsts/work/_temp/b9c25708-da92-48a6-9811-d40f42fb8a4a.sh
TF_VAR_PREFIX_LAPP=[redacted]
TF_VAR_PREFIX_ANALYTICSWORKSPACE=[redacted]
TASK_DISPLAYNAME=Display TF_VAR env variables
TF_VAR_PREFIX_SNET=[redacted]
TF_VAR_SUBSCRIPTION_ID=[redacted]
TF_VAR_PREFIX_VNET=[redacted]
TF_VAR_TAG_ENV=[redacted]
TF_VAR_PREFIX_RG=[redacted]
SYSTEM_TASKDISPLAYNAME=Display TF_VAR env variables
TF_VAR_PREFIX_LAPPSTORAGEACCOUNT=[redacted]
TF_VAR_PREFIX_ASP=[redacted]
TF_VAR_TAG_CREATOR=[redacted]

Lets take the variable prefix_lapp for example : Terraform init, the next step after the “display env variables” does not find it :
image

My repository looks like that,

repository root
|azure-pipelines
   __ azure.pipelines.yaml
| terraform
   __backend.tf 
   __main.tf
   __variables.tf 
   __providers.tf

The TF_VAR_* variables are in a variable group which is passed to the pipeline configuration like that:

[...]
variables:
  - group: 'VARGRP_TF-Azure-LogicApps_DEV'

I use these like that in the main.tf

resource "azurerm_app_service_plan" "asp" {
  name                = "${var.prefix_asp}-lapps"
  [...]
}

And here how the terraform init job looks like in the pipeline,

      - task: TerraformTaskV4@4
        displayName: Terraform Init
        inputs:
          command: 'init'
          backendType: azurerm
          backendAzureRmUseEnvironmentVariablesForAuthentication: true
          backendServiceArm: '$(azdo_serviceconnection)'
          backendAzureRmResourceGroupName: '$(tf_storage_account_rg_name)'
          backendAzureRmStorageAccountName: '$(tf_storage_account_name)'
          backendAzureRmContainerName: '$(tf_storage_account_container_name)'
          backendAzureRmKey: '$(tf_storage_account_key)'
          workingDirectory: $(working_directory)

Finally, in the variables.tf file i’ve entered all of the variables used, with no default value, only the type,

variable "prefix_asp" {
	type 		= string
}

I can’t see my mistake, the documentation says that Terraform should use these TF_VAR firstly in the precedence Input Variables - Configuration Language | Terraform | HashiCorp Developer

Thanks for the help
Arnaud

Update : Problem was due to the breakage of the variable names !
I converted them in all uppercase, in the variable group and the .tf files. It passed.