diff --git a/internal/provider/validator_storagedirective.go b/internal/provider/validator_storagedirective.go index bada4811..33f250d6 100644 --- a/internal/provider/validator_storagedirective.go +++ b/internal/provider/validator_storagedirective.go @@ -8,7 +8,7 @@ import ( "fmt" "github.com/hashicorp/terraform-plugin-framework/schema/validator" - "github.com/juju/juju/storage" + jujustorage "github.com/juju/juju/storage" ) type stringIsStorageDirectiveValidator struct{} @@ -30,6 +30,16 @@ func (v stringIsStorageDirectiveValidator) ValidateMap(ctx context.Context, req return } + // If the value of any element is unknown or null, there is nothing to validate. + // Note tha the method is called twice by terraform. The first time it is called with + // unknown values, and the second time with known values. + // If the behavior changes, there is no need to validate all the values. + for _, element := range req.ConfigValue.Elements() { + if element.IsUnknown() || element.IsNull() { + return + } + } + var storageDirectives map[string]string resp.Diagnostics.Append(req.ConfigValue.ElementsAs(ctx, &storageDirectives, false)...) if resp.Diagnostics.HasError() { @@ -37,7 +47,7 @@ func (v stringIsStorageDirectiveValidator) ValidateMap(ctx context.Context, req } for label, directive := range storageDirectives { - _, err := storage.ParseConstraints(directive) + _, err := jujustorage.ParseConstraints(directive) if err != nil { resp.Diagnostics.AddAttributeError( req.Path,