Skip to content

Commit 3f841e4

Browse files
committed
don't try to create user account if it already exists
1 parent 4531a39 commit 3f841e4

File tree

1 file changed

+7
-2
lines changed
  • examples/templates/gcp-linux

1 file changed

+7
-2
lines changed

examples/templates/gcp-linux/main.tf

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -77,8 +77,13 @@ resource "google_compute_instance" "dev" {
7777
#!/usr/bin/env sh
7878
set -eux pipefail
7979
80-
useradd -m -s /bin/bash "${local.linux_user}"
81-
echo "${local.linux_user} ALL=(ALL) NOPASSWD:ALL" > /etc/sudoers.d/coder-user
80+
# If user does not exist, create it and set up passwordless sudo
81+
if ! id -u "${local.linux_user}" >&/dev/null
82+
then
83+
useradd -m -s /bin/bash "${local.linux_user}"
84+
echo "${local.linux_user} ALL=(ALL) NOPASSWD:ALL" > /etc/sudoers.d/coder-user
85+
fi
86+
8287
exec sudo -u "${local.linux_user}" sh -c '${coder_agent.dev.init_script}'
8388
EOMETA
8489
}

0 commit comments

Comments
 (0)