A Different Way to Use Doppler with Terraform

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 :upside_down_face:

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? :thinking:

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?