Rearchitecture Modules
I maintainer di solito rispondono entro 1 giorno
Nessuno ha ancora preso questa issue.
Valutazione
- Difficoltà
- 5/5
- Tempo stimato
- Più di una settimana
- Idoneità per principianti
- 25/100
- Tipo di issue
- Refactoring
- Chiarezza
- Da chiarire
- Stato di attività
- Ferma
- Stack tecnologico
- bash, shell, terraform
- Ambito
- infrastructure, tooling
Direzione di ricerca
Inizia con gli esempi dei moduli e i file indicati: main.tf, script.tftpl, vars.tftpl, lib.sh, run.sh e .scripts/lib.sh. Confronta il flusso di variabili proposto da Terraform a shell e scegli un approccio manutenibile; il lavoro è concluso quando la struttura del modulo, la gestione di shellcheck/shfmt e le regole di interpolazione delle variabili sono concordate e documentate.
Scritto dal modello di indicizzazione a partire dal testo della issue.
Descrizione
We need a consistent approach to manage shell scripts within Terraform modules. Key challenges include:
- Common Code Inclusion: Best way to include
lib.shacross all modules. shellcheckValidation: Ensure all scripts passshellcheckfor code quality.- TF Variable Access: Reliable access to Terraform variables in scripts.
- Variable Name Conflicts: Avoid
${VAR}misusage between shell and Terraform variables.
Essentially, this is what I've come up with:
resource "coder_script" "vscode-web" {
script = templatefile("${path.module}/script.tftpl", {
LOADER: "/usr/bin/env bash",
LIB: file("${path.module}/lib.sh"),
RUN: file("${path.module}/run.sh"),
VARS: templatefile("${path.module}/vars.tftpl", {
PORT : var.port,
LOG_PATH : var.log_path,
INSTALL_PREFIX : var.install_prefix,
EXTENSIONS : join(",", var.extensions),
TELEMETRY_LEVEL : var.telemetry_level,
// This is necessary otherwise the quotes are stripped!
SETTINGS : replace(jsonencode(var.settings), "\"", "\\\""),
OFFLINE : var.offline,
USE_CACHED : var.use_cached,
EXTENSIONS_DIR : var.extensions_dir,
FOLDER : var.folder,
AUTO_INSTALL_EXTENSIONS : var.auto_install_extensions,
}),
})
}
Where:
script.tftplis generated/based on a templatelib.shis copied to all modules (from e.g..scripts/lib.sh)run.shis a pure editable shell scripts, no TF variables, shellcheck and shfmt worksvars.tftplis autogenerated frommain.tf
script.tftpl:
#!${LOADER}
# lib.sh
touch "$CODER_SCRIPT_DATA_DIR/lib.sh"
${LIB}
# vars.tftpl
touch "$CODER_SCRIPT_DATA_DIR/vars.tftpl"
${VARS}
# run.sh
${RUN}
(The touches are present here to avoid errors when executing run.sh content and sourcing the files. Alternatively the source lines could be stripped out but puts logic in main.tf.)
lib.sh:
#!/bin/sh
log() { echo "$@" }
run.sh:
#!/usr/bin/env bash
# shellcheck source=vscode-web/lib.sh
. "${CODER_SCRIPT_DATA_DIR}/lib.sh"
# shellcheck source=vscode-web/vars.tftpl
. "${CODER_SCRIPT_DATA_DIR}/vars.tftpl"
run_vscode_web() {
log running... # log from lib.sh
# ...
vars.tftpl:
#!/usr/bin/env sh
# Code generated by [insert name]. DO NOT EDIT.
# shellcheck disable=SC2269
PORT="${PORT}" # type: number, default: 13338, description: The port to run VS Code Web on.
LOG_PATH="${LOG_PATH}" # ...
INSTALL_PREFIX="${INSTALL_PREFIX}"
EXTENSIONS="${EXTENSIONS}"
TELEMETRY_LEVEL="${TELEMETRY_LEVEL}"
SETTINGS="${SETTINGS}"
OFFLINE="${OFFLINE}"
USE_CACHED="${USE_CACHED}"
EXTENSIONS_DIR="${EXTENSIONS_DIR}"
FOLDER="${FOLDER}"
AUTO_INSTALL_EXTENSIONS="${AUTO_INSTALL_EXTENSIONS}"
End result (coder script):
#!/usr/bin/env bash
# lib.sh
touch "$CODER_SCRIPT_DATA_DIR/lib.sh"
#!/bin/sh
log() { echo "$@" }
# vars.tftpl
touch "$CODER_SCRIPT_DATA_DIR/vars.tftpl"
#!/usr/bin/env sh
# Code generated by [insert name]. DO NOT EDIT.
# shellcheck disable=SC2269
PORT="${PORT}" # type: number, default: 13338, description: The port to run VS Code Web on.
LOG_PATH="${LOG_PATH}" # ...
INSTALL_PREFIX="${INSTALL_PREFIX}"
EXTENSIONS="${EXTENSIONS}"
TELEMETRY_LEVEL="${TELEMETRY_LEVEL}"
SETTINGS="${SETTINGS}"
OFFLINE="${OFFLINE}"
USE_CACHED="${USE_CACHED}"
EXTENSIONS_DIR="${EXTENSIONS_DIR}"
FOLDER="${FOLDER}"
AUTO_INSTALL_EXTENSIONS="${AUTO_INSTALL_EXTENSIONS}"
# run.sh
#!/usr/bin/env bash
# shellcheck source=vscode-web/lib.sh
. "${CODER_SCRIPT_DATA_DIR}/lib.sh"
# shellcheck source=vscode-web/vars.tftpl
. "${CODER_SCRIPT_DATA_DIR}/vars.tftpl"
run_vscode_web() {
log running... # log from lib.sh
# ...
Not sure if this will make it hard to understand the project structure and how/where to contribute. I have some other ideas too, but that requires introducing a pre-filter for shellcheck and supporting shfmt would be hard. Also you'd still have to be careful with $${VAR} vs ${VAR} but we could introduce a new linter for that and enforce that all tf is at the top of the file, for instance.
Also, it'd be possible to combine script.tftpl and vars.tftpl if that makes things easier, but at the same time it'd be a bit of inception (run.sh imports script.tftpl and script.tftpl embeds run.sh)
Originally posted by @mafredri in #331
- Lingua principale
- HCL
- Stelle
- 81
- Fork
- 168
- Merge medio
- 3g 2h
- PR unite (30g)
- 36
Preparare l'ambiente
- Nessun Dockerfile né file Docker Compose
- Ha un modello di pull request
- Leggi la guida per i contributori
Come iniziare
- Leggi tutta la issue e poi la guida ai contributi del progetto.
- Commenta sulla issue per dire che te ne occupi tu — evita che due persone facciano lo stesso lavoro.
- Fai un fork del repository e lavora su un branch.
- Apri una pull request che faccia riferimento al numero della issue.
Altre issue di coder/registry
-
perplexica: deprecate or fixAperta
Difficoltà 2/5 1-3 ore Idoneità per principianti 65/100
coder/registry#1142 · 2 commenti ·
I maintainer di solito rispondono entro 1 giorno
-
Add a stale workflow for PRsAperta
Difficoltà 2/5 Mezza giornata Idoneità per principianti 68/100
coder/registry#1120 · 1 commento ·
I maintainer di solito rispondono entro 1 giorno
-
OpenShift templateForse già presa @Edd88-pixel l’ha presa 7 giorni fa. Aperta
Difficoltà 4/5 3-5 giorni Idoneità per principianti 50/100
coder/registry#1162 · 1 commento · 1 assegnatario ·
I maintainer di solito rispondono entro 1 giorno
-
bug: claude-code keeps stale configuration after managed settings or API key helper are disabledForse già presa @Edd88-pixel l’ha presa 13 giorni fa. Aperta
coder/registry#1156 · 1 commento · 1 reazione · 1 assegnatario ·
I maintainer di solito rispondono entro 1 giorno
-
chore: ensure that AWS EC2 instances actually use the AWS region moduleForse già presa @phorcys420 l’ha presa 12 giorni fa. Aperta
coder/registry#1122 · 1 commento · 1 assegnatario ·
I maintainer di solito rispondono entro 1 giorno
Tutte le issue di coder/registry
Issue simili
-
good first issue No-AI
Difficoltà 2/5 1-3 ore Idoneità per principianti 69/100
-
Status: Triage Type: Bug
Difficoltà 2/5 1-3 ore Idoneità per principianti 86/100
-
Set wallpaperApertanew-addition
Difficoltà 1/5 Meno di un'ora Idoneità per principianti 60/100
-
Difficoltà 2/5 1-3 ore Idoneità per principianti 78/100
I maintainer di solito rispondono entro 1 giorno
-
ci: pin Go version in Build and Unit Test workflows (>=1.26.6 floats to 1.27.2 and breaks golangci-lint)Forse già presa @leninmehedy l’ha presa oggi. Aperta
Difficoltà 2/5 1-3 ore Idoneità per principianti 87/100
hashgraph/solo-weaver#1255 ·
I maintainer di solito rispondono entro 1 giorno