You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
(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.)
#!/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/shlog() { 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)
We need a consistent approach to manage shell scripts within Terraform modules. Key challenges include:
lib.sh
across all modules.shellcheck
Validation: Ensure all scripts passshellcheck
for code quality.${VAR}
misusage between shell and Terraform variables.Essentially, this is what I've come up with:
Where:
script.tftpl
is generated/based on a templatelib.sh
is copied to all modules (from e.g..scripts/lib.sh
)run.sh
is a pure editable shell scripts, no TF variables, shellcheck and shfmt worksvars.tftpl
is autogenerated frommain.tf
script.tftpl
:(The
touch
es are present here to avoid errors when executingrun.sh
content and sourcing the files. Alternatively the source lines could be stripped out but puts logic inmain.tf
.)lib.sh
:run.sh
:vars.tftpl
:End result (coder script):
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 supportingshfmt
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
andvars.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
The text was updated successfully, but these errors were encountered: