I was working on my personal project on Terraform deployments on AKS and had this urge to automate the deployment. By setting Environment variables in Terraform, certain frequently used variable’s values & behaviour can be customised , or to increase output verbosity for debugging.
Environment variables generally help to abstract away and set variables like usernames, password, aad-client-id, client secret for them to be available through the terraform IAC code deployement process.
When i looked for documentation for setting Environment variables in the Terraform in Windows system, i could only find specific documentation using EXPORT command here.
After running you terraform.exe init command, if you are trying to set the environment variables before running terraform.exe apply and if you are running your Terraform deployments on VS Code or powershell on windows OS, EXPORT command doesn’t really work to set environment variables.
Environment variables in the form TF_VAR_*** cannot be set using the SET command on windows and we either need a variable with $format to set the value. After spending a few hours trying to fix this issue, found the below snippet works for my requirement.
Set-Item -Path env:TF_VAR_user_name -Value “terraform_user“
Hope this helps someone who have same issue with Terraform deployments on windows. Happy Learning!!!