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

Skip to content

Pass git configuration variables via terraform #3034

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 7 commits into from
Jul 19, 2022

Conversation

dwahler
Copy link
Contributor

@dwahler dwahler commented Jul 18, 2022

This PR removes the hard-coded agent functionality that sets GIT_* environment variables automatically. Instead, we pass the username and email address of the workspace owner to the Terraform provisioner, so that users can explicitly configure this behavior with the env block of the coder_agent resource:

resource "coder_agent" "dev" {
  # ...
  env = {
    GIT_AUTHOR_NAME = "${data.coder_workspace.me.owner}"
    GIT_COMMITTER_NAME = "${data.coder_workspace.me.owner}"
    GIT_AUTHOR_EMAIL = "${data.coder_workspace.me.owner_email}"
    GIT_COMMITTER_EMAIL = "${data.coder_workspace.me.owner_email}"
  }
}

I've also added this configuration to the docker and docker-code-server example templates.

Depends on the corresponding provider change in coder/terraform-provider-coder#31 to add the new owner_email data source attribute.

Fixes #2665, obsoletes #2980, obsoletes #2981

@dwahler
Copy link
Contributor Author

dwahler commented Jul 18, 2022

Updated to no longer pass an owner_name variable which is currently redundant with owner.

Comment on lines 99 to 104
env = {
GIT_AUTHOR_NAME = "${data.coder_workspace.me.owner}"
GIT_COMMITTER_NAME = "${data.coder_workspace.me.owner}"
GIT_AUTHOR_EMAIL = "${data.coder_workspace.me.owner_email}"
GIT_COMMITTER_EMAIL = "${data.coder_workspace.me.owner_email}"
}
Copy link
Member

Choose a reason for hiding this comment

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

I think we should add this to our docs (which you can do in this PR too), but we shouldn't do it in all templates. I think it could give the perception that this is mandatory when it certainly isn't.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Makes sense. In that case I'd lean towards including it in the docker and docker-code-server templates, since those are the ones that are most likely to be used for a "quickstart", and removing it from the others. I'll add documentation as well.

Copy link
Member

Choose a reason for hiding this comment

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

I agree with that. Makes sense to me!

@dwahler dwahler requested review from ammario and jsjoeio as code owners July 18, 2022 22:23
Copy link
Contributor

@jsjoeio jsjoeio left a comment

Choose a reason for hiding this comment

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

This seems like a really nice UX improvement - thanks for adding to the docker-code-server template too! 🎉

Copy link
Member

@kylecarbs kylecarbs left a comment

Choose a reason for hiding this comment

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

@ammario is going to review the docs (he's been doing a buncha that), but the code looks great to me!

Awesome change, and good investigation 🕵️🥳

Copy link
Member

@mafredri mafredri left a comment

Choose a reason for hiding this comment

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

This turned out really nice!

for more information.

For example, the [Docker quick-start template](https://github.com/coder/coder/tree/main/examples/templates/docker)
sets a few environment variables based on the username and email address of the user's owner, so
Copy link
Member

Choose a reason for hiding this comment

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

Suggested change
sets a few environment variables based on the username and email address of the user's owner, so
sets a few environment variables based on the username and email address of the workspace's owner, so

}
```

You can add these variable definitions to your own templates, or customize them however you like.
Copy link
Member

Choose a reason for hiding this comment

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

Suggested change
You can add these variable definitions to your own templates, or customize them however you like.
You can add these environment variable definitions to your own templates, or customize them however you like.

@@ -39,6 +39,17 @@ resource "coder_agent" "dev" {
arch = var.docker_arch
os = "linux"
startup_script = "code-server --auth none"

# These environment variables allow you to make Git commits right away after creating a
# workspace. Note that they take precedence over configuration defined in ~/.gitconfig!
Copy link
Member

Choose a reason for hiding this comment

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

❤️ For calling out this behavior!

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

Successfully merging this pull request may close these issues.

Add option to disable the automated settings of git env vars or make it possible to customise them
5 participants