I found a new way to set your variables with terraform without having to add the DopplerHQ/doppler
provider to the terraform files. This might be a more tedious approach, but I found it interesting
For all the variables, I set them in the variables.tf
file and then just used doppler when running the apply command.
Letâs say we had a variable
# variables.tf file
var "gitlab_pat" {
type = string
description = " .... "
}
Then we would run the apply command with
terraform apply -var gitlab_pat=$(doppler run -- printenv GITLAB_PAT)
I wonder if thereâs a better way of accessing environment variables in Terraform from the doppler CLI without adding the doppler provider?
Hi @snpranav,
Great idea! While using the Doppler Terraform provider gives a ton of control, it can be a heavy-weight solution if you just want to load your variables into Terraform.
Weâve actually just added beta support for âname transformersâ in the Doppler CLI. The idea is that the CLI can transform the names of your Doppler variables from UPPER_SNAKE_CASE to camelCase, lower_snake_case, or UpperCamelCase (depending on the flag you set). The CLI also supports a special name transformer called âtf-varâ which transforms your secret names into the Terraform Environment Variable format.
In your GITLAB_PAT
example, you can run:
doppler run --name-transformer tf-var -- terraform apply
This will convert GITLAB_PAT
to an environment variable called TF_VAR_gitlab_pat
, which will be automatically be read into Terraform as the gitlab_pat
variable.
This functionality is brand new so we havenât added docs for it yet but they should be available soon! Is this along the lines of what youâre looking for?