Dotfiles
Allow developers to optionally bring their own dotfiles repository to customize their shell and IDE settings!
View on GitHub (link opens in new tab)1.3M installs
Allow developers to optionally bring their own dotfiles repository.
This will prompt the user for their dotfiles repository URL on template creation using a coder_parameter
.
Under the hood, this module uses the coder dotfiles command.
module "dotfiles" { count = data.coder_workspace.me.start_count source = "registry.coder.com/coder/dotfiles/coder" version = "1.2.1" agent_id = coder_agent.example.id }
Examples
Apply dotfiles as the current user
module "dotfiles" { count = data.coder_workspace.me.start_count source = "registry.coder.com/coder/dotfiles/coder" version = "1.2.1" agent_id = coder_agent.example.id }
Apply dotfiles as another user (only works if sudo is passwordless)
module "dotfiles" { count = data.coder_workspace.me.start_count source = "registry.coder.com/coder/dotfiles/coder" version = "1.2.1" agent_id = coder_agent.example.id user = "root" }
Apply the same dotfiles as the current user and root (the root dotfiles can only be applied if sudo is passwordless)
module "dotfiles" { count = data.coder_workspace.me.start_count source = "registry.coder.com/coder/dotfiles/coder" version = "1.2.1" agent_id = coder_agent.example.id } module "dotfiles-root" { count = data.coder_workspace.me.start_count source = "registry.coder.com/coder/dotfiles/coder" version = "1.2.1" agent_id = coder_agent.example.id user = "root" dotfiles_uri = module.dotfiles.dotfiles_uri }
Setting a default dotfiles repository
You can set a default dotfiles repository for all users by setting the default_dotfiles_uri
variable:
module "dotfiles" { count = data.coder_workspace.me.start_count source = "registry.coder.com/coder/dotfiles/coder" version = "1.2.1" agent_id = coder_agent.example.id default_dotfiles_uri = "https://github.com/coder/dotfiles" }
1terraform {
2 required_version = ">= 1.0"
3
4 required_providers {
5 coder = {
6 source = "coder/coder"
7 version = ">= 2.5"
8 }
9 }
10}
11
12variable "order" {
13 type = number
14 description = "The order determines the position of app in the UI presentation. The lowest order is shown first and apps with equal order are sorted by name (ascending order)."
15 default = null
16}
17
18variable "group" {
19 type = string
20 description = "The name of a group that this app belongs to."
21 default = null
22}
23
24variable "agent_id" {
25 type = string
26 description = "The ID of a Coder agent."
27}
28
29variable "description" {
30 type = string
31 description = "A custom description for the dotfiles parameter. This is shown in the UI - and allows you to customize the instructions you give to your users."
32 default = "Enter a URL for a [dotfiles repository](https://dotfiles.github.io) to personalize your workspace"
33}
34
35variable "default_dotfiles_uri" {
36 type = string
37 description = "The default dotfiles URI if the workspace user does not provide one"
38 default = ""
39}
40
41variable "dotfiles_uri" {
42 type = string
43 description = "The URL to a dotfiles repository. (optional, when set, the user isn't prompted for their dotfiles)"
44
45 default = null
46}
47
48variable "user" {
49 type = string
50 description = "The name of the user to apply the dotfiles to. (optional, applies to the current user by default)"
51 default = null
52}
53
54variable "coder_parameter_order" {
55 type = number
56 description = "The order determines the position of a template parameter in the UI/CLI presentation. The lowest order is shown first and parameters with equal order are sorted by name (ascending order)."
57 default = null
58}
59
60variable "manual_update" {
61 type = bool
62 description = "If true, this adds a button to workspace page to refresh dotfiles on demand."
63 default = false
64}
65
66data "coder_parameter" "dotfiles_uri" {
67 count = var.dotfiles_uri == null ? 1 : 0
68 type = "string"
69 name = "dotfiles_uri"
70 display_name = "Dotfiles URL"
71 order = var.coder_parameter_order
72 default = var.default_dotfiles_uri
73 description = var.description
74 mutable = true
75 icon = "/icon/dotfiles.svg"
76}
77
78locals {
79 dotfiles_uri = var.dotfiles_uri != null ? var.dotfiles_uri : data.coder_parameter.dotfiles_uri[0].value
80 user = var.user != null ? var.user : ""
81}
82
83resource "coder_script" "dotfiles" {
84 agent_id = var.agent_id
85 script = templatefile("${path.module}/run.sh", {
86 DOTFILES_URI : local.dotfiles_uri,
87 DOTFILES_USER : local.user
88 })
89 display_name = "Dotfiles"
90 icon = "/icon/dotfiles.svg"
91 run_on_start = true
92}
93
94resource "coder_app" "dotfiles" {
95 count = var.manual_update ? 1 : 0
96 agent_id = var.agent_id
97 display_name = "Refresh Dotfiles"
98 slug = "dotfiles"
99 icon = "/icon/dotfiles.svg"
100 order = var.order
101 group = var.group
102 command = templatefile("${path.module}/run.sh", {
103 DOTFILES_URI : local.dotfiles_uri,
104 DOTFILES_USER : local.user
105 })
106}
107
108output "dotfiles_uri" {
109 description = "Dotfiles URI"
110 value = local.dotfiles_uri
111}
112