Skip to content

Commit 269046e

Browse files
fix: skip validating unknown versions list (#115)
This fixes an error when setting the `versions` attribute of a `coderd_template` using a variable, e.g: ```terraform resource "coderd_template" "dev" { versions = var.template_versions [...] } variable "template_versions" { description = "Versions of the Coder template." default = [ { directory = "modules/" active = true tf_vars = [ { name = "coder_instance" value = "prod" } ] } ] } ``` would return: ``` │ Error: Value Conversion Error │ │ with module.devcontainers.coderd_template.dev, │ 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: │ Target Type: []provider.TemplateVersion │ Suggested Type: basetypes.ListValue ``` This error was caused by attempting to validate the versions list without checking if the config value is unknown. Normally, this value should never be unknown, as it's required, but it looks like Terraform does a configuration validation *before* variables are populated, as well as after. To confirm this is the correct solution, we see that all the default validators perform the same null & unknown checks, e.g: ```go func (v lengthBetweenValidator) ValidateString(ctx context.Context, request validator.StringRequest, response *validator.StringResponse) { if request.ConfigValue.IsNull() || request.ConfigValue.IsUnknown() { return } ... } ```
1 parent 7bbfc7f commit 269046e

File tree

1 file changed

+4
-0
lines changed

1 file changed

+4
-0
lines changed

internal/provider/template_resource.go

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -888,6 +888,10 @@ func (a *activeVersionValidator) MarkdownDescription(context.Context) string {
888888

889889
// ValidateList implements validator.List.
890890
func (a *activeVersionValidator) ValidateList(ctx context.Context, req validator.ListRequest, resp *validator.ListResponse) {
891+
if req.ConfigValue.IsNull() || req.ConfigValue.IsUnknown() {
892+
return
893+
}
894+
891895
var data []TemplateVersion
892896
resp.Diagnostics.Append(req.ConfigValue.ElementsAs(ctx, &data, false)...)
893897
if resp.Diagnostics.HasError() {

0 commit comments

Comments
 (0)
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