Skip to content

feat: add coder_env #174

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

Merged
merged 3 commits into from
Dec 8, 2023
Merged

feat: add coder_env #174

merged 3 commits into from
Dec 8, 2023

Conversation

mafredri
Copy link
Member

@mafredri mafredri commented Dec 8, 2023

I opted for the single-var approach (vs multi as described in #170) because I don't see a use-case for setting a lot of environment variables, and I feel it better matches the resource name and I foresee use-cases for per-environment settings (overwrite, unset, prepend, append, etc.).

Fixes #170
Refs coder/coder#10166

@mafredri mafredri requested review from matifali and mtojek December 8, 2023 11:29
return &schema.Resource{
Description: "Use this resource to set an environment variable in a workspace.",
CreateContext: func(_ context.Context, rd *schema.ResourceData, _ interface{}) diag.Diagnostics {
rd.SetId(uuid.NewString())
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I considered disallowing envs here, like PATH, CODER_AGENT_TOKEN, etc. However, I opted for doing this agent side instead (we'll log an error).

Copy link
Member

@mtojek mtojek left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I left a few ideas for further improvement. What you proposed is good for MVP.

@@ -80,6 +80,7 @@ func New() *schema.Provider {
"coder_app": appResource(),
"coder_metadata": metadataResource(),
"coder_script": scriptResource(),
"coder_env": envResource(),
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thinking loud: Do we need an "opposite" resource? coder_no_env to remove the ENV variable?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

For sure, I'd say that goes as a prop: resource "coder_env" "" { name = "FOO", unset = true }. Discussion ongoing in coder/coder#10166.

ForceNew: true,
Required: true,
},
"value": {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thinking loud: default_value if not set?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What's the use-case? Maybe we can add it later if we identify one? Since this is an optional string the default value is empty string, which is just fine.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Something similar to: using generic dot files if the user didn't provide a custom URL. But I agree to postpone it for later until we meet scenario.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Maybe that can be handled in terraform? Like value = something_something ? other : "fallback", I think this is OK since we're not really looking for user input for variables and it's unlikely you define a coder_env unless you have an idea of what it should be. 🤔

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is fine for now, thanks for challenging

Copy link
Member

@matifali matifali left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Great work. <3 I am eager to test this :)

@mafredri mafredri merged commit 471368b into main Dec 8, 2023
@mafredri mafredri deleted the mafredri/coder-env branch December 8, 2023 14:10
@github-actions github-actions bot locked and limited conversation to collaborators Dec 8, 2023
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Feature Request: Add coder_env Resource for Injecting Environment Variables into Workspaces
3 participants