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: include template variables in dynamic parameter rendering#18819

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
Emyrk merged 14 commits intomainfromstevenmasley/template_vars
Jul 21, 2025

Conversation

Emyrk
Copy link
Member

@EmyrkEmyrk commentedJul 9, 2025
edited by coderabbitaibot
Loading

Closes#18671

Template variables now loaded into dynamic parameters. Future work is#18819 (comment) &#18819 (comment). Both are related

Summary by CodeRabbit

  • New Features

    • Added support for template version variables in dynamic parameter rendering and workspace tag generation.
    • Users can now provide variable values when creating or previewing template versions.
    • Terraform configurations can now expose and utilize user-defined variables in dynamic parameters.
  • Bug Fixes

    • Improved handling of variable types and defaults in dynamic parameter evaluation.
  • Tests

    • Enhanced test coverage for dynamic parameters and workspace tags with new test cases and refactored test structures.
  • Chores

    • Updated dependencies to the latest version of the preview module.
    • Added clarifying comments for future improvements in Terraform parsing.

@EmyrkEmyrk self-assigned thisJul 9, 2025
@EmyrkEmyrkforce-pushed thestevenmasley/template_vars branch frome1915e7 toa8bdd04CompareJuly 14, 2025 16:17
@EmyrkEmyrk marked this pull request as ready for reviewJuly 17, 2025 18:17
Comment on lines +28 to +34
// Defaulting the empty type to "string"
// TODO: This does not match the terraform behavior, however it is too late
// at this point in the code to determine this, as the database type stores all values
// as strings. The code needs to be fixed in the `Parse` step of the provisioner.
// That step should determine the type of the variable correctly and store it in the database.
case"string","":
ctyVals[v.Name]=cty.StringVal(value)
Copy link
MemberAuthor

Choose a reason for hiding this comment

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

This is not ideal, will resolve in another PR

Comment on lines +18 to +21
// TODO: This Parse is incomplete. It uses tfparse instead of terraform.
// The inputs are incomplete, as values such as the user context, parameters,
// etc are all important to the parsing process. This should be replaced with
// preview and have all inputs.
Copy link
MemberAuthor

Choose a reason for hiding this comment

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

I need to fix this to remove the need for tfparse

johnstcn reacted with thumbs up emoji
@EmyrkEmyrk requested a review fromjohnstcnJuly 21, 2025 14:49
@coderabbitaicoderabbitai
Copy link

coderabbitaibot commentedJul 21, 2025
edited
Loading

Caution

Review failed

An error occurred during the review process. Please try again later.

Walkthrough

The changes introduce support for passing and handling user-supplied template variable values in dynamic parameter flows, aligning behavior with classic flows. This includes updates to data structures, dynamic parameter rendering, test coverage, and workspace builder logic. Additional refactoring and minor improvements are made to related tests and documentation.

Changes

File(s)Change Summary
coderd/coderdtest/dynamicparameters.goAddedVariables field toDynamicParameterTemplateParams; logic to handle variables in template creation and parsing.
coderd/dynamicparameters/render.go, coderd/dynamicparameters/variablevalues.goAdded support for loading, caching, and converting template version variables for dynamic parameter rendering.
coderd/parameters_test.goAdded test coverage for template variables; extended test setup to support variable injection.
coderd/templateversions.goUpdated function signatures and logic to pass user-supplied template variable values for dynamic tag generation.
coderd/testdata/parameters/variables/main.tfAdded Terraform configuration for variable and coder_parameter resource for parameter exposure in tests.
coderd/wsbuilder/wsbuilder.goIntegrated template version variables into dynamic parameter renderer preparation; added error handling.
enterprise/coderd/workspaces_test.goRefactored workspace tags Terraform tests; added struct for test cases, helper function, and improved assertions.
go.modUpdatedgithub.com/coder/preview module version.
provisioner/terraform/parse.goAdded a TODO comment regarding the completeness and future direction of theParse method.

Sequence Diagram(s)

sequenceDiagram    participant User    participant API    participant DB    participant DynamicRenderer    User->>API: Submit template version with variable values    API->>DB: Store template and variables    API->>DynamicRenderer: Prepare dynamic renderer (with variables)    DynamicRenderer->>DB: Load template variable values (if not provided)    DynamicRenderer->>DynamicRenderer: Convert variables to TFVars    DynamicRenderer->>API: Return rendered parameters (using TFVars)    API->>User: Respond with rendered parameters
Loading

Estimated code review effort

3 (~45 minutes)

Poem

🐇
In burrows deep, I tweak and twirl,
Now variables in both worlds swirl!
Dynamic and Classic, side by side,
No more differences to hide.
With tests and tags, the code’s refined—
A rabbit’s hop for peace of mind!
🌱


🪧 Tips

Chat

There are 3 ways to chat withCodeRabbit:

  • Review comments: Directly reply to a review comment made by CodeRabbit. Example:
    • I pushed a fix in commit <commit_id>, please review it.
    • Explain this complex logic.
    • Open a follow-up GitHub issue for this discussion.
  • Files and specific lines of code (under the "Files changed" tab): Tag@coderabbitai in a new review comment at the desired location with your query. Examples:
    • @coderabbitai explain this code block.
    • @coderabbitai modularize this function.
  • PR comments: Tag@coderabbitai in a new PR comment to ask questions about the PR branch. For the best results, please provide a very specific query, as very limited context is provided in this mode. Examples:
    • @coderabbitai gather interesting stats about this repository and render them as a table. Additionally, render a pie chart showing the language distribution in the codebase.
    • @coderabbitai read src/utils.ts and explain its main purpose.
    • @coderabbitai read the files in the src/scheduler package and generate a class diagram using mermaid and a README in the markdown format.
    • @coderabbitai help me debug CodeRabbit configuration file.

Support

Need help? Create a ticket on oursupport page for assistance with any issues or questions.

Note: Be mindful of the bot's finite context window. It's strongly recommended to break down tasks such as reading entire modules into smaller chunks. For a focused discussion, use review comments to chat about specific files and their changes, instead of using the PR comments.

CodeRabbit Commands (Invoked using PR comments)

  • @coderabbitai pause to pause the reviews on a PR.
  • @coderabbitai resume to resume the paused reviews.
  • @coderabbitai review to trigger an incremental review. This is useful when automatic reviews are disabled for the repository.
  • @coderabbitai full review to do a full review from scratch and review all the files again.
  • @coderabbitai summary to regenerate the summary of the PR.
  • @coderabbitai generate docstrings togenerate docstrings for this PR.
  • @coderabbitai generate sequence diagram to generate a sequence diagram of the changes in this PR.
  • @coderabbitai resolve resolve all the CodeRabbit review comments.
  • @coderabbitai configuration to show the current CodeRabbit configuration for the repository.
  • @coderabbitai help to get help.

Other keywords and placeholders

  • Add@coderabbitai ignore anywhere in the PR description to prevent this PR from being reviewed.
  • Add@coderabbitai summary to generate the high-level summary at a specific location in the PR description.
  • Add@coderabbitai anywhere in the PR title to generate the title automatically.

CodeRabbit Configuration File (.coderabbit.yaml)

  • You can programmatically configure CodeRabbit by adding a.coderabbit.yaml file to the root of your repository.
  • Please see theconfiguration documentation for more information.
  • If your editor has YAML language server enabled, you can add the path at the top of this file to enable auto-completion and validation:# yaml-language-server: $schema=https://coderabbit.ai/integrations/schema.v2.json

Documentation and Community

  • Visit ourDocumentation for detailed information on how to use CodeRabbit.
  • Join ourDiscord Community to get help, request features, and share feedback.
  • Follow us onX/Twitter for updates and announcements.

@EmyrkEmyrk requested a review fromCopilotJuly 21, 2025 15:00
Copy link
Contributor

@CopilotCopilotAI left a comment

Choose a reason for hiding this comment

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

Pull Request Overview

This PR implements support for template variables in dynamic parameter rendering, allowing templates to access variable values during the dynamic parameter resolution process. Previously, template variables were not available when rendering dynamic parameters, limiting the flexibility of parameter definitions.

  • Adds template variable support to the dynamic parameter rendering system
  • Updates the preview library dependency to enable template variable functionality
  • Includes comprehensive test coverage for both "classic" and "dynamic" parameter flows

Reviewed Changes

Copilot reviewed 10 out of 11 changed files in this pull request and generated 2 comments.

Show a summary per file
FileDescription
provisioner/terraform/parse.goAdds TODO comment about incomplete Parse function implementation
go.modUpdates preview library dependency to newer version
enterprise/coderd/workspaces_test.goRefactors test to support both dynamic and classic parameter flows
coderd/wsbuilder/wsbuilder.goIntegrates template variables into dynamic parameter renderer
coderd/testdata/parameters/variables/main.tfAdds test terraform configuration for variable testing
coderd/templateversions.goPasses template variables to dynamic tag rendering
coderd/parameters_test.goAdds test case for template variables in dynamic parameters
coderd/dynamicparameters/variablevalues.goImplements variable value conversion to cty.Value format
coderd/dynamicparameters/render.goIntegrates template variable values into dynamic renderer
coderd/coderdtest/dynamicparameters.goUpdates test helper to support template variables
Comments suppressed due to low confidence (1)

enterprise/coderd/workspaces_test.go:3178

  • The change from-time.Second*10 to-time.Second reduces the time tolerance significantly. This change appears unrelated to the PR's purpose and could make the test flaky if there are timing variations.
require.WithinRange(t, *workspace.DormantAt, time.Now().Add(-time.Second), time.Now())

// TODO: Does this break if the type is not a string?
tfVarValues:=make(map[string]cty.Value)
for_,variable:=rangetemplateVariables {
tfVarValues[variable.Name]=cty.StringVal(variable.Value)
Copy link
Member

Choose a reason for hiding this comment

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

AFAICTVariableValue.Value will always be a string?

Copy link
MemberAuthor

Choose a reason for hiding this comment

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

It is, which I just found strange. This is working for now, I will test complex behavior as I edit the source of this (the parse function)

@EmyrkEmyrk merged commitaedc019 intomainJul 21, 2025
28 checks passed
@EmyrkEmyrk deleted the stevenmasley/template_vars branchJuly 21, 2025 18:02
@github-actionsgithub-actionsbot locked and limited conversation to collaboratorsJul 21, 2025
Sign up for freeto subscribe to this conversation on GitHub. Already have an account?Sign in.
Reviewers

Copilot code reviewCopilotCopilot left review comments

@johnstcnjohnstcnjohnstcn approved these changes

Assignees

@EmyrkEmyrk

Labels
None yet
Projects
None yet
Milestone
No milestone
Development

Successfully merging this pull request may close these issues.

Terraform variables show different behavior between Classic and Dynamic template formats
2 participants
@Emyrk@johnstcn

[8]ページ先頭

©2009-2025 Movatter.jp