Skip to content

Resource coderd_template: key-value pairs should use a map #121

@michvllni

Description

@michvllni

As the tf_vars are unique ( it is not possible to define a value for a variable more than once ) it would make sense to change the type of the tf_vars property in the template resource to a map.

How it is now:

resource "coderd_template" "template" {
  name        = "example"
  description = "example"

  versions = [
    {
      name      = "example"
      message   = "example"
      directory = "./template"
      active    = true
      tf_vars = [
        {
          name  = "default_project"
          value = "myproject"
        },
        {
          name  = "default_image_variant"
          value = "bookworm"
        },
        {
          name  = "repository"
          value = "github.com/my/repo"
        }
      ]
    }
  ]
}

How it could be:

resource "coderd_template" "template" {
  name        = "example"
  description = "example"

  versions = [
    {
      name      = "example"
      message   = "example"
      directory = "./template"
      active    = true
      tf_vars = {
          "default_project" = "myproject"
          "default_image_variant" = "bookworm"
          "repository" = "github.com/my/repo"
      }
    }
  ]
}

By doing this we could ensure that no variable is defined twice.

It would also greatly improve the plans readability, heres an example:

  # coderd_template.templates["terraform"] will be updated in-place
  ~ resource "coderd_template" "templates" {
      ~ display_name                      = "terraform" -> (known after apply)
        id                                = "442609fa-9d44-40bd-81ac-593bcbe4aec7"
      ~ max_port_share_level              = "public" -> (known after apply)
        name                              = "terraform"
      ~ organization_id                   = "6aa09569-a619-446e-8e7c-8ea848458631" -> (known after apply)
      ~ versions                          = [
          ~ {
              ~ id             = "512d14e5-2173-4091-be70-5b41209df4ac" -> (known after apply)
              ~ message        = "Merged PR 15261: fix: separate tempalte files to create separate messages" -> "Merged PR 15262: fix: terraform 1.9.8"
              ~ name           = "17f1e43475d9d47871b9aa240026e7cf729d0909" -> "54d813a3f801811851aedf69af079ea7370fafc8"
              ~ tf_vars        = [
                  - {
                      - name  = "default_image_variant" -> null
                      - value = "1.9.7" -> null
                    },
                  - {
                      - name  = "image_variants" -> null
                      - value = jsonencode(
                            [
                              - "1.5.7",
                              - "1.7.4",
                              - "1.9.2",
                              - "1.9.5",
                              - "1.9.6",
                              - "1.9.7",
                            ]
                        ) -> null
                    },
                  + {
                      + name  = "default_image_variant"
                      + value = "1.9.8"
                    },
                  + {
                      + name  = "image_variants"
                      + value = jsonencode(
                            [
                              + "1.5.7",
                              + "1.7.4",
                              + "1.9.2",
                              + "1.9.5",
                              + "1.9.6",
                              + "1.9.7",
                              + "1.9.8",
                            ]
                        )
                    },
                    # (8 unchanged elements hidden)
                ]
                # (3 unchanged attributes hidden)
            },
        ]
        # (14 unchanged attributes hidden)
    }

this could be as simple as

  # coderd_template.templates["terraform"] will be updated in-place
  ~ resource "coderd_template" "templates" {
      ~ display_name                      = "terraform" -> (known after apply)
        id                                = "442609fa-9d44-40bd-81ac-593bcbe4aec7"
      ~ max_port_share_level              = "public" -> (known after apply)
        name                              = "terraform"
      ~ organization_id                   = "6aa09569-a619-446e-8e7c-8ea848458631" -> (known after apply)
      ~ versions                          = [
          ~ {
              ~ id             = "512d14e5-2173-4091-be70-5b41209df4ac" -> (known after apply)
              ~ message        = "Merged PR 15261: fix: separate tempalte files to create separate messages" -> "Merged PR 15262: fix: terraform 1.9.8"
              ~ name           = "17f1e43475d9d47871b9aa240026e7cf729d0909" -> "54d813a3f801811851aedf69af079ea7370fafc8"
              ~ tf_vars        = {
                  ~ "default_image_variant" = "1.9.7" -> "1.9.8"
                  ~ "image_variants"        = "[\"1.5.7\",\"1.7.4\",\"1.9.2\",\"1.9.5\",\"1.9.6\",\"1.9.7\"]" -> "[\"1.5.7\",\"1.7.4\",\"1.9.2\",\"1.9.5\",\"1.9.6\",\"1.9.7\",\"1.9.8\"]"
                    # (8 unchanged elements hidden)
              }
                # (3 unchanged attributes hidden)
            },
        ]
        # (14 unchanged attributes hidden)
    }

I understand this is a breaking change, but as we are very early in the product life cycle I thought it might be an option to change this now before lots of people use the provider

Edit: Typo

Metadata

Metadata

Assignees

Labels

No labels
No labels

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions

    pFad - Phonifier reborn

    Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

    Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


    Alternative Proxies:

    Alternative Proxy

    pFad Proxy

    pFad v3 Proxy

    pFad v4 Proxy