Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Sourcing Terraform Variables from Within Coder #8279

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
ElioDiNino opened this issue Jun 30, 2023 · 2 comments
Closed

Sourcing Terraform Variables from Within Coder #8279

ElioDiNino opened this issue Jun 30, 2023 · 2 comments
Labels
stale This issue is like stale bread.

Comments

@ElioDiNino
Copy link
Contributor

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:
Screenshot 2023-06-30 at 9 03 33 AM
Screenshot 2023-06-30 at 9 04 25 AM

When trying to upload a template that uses the variables inside Coder:
Screenshot 2023-06-30 at 9 08 22 AM

@cdr-bot cdr-bot bot added the bug label Jun 30, 2023
@bpmct bpmct added the s2 Broken use cases or features (with a workaround). Only humans may set this. label Jul 14, 2023
@bpmct
Copy link
Member

bpmct commented Jul 14, 2023

Ah interesting. I'd expect that Coder wouldn't prompt for these if they are set with TF_VAR. What do you think @mtojek?

@mtojek
Copy link
Member

mtojek commented Jul 14, 2023

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.

Frankly speaking TF_VAR_... is a Terraform variable, not a Coder one, but as long as we strongly depend on Terraform, this might be a valid feature request to extend it.

@mtojek mtojek removed the bug label Jul 25, 2023
@cdr-bot cdr-bot bot added the bug label Jul 25, 2023
@mtojek mtojek added feature and removed s2 Broken use cases or features (with a workaround). Only humans may set this. bug labels Jul 25, 2023
@github-actions github-actions bot added the stale This issue is like stale bread. label Jan 22, 2024
@github-actions github-actions bot closed this as not planned Won't fix, can't repro, duplicate, stale Jan 30, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
stale This issue is like stale bread.
Projects
None yet
Development

No branches or pull requests

3 participants