Skip to content

Stable way to get Workspace owner's email in terraform #326

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

Open
aarosil opened this issue Jan 14, 2025 · 5 comments
Open

Stable way to get Workspace owner's email in terraform #326

aarosil opened this issue Jan 14, 2025 · 5 comments

Comments

@aarosil
Copy link

aarosil commented Jan 14, 2025

I'm reading data.coder_workspace_owner.me.email in a template for use in Kubernetes, to derive the user's namespace from their email address. During destroy, the datasource returns [email protected], so my template breaks. Is there a stable way to access the user's email from within the template?

This is the code I'm using now which doesn't work:

namespace = data.coder_workspace_owner.me.email != "[email protected]" ? replace(split("@", data.coder_workspace_owner.me.email)[0], ".", "-") : "coder"

I added a check for the default value after noticing template push failed validation

@coder-labeler coder-labeler bot added the question Further information is requested label Jan 14, 2025
@aarosil
Copy link
Author

aarosil commented Jan 14, 2025

From talking to a co-worker, I'm thinking this could fairly be considered a bug... it makes sense to use dummy values during coder template push, but given the workstation was already created with known values of the workspace owner, it seems like they should be able to be populated during terraform destroy...

@aarosil
Copy link
Author

aarosil commented Jan 16, 2025

I added this to my template as a workaround:

# write email to a file since data.coder_workspace_owner
# gets populated with dummy values upon teraform destroy
resource "local_file" "email" {
  filename = "email"
  content  = data.coder_workspace_owner.me.email
  lifecycle {
    ignore_changes = [
      content
    ]
  }
}

Then I just replaced local_file.email.content everywhere I had coder_workspace_owner.me.email

@aarosil
Copy link
Author

aarosil commented Jan 16, 2025

Not sure whether you consider this a bug. If not, it would be useful to mention at the docs that the values are only populated during terraform apply

@johnstcn
Copy link
Member

Hi @aarosil , can you provide the versions of Coder and the Terraform provider for which you are seeing this behaviour?

@aarosil
Copy link
Author

aarosil commented Feb 7, 2025

Hi @aarosil , can you provide the versions of Coder and the Terraform provider for which you are seeing this behaviour?

Sure, it was coder Helm chart 2.16.1 and the latest provider...I pinned my provider to < 3.0.0

I can try again with any later versions in case you can't reproduce it

@matifali matifali removed the question Further information is requested label Feb 7, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants