Skip to content

Commit

Permalink
schema: fix unknown value validation bug (#1047)
Browse files Browse the repository at this point in the history
The validate function should exit early in the case that a value is not
wholly known. This is the intent of the comment and earlier code in this
file - however, subsequent refactors introduced a bug in which one
aspect of validation was run for unknown values: deprecation warnings.

Deprecation warnings for known values are generated by validateType
lower down.

This fix ensures that deprecation warnings are not shown for unknown
values, while still ensuring we exit validation early for all unknown
values.
  • Loading branch information
kmoe committed Sep 2, 2022
1 parent a5eecf7 commit 1288887
Show file tree
Hide file tree
Showing 2 changed files with 2 additions and 13 deletions.
10 changes: 1 addition & 9 deletions helper/schema/schema.go
Expand Up @@ -1735,15 +1735,7 @@ func (m schemaMap) validate(
// The SDK has to allow the unknown value through initially, so that
// Required fields set via an interpolated value are accepted.
if !isWhollyKnown(raw) {
if schema.Deprecated != "" {
return append(diags, diag.Diagnostic{
Severity: diag.Warning,
Summary: "Argument is deprecated",
Detail: schema.Deprecated,
AttributePath: path,
})
}
return diags
return nil
}

err = validateConflictingAttributes(k, schema, c)
Expand Down
5 changes: 1 addition & 4 deletions helper/schema/schema_test.go
Expand Up @@ -5792,10 +5792,7 @@ func TestSchemaMap_Validate(t *testing.T) {
Config: map[string]interface{}{
"old_news": hcl2shim.UnknownVariableValue,
},

Warnings: []string{
"Warning: Argument is deprecated: please use 'new_news' instead",
},
Err: false,
},

"Required sub-resource field": {
Expand Down

0 comments on commit 1288887

Please sign in to comment.