Skip to content

Rework coder-utils module: make start_script optional, install_script required #848

@35C4n0r

Description

@35C4n0r

Summary

The coder-utils module currently requires start_script but gives install_script a default of null. In practice this is backwards — most consumers always need an install step but may not need a persistent start process. The module should be reworked so that install_script is the only required script and start_script becomes optional.

Current Behavior

  • install_script has default = null (optional).
  • start_script is required (no default).
  • module_dir_name sets a directory under $HOME/<name>.
  • Four separate outputs (pre_install_script_name, install_script_name, post_install_script_name, start_script_name) are always populated, even when the corresponding script is not created.

Desired Behavior

1. Flip required/optional for install vs start

  • install_scriptrequired (remove default). The coder_script resource is always created (no count).
  • start_scriptoptional (default = null). Conditionally created with count = var.start_script != null ? 1 : 0.

2. Rename module_dir_namemodule_directory

Give callers direct control over the full working directory path instead of only a subdirectory name. This is a breaking variable rename.

3. Consolidate outputs into a single map

Replace the four individual outputs with a single script_names map:

output "script_names" {
  value = {
    pre_install  = var.pre_install_script != null ? local.pre_install_script_name : ""
    install      = local.install_script_name
    post_install = var.post_install_script != null ? local.post_install_script_name : ""
    start        = var.start_script != null ? local.start_script_name : ""
  }
}

Empty string ("") for scripts that are not provided, rather than emitting a name for a resource that does not exist.

4. Move sync dependency resolution into locals

Introduce install_sync_deps and start_sync_deps locals to compute the correct coder exp sync want arguments, removing the duplicated conditional logic from inline script templates.

5. Add mkdir -p to every script block

With install_script now potentially the first script to run (no pre_install_script), each script block should ensure the module directory exists via mkdir -p.

6. Bump required Terraform version to >= 1.9

Breaking Changes

  • install_script becomes required — callers that omitted it will need to provide a value.
  • start_script becomes optional — callers relying on it being required should be unaffected (providing a value still works).
  • module_dir_name renamed to module_directory.
  • Four individual outputs replaced by a single script_names map output — callers referencing module.coder_utils.install_script_name must change to module.coder_utils.script_names.install, etc.

Open Questions

  • Semver: These are breaking changes. Should the version bump be 2.0.0 instead of 1.1.0?
  • Missing newline at EOF in main.tf should be fixed.

Related

Metadata

Metadata

Assignees

Labels

No labels
No labels

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions