Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Template parsing error when using count with module outputs in Coder 2.25.2 #19789

@blink-so

Description

@blink-so

Bug Report

Coder Version: 2.25.2

Description

When using dynamic parameters in Terraform templates, the Coder template editor displays parsing errors when a module uses count with a value that references another module's output. This affects both the count and for_each patterns.

This aligns with #19754, but we're documenting the two differences:

  • Affects local AND remote modules
  • Throws a different error when using "count"

Expected Behavior

The template should parse correctly in the Coder UI when using module outputs in count expressions, and no error messages should be displayed during template parameter configuration.

Actual Behavior

The Coder template editor shows error messages when enabling boolean parameters that control module instantiation via count. However, workspace creation still works correctly - this appears to be a cosmetic parsing issue in the editor.

Error messages displayed:

  • "Module not loaded. Did you run 'terraform init'?"
  • "Module 'module "jetbrains"[0]' in file 'main.tf:206,1-19' cannot be resolved. This module will be ignored."

Minimal Reproduction Case

File structure:

├── main.tf
└── test/
    └── test.tf

main.tf:

module "image_selector" {
  source = "./test"
}

module "jetbrains" {
  count      = module.image_selector.desktop_enabled ? 1 : 0  # This causes parsing errors
  source     = "./jetbrains"
  agent_id   = coder_agent.main.id
  agent_name = "main"
  folder     = "/home/coder"
}

resource "coder_app" "desktop" {
  count        = module.image_selector.desktop_enabled ? 1 : 0  # This also causes parsing errors
  agent_id     = coder_agent.main.id
  slug         = "desktop"
  display_name = "Desktop"
  url          = "http://localhost:6080/vnc.html?autoconnect=true"
  icon         = "/icon/desktop.svg"
}

test/test.tf:

data "coder_parameter" "enable_desktop" {
  name         = "desktop_support"
  display_name = "Enable desktop support"
  type         = "bool"
  mutable      = true
  default      = false
}

output "desktop_enabled" {
  value = data.coder_parameter.enable_desktop.value
}

Steps to Reproduce

  1. Create a Coder template with the above structure
  2. Push the template to Coder
  3. Navigate to template settings/parameters in the Coder UI
  4. Toggle the "Enable desktop support" boolean parameter
  5. Observe error messages appear in the UI

Workarounds Attempted

As suggested in the support conversation, switching to for_each produces the same parsing errors:

locals {
  desktop_enabled = module.image_selector.desktop_enabled
}

module "desktop_app" {
  for_each = local.desktop_enabled ? { "main" = true } : {}
  source   = "./modules/desktop-app"
  agent_id = module.coder_agent.agent.id
}

Related Issues

This may be related to #19754

Environment

  • Coder Version: 2.25.2
  • Terraform Version: >= 1.0 (as specified in template requirements)
  • Template Type: Custom Terraform template with dynamic parameters

Additional Context

This issue is purely cosmetic as workspace creation and functionality work as intended. The problem is limited to the template parsing in the Coder UI, which shows confusing error messages to users when configuring template parameters.

The issue occurs specifically when:

  1. A module output is used in a count or for_each expression
  2. The module output depends on a coder parameter
  3. The parameter is toggled in the Coder UI

Impact

This creates a poor user experience as users see error messages in the UI even though the template works correctly, potentially causing confusion about whether the template is properly configured.

Metadata

Metadata

Assignees

No one assigned

    Labels

    parametersbugs & feature requests related to Dynamic Parameterstemplate

    Type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions