这是indexloc提供的服务,不要输入任何密码
Skip to content

Conversation

@walteh
Copy link
Owner

@walteh walteh commented Aug 5, 2025

Summary

  • allow tasks to define their own vars that override global ones
  • test task-local vars referencing globals

Testing

  • go test ./...

Prompt

Task 11: Support Nested vars Blocks Within Tasks

Purpose:
Enable task-scoped variable definitions via vars blocks inside individual task definitions. This allows task-local variables that override or extend global ones and participate in the same expression resolution model.


Requirements:

  • Each task block may contain its own vars block.
  • The semantics of task-scoped vars should follow the same lazy evaluation and recursive resolution rules as global variables.
  • Task-local variables may refer to global variables via vars.X, and vice versa is not allowed.
  • The task-scoped vars must be evaluated in a merged context (global + local), with local vars taking precedence.
  • Dynamic typing and expression support must be preserved in the task-level vars.

Examples to Support:

vars {
  ABC = 123
}

task "hi" {
  vars {
    DEF = 456
    GHI = "${vars.ABC}${vars.DEF}"
  }
}

Assert:

  • vars.ABC == 123
  • vars.DEF == 456 (only within task hi)
  • vars.GHI == "123456" (in task hi only)

Scope:

  • Applies only to the vars block (not env) inside tasks.
  • Only variables defined in a task block's vars should shadow globals.
  • Resolution behavior must follow the recursive logic from Task 9, using the merged context.

Implementation Notes (Do Not Copy Code):

  • During decoding, task-level vars should be parsed as hcl.Expression like global vars.
  • During task execution, merge the global variable context with the task-local context to form a unified evaluator.
  • Ensure memoization and cycle detection respects the local vs global separation.
  • Preserve HCL source range on all expressions for consistent error messages.

Validation:

  • Add a test to HCLE2ETest that defines global vars, and a task with additional vars.
  • Confirm:
    • Global variables are available inside tasks.
    • Task-local variables can override or extend global ones.
    • Combined interpolations (like ${vars.ABC}${vars.DEF}) resolve as expected.
  • Test that a task referencing only local variables behaves the same way.
  • Test invalid references (e.g., task-local vars attempting to override global env) and validate that appropriate errors or rejections occur.
  • Confirm that the scope of task-level vars is isolated and does not leak between tasks.

https://chatgpt.com/codex/tasks/task_e_68924507f3508330b1b9e26a2cb6344d

@walteh walteh merged commit e039842 into codex/hcl Aug 5, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants