This repository has been archived on 2026-01-10. You can view files and clone it, but cannot push or open issues or pull requests.
coder-templates/alpine/main.tf
Steve McMaster a02ad02371
All checks were successful
continuous-integration/drone/push Build is passing
update
2022-12-01 00:01:17 -05:00

127 lines
2.9 KiB
HCL

terraform {
required_providers {
coder = {
source = "coder/coder"
version = "0.5.3"
}
kubernetes = {
source = "hashicorp/kubernetes"
version = "~> 2.12.1"
}
}
}
provider "kubernetes" {
# Authenticate via ~/.kube/config or a Coder-specific ServiceAccount, depending on admin preferences
config_path = null
}
provider "coder" {
url = "http://coder.coder.svc.cluster.local"
}
data "coder_workspace" "me" {}
resource "coder_agent" "main" {
os = "linux"
arch = "amd64"
startup_script = <<EOT
#!/bin/bash
# home folder can be empty, so copying default bash settings
if [ ! -f ~/.profile ]; then
cp /etc/skel/.profile $HOME
fi
if [ ! -f ~/.bashrc ]; then
cp /etc/skel/.bashrc $HOME
fi
# Clone the aports repository
if [ ! -d aports ]; then
git clone https://gitlab.alpinelinux.org/mcm/aports.git
(
cd aports
git pull https://gitlab.alpinelinux.org/alpine/aports.git
)
fi
# Generate abuild keys
abuild-keygen -a -i
# install and start code-server
curl -fsSL https://code-server.dev/install.sh | sh | tee code-server-install.log
code-server --auth none --port 13337 | tee code-server-install.log &
EOT
}
# code-server
resource "coder_app" "code-server" {
agent_id = coder_agent.main.id
name = "code-server"
icon = "/icon/code.svg"
url = "http://localhost:13337?folder=/home/coder"
subdomain = false
share = "owner"
healthcheck {
url = "http://localhost:13337/healthz"
interval = 3
threshold = 10
}
}
resource "kubernetes_persistent_volume_claim" "home" {
metadata {
name = "coder-${lower(data.coder_workspace.me.owner)}-${lower(data.coder_workspace.me.name)}-home"
namespace = "coder"
}
wait_until_bound = false
spec {
access_modes = ["ReadWriteOnce"]
resources {
requests = {
storage = "10Gi"
}
}
}
}
resource "kubernetes_pod" "main" {
count = data.coder_workspace.me.start_count
metadata {
name = "coder-${lower(data.coder_workspace.me.owner)}-${lower(data.coder_workspace.me.name)}"
namespace = "coder"
}
spec {
security_context {
run_as_user = "1000"
fs_group = "1000"
}
container {
name = "dev"
image = "cr.smcm.xyz/coder-images/alpine:latest"
command = ["bash", "-c", coder_agent.main.init_script]
security_context {
run_as_user = "1000"
}
env {
name = "CODER_AGENT_TOKEN"
value = coder_agent.main.token
}
volume_mount {
mount_path = "/home/coder"
name = "home"
read_only = false
}
}
volume {
name = "home"
persistent_volume_claim {
claim_name = kubernetes_persistent_volume_claim.home.metadata.0.name
read_only = false
}
}
}
}