Search code examples
terraform

How do I use "http" backend provider together with environment variables ? I set the required env variables on my computer, but it is not working


I wanted to set up Terraform "http" backend (https://developer.hashicorp.com/terraform/language/settings/backends/http) and one of the options (which is recommended) is to use environment variables as shown below:

enter image description here

I have set up those environment variables on my local machine (using export command) to point to my GitLab repository state storage and in the terraform{} block I leave the backend "http" {} block empty as shown:

enter image description here

But once I run the command terraform init , it still asks me to enter the data manually even though I have environment variables set up:

enter image description here

Why is that so ? Has anyone encountered similar situation and has an answer why do my environment variables are not working ? Maybe there is an additional step I need to make ?


Solution

  • Turns out the problem was related to environment variables. I was only setting env variables for the shell process that I had open and then I opened another shell the variables were not there anymore.

    I added the variables to the .bashrc file so every time a new shell is launched it automatically adds the environment variables also.