Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

feat(cli): prompt for missing required template variables on template creation#19973

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to ourterms of service andprivacy statement. We’ll occasionally send you account related emails.

Already on GitHub?Sign in to your account

Merged
rafrdz merged 2 commits intomainfromrafrdz/missing-template-variable
Oct 3, 2025

Conversation

rafrdz
Copy link

Summary

In this pull request we're adding support in the CLI for prompting the user for any missing required template variables in thecoder templates push command and automatically retrying the template build once a user has provided any missing variable values.

Closes:#19782

Demo

In the following recording I created a simple template terraform file that used different variable types (string, number, boolean, and sensitive) and prompted the user to enter a value for each variable.

See example template terraform file
...# Required variables for testing interactive promptingvariable"docker_image" {description="Docker image to use for the workspace"type=string}variable"workspace_name" {description="Name of the workspace"type=string}variable"cpu_limit" {description="CPU limit for the container (number of cores)"type=number}variable"enable_gpu" {description="Enable GPU access for the container"type=bool}variable"api_key" {description="API key for external services (sensitive)"type=stringsensitive=true}# Optional variable with defaultvariable"docker_socket" {default="/var/run/docker.sock"description="Docker socket path"type=string}...

Once the user entered a valid value for each variable, the template build would be retried.

prompt-template-variables.mov
See output from recording
$ ./scripts/coder-dev.sh templates push test-required-params -d examples/templates/test-required-params/INFO: Overriding codersdk.SessionTokenCookie as we are developing inside a Coder workspace./home/coder/coder/build/coder-slim_2.26.0-devel+a68122ca3_linux_amd64Provisioner tags:<none>WARN: No .terraform.lock.hcl file found| When provisioning, Coder will be unable to cache providers without a lockfile and must download them from the internet each time.| Create one by running  terraform initin your template directory.> Upload"examples/templates/test-required-params"? (yes/no) yes=== ✔ Queued [0ms]==> ⧗ Running==> ⧗ Running=== ✔ Running [4ms]==> ⧗ Setting up=== ✔ Setting up [0ms]==> ⧗ Parsing template parameters=== ✔ Parsing template parameters [8ms]==> ⧗ Cleaning Up=== ✘ Cleaning Up [4ms]=== ✘ Cleaning Up [8ms]Found 5 missing required variables:  - docker_image (string): Docker image to usefor the workspace  - workspace_name (string): Name of the workspace  - cpu_limit (number): CPU limitfor the container (number of cores)  - enable_gpu (bool): Enable GPU accessfor the container  - api_key (string): API keyfor external services (sensitive)The template requires valuesfor the following variables:var.docker_image (required)  Description: Docker image to usefor the workspace  Type: string  Current value:<empty>> Enter value: image-namevar.workspace_name (required)  Description: Name of the workspace  Type: string  Current value:<empty>> Enter value: workspace-namevar.cpu_limit (required)  Description: CPU limitfor the container (number of cores)  Type: number  Current value:<empty>> Enter value: 1var.enable_gpu (required)  Description: Enable GPU accessfor the container  Type: bool  Current value:<empty>? Select value:falsevar.api_key (required), sensitive  Description: API keyfor external services (sensitive)  Type: string  Current value:<empty>> Enter value: (*redacted*)******Retrying template build with provided variables...=== ✔ Queued [0ms]==> ⧗ Running==> ⧗ Running=== ✔ Running [2ms]==> ⧗ Setting up=== ✔ Setting up [0ms]==> ⧗ Parsing template parameters=== ✔ Parsing template parameters [7ms]==> ⧗ Detecting persistent resources2025-09-25 22:34:14.731Z Terraform 1.13.02025-09-25 22:34:15.140Z data.coder_provisioner.me: Refreshing...2025-09-25 22:34:15.140Z data.coder_workspace.me: Refreshing...2025-09-25 22:34:15.140Z data.coder_workspace_owner.me: Refreshing...2025-09-25 22:34:15.141Z data.coder_provisioner.me: Refreshcomplete after 0s [id=2bd73098-d127-4362-b3a5-628e5bce6998]2025-09-25 22:34:15.141Z data.coder_workspace_owner.me: Refreshcomplete after 0s [id=c2006933-4f3e-4c45-9e04-79612c3a5eca]2025-09-25 22:34:15.141Z data.coder_workspace.me: Refreshcomplete after 0s [id=36f2dc6f-0bf2-43bd-bc4d-b29768334e02]2025-09-25 22:34:15.186Z coder_agent.main: Plan to create2025-09-25 22:34:15.186Z module.code-server[0].coder_app.code-server: Plan to create2025-09-25 22:34:15.186Z docker_volume.home_volume: Plan to create2025-09-25 22:34:15.186Z module.code-server[0].coder_script.code-server: Plan to create2025-09-25 22:34:15.187Z docker_container.workspace[0]: Plan to create2025-09-25 22:34:15.187Z Plan: 5 to add, 0 to change, 0 to destroy.=== ✔ Detecting persistent resources [3104ms]==> ⧗ Detecting ephemeral resources2025-09-25 22:34:16.033Z Terraform 1.13.02025-09-25 22:34:16.428Z data.coder_workspace.me: Refreshing...2025-09-25 22:34:16.428Z data.coder_provisioner.me: Refreshing...2025-09-25 22:34:16.429Z data.coder_workspace_owner.me: Refreshing...2025-09-25 22:34:16.429Z data.coder_provisioner.me: Refreshcomplete after 0s [id=2d2f7083-88e6-425c-9df3-856a3bf4cc73]2025-09-25 22:34:16.429Z data.coder_workspace.me: Refreshcomplete after 0s [id=c723575e-c7d3-43d7-bf54-0e34d0959dc3]2025-09-25 22:34:16.431Z data.coder_workspace_owner.me: Refreshcomplete after 0s [id=d43470c2-236e-4ae9-a977-6b53688c2cb1]2025-09-25 22:34:16.453Z coder_agent.main: Plan to create2025-09-25 22:34:16.453Z docker_volume.home_volume: Plan to create2025-09-25 22:34:16.454Z Plan: 2 to add, 0 to change, 0 to destroy.=== ✔ Detecting ephemeral resources [1278ms]==> ⧗ Cleaning Up=== ✔ Cleaning Up [6ms]┌──────────────────────────────────┐│ Template Preview                 │├──────────────────────────────────┤│ RESOURCE                         │├──────────────────────────────────┤│ docker_container.workspace       ││ └─ main (linux, amd64)           │├──────────────────────────────────┤│ docker_volume.home_volume        │└──────────────────────────────────┘The test-required-params template has been created at Sep 2522:34:16! Developers can provision a workspace with this template using:Updated version at Sep 25 22:34:16!

Changes

  • Added a new function to check if the provisioner failed due to a template missing required variables
  • Added a handler function that is called when a provisioner fails due to the "missing required variables" error. The handler function will:
    • Check for provided template variables and identify any missing variables
    • Prompt the user for any missing variables (prompt is adapted based on the variable type)
    • Validate user input for missing variables
    • Retry the template build when all variables have been provided by the user

Testing

Added tests for the following scenarios:

  • Ensure validation based on variable type
  • Ensure users are not prompted for variables with a default value
  • Ensure variables provided via a variables files (--variables-file) or a variable flag (--variable) take precedence over a template

@rafrdzrafrdz marked this pull request as ready for reviewSeptember 25, 2025 23:11
@github-actionsgithub-actionsbot added the staleThis issue is like stale bread. labelOct 3, 2025
Copy link
Contributor

@brettkolodnybrettkolodny left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others.Learn more.

Lgtm!

rafrdz reacted with hooray emoji
@rafrdzrafrdz merged commitbb58844 intomainOct 3, 2025
33 checks passed
@rafrdzrafrdz deleted the rafrdz/missing-template-variable branchOctober 3, 2025 15:20
@github-actionsgithub-actionsbot locked and limited conversation to collaboratorsOct 3, 2025
Sign up for freeto subscribe to this conversation on GitHub. Already have an account?Sign in.
Reviewers

@brettkolodnybrettkolodnybrettkolodny approved these changes

Assignees

@rafrdzrafrdz

Labels
staleThis issue is like stale bread.
Projects
None yet
Milestone
No milestone
Development

Successfully merging this pull request may close these issues.

feat: prompt User to add missingvar in CLI
2 participants
@rafrdz@brettkolodny

[8]ページ先頭

©2009-2025 Movatter.jp