Skip to content

Bug: Panic when removing resource_monitoring block from coder_agent resource #432

@blink-so

Description

@blink-so

Description

Removing the resource_monitoring block from a coder_agent resource causes a panic with "index out of range [0] with length 0" error when starting workspaces. This appears to be a long-standing issue that affects workspace functionality when users attempt to disable resource monitoring.

Note: The issue occurs both when completely removing the block AND when replacing the content with empty braces {}.

Expected Behavior

  • Removing the resource_monitoring block should either:
    1. Allow the workspace to start normally without monitoring (if this is intended to be optional)
    2. Provide a clear validation error explaining that resource_monitoring is required
  • Empty resource_monitoring {} blocks should either be handled gracefully or validated properly

Actual Behavior

  • Workspace fails to start with a panic
  • Error message: The plugin.(*GRPCProvider).PlanResourceChange request was cancelled.
  • Stack trace shows: panic: runtime error: index out of range [0] with length 0

Steps to Reproduce

  1. Create a template with a coder_agent resource that includes a resource_monitoring block
  2. Successfully deploy workspaces using this template
  3. Either:
    • Remove the entire resource_monitoring block from the coder_agent resource, OR
    • Replace the resource_monitoring content with empty braces: resource_monitoring {}
  4. Update the template
  5. Attempt to start a workspace

Environment

  • Provider Version: v2.10.0 (also reproduced in v2.8.0 and v2.4.0)
  • Test platform: Coder 2.25.1

Example Configuration

Working configuration:

resource "coder_agent" "main" {
  os   = "linux"
  arch = "amd64"

  resources_monitoring {
    memory {
      enabled   = true
      threshold = 90
    }
    volume {
      path      = "/home/coder"
      enabled   = true
      threshold = 80
    }
  }
}

Failing configurations:

Option 1 - Completely removed:

resource "coder_agent" "main" {
  os   = "linux"
  arch = "amd64"
  # resource_monitoring block removed entirely
}

Option 2 - Empty block:

resource "coder_agent" "main" {
  os   = "linux"
  arch = "amd64"
  
  resources_monitoring {
    # empty block - also causes panic
  }
}

Additional Context

  • This issue has been consistent across multiple provider versions (v2.4.0, v2.8.0, v2.10.0)
  • The panic occurs at runtime when starting workspaces, not during template validation
  • Template can be uploaded successfully, but workspace creation fails
  • Rolling back the provider version does not resolve the issue once the resource_monitoring block is removed or emptied
  • The error specifically affects line 86 in the customer's template (the coder_agent resource)
  • Both complete removal and empty block replacement ({}) are equally destructive

Customer Impact

  • Prevents users from disabling resource monitoring when desired
  • Causes workspace startup failures
  • Requires keeping resource monitoring enabled with actual content even when not needed
  • No graceful way to disable monitoring functionality

Suggested Solutions

  1. If resource_monitoring is optional: Fix the panic by properly handling the case where the block is absent or empty
  2. If resource_monitoring is required: Add proper validation to prevent template upload/update when the block is missing or empty
  3. Feature enhancement: Allow explicit disabling of resource monitoring with a boolean flag or handle empty blocks gracefully
  4. Validation improvement: Provide clear error messages during template validation rather than runtime panics

Classification

This issue sits between a bug report and feature request:

  • Bug aspect: The panic and poor error handling when the block is removed or emptied
  • Feature aspect: The ability to optionally disable resource monitoring

Metadata

Metadata

Assignees

Type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions