From bfd66083de8ac2148bf6e7ee4cdf6306472c6c02 Mon Sep 17 00:00:00 2001 From: Kristin Laemmert Date: Tue, 30 Jul 2019 16:00:43 -0400 Subject: [PATCH] helper/schema: don't skip deprecation check during validation If an attribute was not wholly known, helper/schema was skipping the `validateType` function which (among other things) returned deprecation messages. This PR checks for deprecation before returning when skipping validateType. --- helper/schema/schema.go | 3 +++ helper/schema/schema_test.go | 18 ++++++++++++++++++ 2 files changed, 21 insertions(+) diff --git a/helper/schema/schema.go b/helper/schema/schema.go index 3e5f5da1b..bcc8e4ba3 100644 --- a/helper/schema/schema.go +++ b/helper/schema/schema.go @@ -1371,6 +1371,9 @@ 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 []string{fmt.Sprintf("%q: [DEPRECATED] %s", k, schema.Deprecated)}, nil + } return nil, nil } diff --git a/helper/schema/schema_test.go b/helper/schema/schema_test.go index 055e76f26..2f941c8a6 100644 --- a/helper/schema/schema_test.go +++ b/helper/schema/schema_test.go @@ -4510,6 +4510,24 @@ func TestSchemaMap_Validate(t *testing.T) { Err: false, }, + "Unknown + Deprecation": { + Schema: map[string]*Schema{ + "old_news": &Schema{ + Type: TypeString, + Optional: true, + Deprecated: "please use 'new_news' instead", + }, + }, + + Config: map[string]interface{}{ + "old_news": hcl2shim.UnknownVariableValue, + }, + + Warnings: []string{ + "\"old_news\": [DEPRECATED] please use 'new_news' instead", + }, + }, + "Required sub-resource field": { Schema: map[string]*Schema{ "ingress": &Schema{