Skip to content

coderd_template "Attributes Set" input types issue #305

@jatcod3r

Description

@jatcod3r

coder/coderd Version: v0.0.12

Running into the following error for both the tf_vars and provisioner_tags attributes

│ Error: Value Conversion Error
│ 
│   with module.ai-coder-com-coder.coderd_template.this,
│   on ../modules/template/main.tf line 77, in resource "coderd_template" "this":
│   77: resource "coderd_template" "this" {
│ 
│ An unexpected error was encountered trying to build a value. This is always an error in the provider. Please report the following to the provider developer:
│ 
│ Received unknown value, however the target type cannot handle unknown values. Use the corresponding `types` package type or a custom type that handles unknown values.
│ 
│ Path: [0].tf_vars
│ Target Type: []provider.Variable
│ Suggested Type: basetypes.SetValue

Full trace output:

2026-02-23T12:12:30.572-0800 [ERROR] provider.terraform-provider-coderd_v0.0.12: Response contains error diagnostic: tf_proto_version=6.9 tf_rpc=ValidateResourceConfig @module=sdk.proto diagnostic_attribute="ElementKeyInt(0).AttributeName(\"tf_vars\")" diagnostic_severity=ERROR diagnostic_summary="Value Conversion Error" tf_provider_addr=registry.terraform.io/coder/coderd tf_req_id=4c9eed24-af71-1c06-0acd-8d0342e91694 tf_resource_type=coderd_template @caller=github.com/hashicorp/terraform-plugin-go@v0.28.0/tfprotov6/internal/diag/diagnostics.go:58
  diagnostic_detail=
  | An unexpected error was encountered trying to build a value. This is always an error in the provider. Please report the following to the provider developer:
  | 
  | Received unknown value, however the target type cannot handle unknown values. Use the corresponding `types` package type or a custom type that handles unknown values.
  | 
  | Path: [0].tf_vars
  | Target Type: []provider.Variable
  | Suggested Type: basetypes.SetValue
   timestamp=2026-02-23T12:12:30.548-0800
2026-02-23T12:12:30.572-0800 [ERROR] provider.terraform-provider-coderd_v0.0.12: Response contains error diagnostic: tf_proto_version=6.9 diagnostic_attribute="ElementKeyInt(0).AttributeName(\"tf_vars\")" tf_provider_addr=registry.terraform.io/coder/coderd tf_req_id=86de3acb-51e9-701e-efea-e819f02dd0ce tf_resource_type=coderd_template tf_rpc=ValidateResourceConfig @caller=github.com/hashicorp/terraform-plugin-go@v0.28.0/tfprotov6/internal/diag/diagnostics.go:58 @module=sdk.proto
  diagnostic_detail=
  | An unexpected error was encountered trying to build a value. This is always an error in the provider. Please report the following to the provider developer:
  | 
  | Received unknown value, however the target type cannot handle unknown values. Use the corresponding `types` package type or a custom type that handles unknown values.
  | 
  | Path: [0].tf_vars
  | Target Type: []provider.Variable
  | Suggested Type: basetypes.SetValue
   diagnostic_severity=ERROR diagnostic_summary="Value Conversion Error" timestamp=2026-02-23T12:12:30.548-0800
2026-02-23T12:12:30.572-0800 [TRACE] provider.terraform-provider-coderd_v0.0.12: Served request: @caller=github.com/hashicorp/terraform-plugin-go@v0.28.0/tfprotov6/tf6server/server.go:781 tf_provider_addr=registry.terraform.io/coder/coderd tf_req_id=4c9eed24-af71-1c06-0acd-8d0342e91694 tf_resource_type=coderd_template tf_rpc=ValidateResourceConfig @module=sdk.proto tf_proto_version=6.9 timestamp=2026-02-23T12:12:30.548-0800
2026-02-23T12:12:30.572-0800 [TRACE] provider.terraform-provider-coderd_v0.0.12: Served request: @caller=github.com/hashicorp/terraform-plugin-go@v0.28.0/tfprotov6/tf6server/server.go:781 @module=sdk.proto tf_proto_version=6.9 tf_provider_addr=registry.terraform.io/coder/coderd tf_req_id=86de3acb-51e9-701e-efea-e819f02dd0ce tf_resource_type=coderd_template tf_rpc=ValidateResourceConfig timestamp=2026-02-23T12:12:30.548-0800

Don't think we're handling the tf_vars or provisioner_tags sections correctly where it fails to convert the input even when it's converted to a set explicitly.

This is how I currently pass in variables to tf_vars:

variable "templates" {
    type = map(object({
        path        = string
        display_name = optional(string, "")
        icon        = optional(string, "")
        description = optional(string, "")
        platform = optional(string, "linux_amd64")
        vars = optional(map(string), {})
        tags = optional(map(string), {})
    }))
}

resource "coderd_template" "this" {
    
    for_each = var.templates
    depends_on = [ null_resource.upgrade-and-init ]
    
    name = each.key
    organization_id = var.org_id
    display_name = each.value.display_name == "" ? each.key : each.value.display_name
    description = each.value.description
    icon = each.value.icon
    require_active_version = true
    acl = null
    # At least 1 template must be stable. 
    # We'll keep track of this via Terraform.
    versions = [{
        name        = "stable-${formatdate("YYYY-MM-DD_hh-mm-ss", time_static.this[each.key].rfc3339)}"
        description = "Stable Version."
        directory   = each.value.path
        provisioner_tags = toset([ for k, v in each.value.tags : { name = k, value = tostring(v)}])
        tf_vars     = toset([ for k, v in each.value.vars : { name = k, value = tostring(v)}])
        active = true
    }]
}

And the TF file consuming these would look something like:

module "ai-coder-com-coder" {
  source = "../modules/template"
  providers = {
    coderd = coderd.ai-coder-com
  }
  access_url = var.ai_coder_com_access_url
  token      = var.ai_coder_com_token
  org_id     = data.coderd_organization.coder.id
  templates = {
    "memorycard" = {
      path         = "${path.module}/../deployments/ai.coder.com/coder/memorycard"
      description = "Work on a AI-powered Vite.js app running a memory card game on Coder!"
      display_name = "Memory Game App"
      icon         = "https://raw.githubusercontent.com/devicons/devicon/54cfe13ac10eaa1ef817a343ab0a9437eb3c2e08/icons/vitejs/vitejs-original.svg"
      tags = {}
      vars = {
        gh_username = var.ai_coder_com_bot_gh_username
        gh_email = var.ai_coder_com_bot_gh_email
        gh_token = var.ai_coder_com_bot_gh_token
        aws_region = "us-east-2"
        aws_account_id = var.ai_coder_com_bot_aws_account_id
        namespace = "coder-ws"
      }
    }
  }
}

The values I pass in are static strings stored in auto.tfvars.json, so although the error states that they're not resolved, they will be resolving at some point later in the Terraform apply lifecycle. I verified by statically passing in a set directly to coderd_template that this works. For example:


resource "coderd_template" "this" {
    
    for_each = var.templates
    depends_on = [ null_resource.upgrade-and-init ]
    
    name = each.key
    organization_id = var.org_id
    display_name = each.value.display_name == "" ? each.key : each.value.display_name
    description = each.value.description
    icon = each.value.icon
    require_active_version = true
    acl = null
    # At least 1 template must be stable. 
    # We'll keep track of this via Terraform.
    versions = [{
        name        = "stable-${formatdate("YYYY-MM-DD_hh-mm-ss", time_static.this[each.key].rfc3339)}"
        description = "Stable Version."
        directory   = each.value.path
        provisioner_tags = [{ name = "a", value = "b" }]
        tf_vars     = [{ name = "a", value = "b" }]
        active = true
    }]
}

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type
    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions