Commit 269046e
authored
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
1 file changed
+4
-0
lines changed| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
888 | 888 | | |
889 | 889 | | |
890 | 890 | | |
| 891 | + | |
| 892 | + | |
| 893 | + | |
| 894 | + | |
891 | 895 | | |
892 | 896 | | |
893 | 897 | | |
| |||
0 commit comments