Description
Version: 0.24.1
Original Discord Thread
Problem
I have set specific TF_VAR
's (environment variables) inside of my coder instance running in Kubernetes and I want the terraform templates to use them. However when I create new templates using these variables coder complains and wants me to pass them in through the CLI with the --variable flag
. The strange thing is that I can see the special env variables inside Coder are being read because all current templates show
terraform environment variable: TF_VAR_vault_role_id=<value redacted>
terraform environment variable: TF_VAR_vault_secret_id=<value redacted>
Initializing the backend...
Initializing modules...
...
when starting up (and I also see this when doing a template push with either garbage variable data or default values set for the variables in the tf). No matter what I have tried though, Coder doesn't actually use the TF_VAR
's it retrieves. The only way I can get these variables to be used is through this less than idea hack:
data "external" "vault_variables" {
program = ["bash", "-c", "echo \"{\\\"role_id\\\": \\\"$${TF_VAR_vault_role_id}\\\", \\\"secret_id\\\": \\\"$${TF_VAR_vault_secret_id}\\\"}\""]
}
Proposal
I'm not sure if I am doing something wrong (doesn't seem like it), if this is a bug, or if this is functionality that needs to be added. Either way, I would like for templates to have the ability to first check for applicable environment variables inside of Coder and use them before complaining that a user has not provided the required variables or just uses the default value set in the Terraform. I think what would make most sense is that by default when uploading a template to Coder, it first uses TF_VAR
's already defined and then relies on the --variable
flag for anything missing. If a user passes a variable through the flag that is already inside Coder then it overwrites that value for this template.
Images
Whenever a workspace is started:
When trying to upload a template that uses the variables inside Coder: