From 354536dad5f867bf2f704956ae2950d0948b47fe Mon Sep 17 00:00:00 2001 From: Octoturge Date: Wed, 26 Aug 2026 18:38:46 +0200 Subject: [PATCH] fix: use sudo for /opt/coder setup in cli_setup_wizard and install_skills The coder_agent's coder_script resources run as the unprivileged coder user, which can't mkdir under root-owned /opt. Every template hit this identically (mkdir: cannot create directory '/opt/coder': Permission denied) since coder_script content is shared verbatim across all 6. coder has passwordless sudo everywhere, so sudo mkdir + chown to the running user unblocks the rest of each script's non-sudo writes. --- templates/3d-printing/main.tf | 6 ++++-- templates/cobol/main.tf | 6 ++++-- templates/default/main.tf | 6 ++++-- templates/python/main.tf | 6 ++++-- templates/ttrpg/main.tf | 6 ++++-- templates/web/main.tf | 6 ++++-- 6 files changed, 24 insertions(+), 12 deletions(-) diff --git a/templates/3d-printing/main.tf b/templates/3d-printing/main.tf index 196bd00..04a38e7 100644 --- a/templates/3d-printing/main.tf +++ b/templates/3d-printing/main.tf @@ -250,7 +250,8 @@ resource "coder_script" "cli_setup_wizard" { script = <<-EOT #!/bin/bash set -e - mkdir -p /opt/coder + sudo mkdir -p /opt/coder + sudo chown "$(id -u):$(id -g)" /opt/coder echo '${base64encode(file("${path.module}/cli-setup-wizard.sh"))}' | base64 -d > /opt/coder/cli-setup-wizard.sh chmod +x /opt/coder/cli-setup-wizard.sh @@ -305,7 +306,8 @@ resource "coder_script" "install_skills" { script = <<-EOT #!/bin/bash set -e - mkdir -p /opt/coder + sudo mkdir -p /opt/coder + sudo chown "$(id -u):$(id -g)" /opt/coder echo '${base64encode(file("${path.module}/install-skills.sh"))}' | base64 -d > /opt/coder/install-skills.sh chmod +x /opt/coder/install-skills.sh SPECIALTY_SKILLS="openscad-parametric" /opt/coder/install-skills.sh diff --git a/templates/cobol/main.tf b/templates/cobol/main.tf index ea53cff..4419fd8 100644 --- a/templates/cobol/main.tf +++ b/templates/cobol/main.tf @@ -250,7 +250,8 @@ resource "coder_script" "cli_setup_wizard" { script = <<-EOT #!/bin/bash set -e - mkdir -p /opt/coder + sudo mkdir -p /opt/coder + sudo chown "$(id -u):$(id -g)" /opt/coder echo '${base64encode(file("${path.module}/cli-setup-wizard.sh"))}' | base64 -d > /opt/coder/cli-setup-wizard.sh chmod +x /opt/coder/cli-setup-wizard.sh @@ -305,7 +306,8 @@ resource "coder_script" "install_skills" { script = <<-EOT #!/bin/bash set -e - mkdir -p /opt/coder + sudo mkdir -p /opt/coder + sudo chown "$(id -u):$(id -g)" /opt/coder echo '${base64encode(file("${path.module}/install-skills.sh"))}' | base64 -d > /opt/coder/install-skills.sh chmod +x /opt/coder/install-skills.sh SPECIALTY_SKILLS="cobol-teacher" /opt/coder/install-skills.sh diff --git a/templates/default/main.tf b/templates/default/main.tf index ff57b18..76caa0b 100644 --- a/templates/default/main.tf +++ b/templates/default/main.tf @@ -250,7 +250,8 @@ resource "coder_script" "cli_setup_wizard" { script = <<-EOT #!/bin/bash set -e - mkdir -p /opt/coder + sudo mkdir -p /opt/coder + sudo chown "$(id -u):$(id -g)" /opt/coder echo '${base64encode(file("${path.module}/cli-setup-wizard.sh"))}' | base64 -d > /opt/coder/cli-setup-wizard.sh chmod +x /opt/coder/cli-setup-wizard.sh @@ -306,7 +307,8 @@ resource "coder_script" "install_skills" { script = <<-EOT #!/bin/bash set -e - mkdir -p /opt/coder + sudo mkdir -p /opt/coder + sudo chown "$(id -u):$(id -g)" /opt/coder echo '${base64encode(file("${path.module}/install-skills.sh"))}' | base64 -d > /opt/coder/install-skills.sh chmod +x /opt/coder/install-skills.sh SPECIALTY_SKILLS="" /opt/coder/install-skills.sh diff --git a/templates/python/main.tf b/templates/python/main.tf index f6f676c..958822d 100644 --- a/templates/python/main.tf +++ b/templates/python/main.tf @@ -250,7 +250,8 @@ resource "coder_script" "cli_setup_wizard" { script = <<-EOT #!/bin/bash set -e - mkdir -p /opt/coder + sudo mkdir -p /opt/coder + sudo chown "$(id -u):$(id -g)" /opt/coder echo '${base64encode(file("${path.module}/cli-setup-wizard.sh"))}' | base64 -d > /opt/coder/cli-setup-wizard.sh chmod +x /opt/coder/cli-setup-wizard.sh @@ -306,7 +307,8 @@ resource "coder_script" "install_skills" { script = <<-EOT #!/bin/bash set -e - mkdir -p /opt/coder + sudo mkdir -p /opt/coder + sudo chown "$(id -u):$(id -g)" /opt/coder echo '${base64encode(file("${path.module}/install-skills.sh"))}' | base64 -d > /opt/coder/install-skills.sh chmod +x /opt/coder/install-skills.sh SPECIALTY_SKILLS="" /opt/coder/install-skills.sh diff --git a/templates/ttrpg/main.tf b/templates/ttrpg/main.tf index c6604a4..d041c28 100644 --- a/templates/ttrpg/main.tf +++ b/templates/ttrpg/main.tf @@ -250,7 +250,8 @@ resource "coder_script" "cli_setup_wizard" { script = <<-EOT #!/bin/bash set -e - mkdir -p /opt/coder + sudo mkdir -p /opt/coder + sudo chown "$(id -u):$(id -g)" /opt/coder echo '${base64encode(file("${path.module}/cli-setup-wizard.sh"))}' | base64 -d > /opt/coder/cli-setup-wizard.sh chmod +x /opt/coder/cli-setup-wizard.sh @@ -306,7 +307,8 @@ resource "coder_script" "install_skills" { script = <<-EOT #!/bin/bash set -e - mkdir -p /opt/coder + sudo mkdir -p /opt/coder + sudo chown "$(id -u):$(id -g)" /opt/coder echo '${base64encode(file("${path.module}/install-skills.sh"))}' | base64 -d > /opt/coder/install-skills.sh chmod +x /opt/coder/install-skills.sh SPECIALTY_SKILLS="foundryvtt-modding ttrpg-lore-weaver" /opt/coder/install-skills.sh diff --git a/templates/web/main.tf b/templates/web/main.tf index 5f1d0ba..2d66b75 100644 --- a/templates/web/main.tf +++ b/templates/web/main.tf @@ -270,7 +270,8 @@ resource "coder_script" "cli_setup_wizard" { script = <<-EOT #!/bin/bash set -e - mkdir -p /opt/coder + sudo mkdir -p /opt/coder + sudo chown "$(id -u):$(id -g)" /opt/coder echo '${base64encode(file("${path.module}/cli-setup-wizard.sh"))}' | base64 -d > /opt/coder/cli-setup-wizard.sh chmod +x /opt/coder/cli-setup-wizard.sh @@ -307,7 +308,8 @@ resource "coder_script" "install_skills" { script = <<-EOT #!/bin/bash set -e - mkdir -p /opt/coder + sudo mkdir -p /opt/coder + sudo chown "$(id -u):$(id -g)" /opt/coder echo '${base64encode(file("${path.module}/install-skills.sh"))}' | base64 -d > /opt/coder/install-skills.sh chmod +x /opt/coder/install-skills.sh SPECIALTY_SKILLS="" /opt/coder/install-skills.sh