From 35eb6bd20ea9450fa00117478356d0bb6a69e90e Mon Sep 17 00:00:00 2001 From: Brian Flad Date: Fri, 2 Sep 2022 06:50:53 -0400 Subject: [PATCH 1/2] internal/fwserver: Delay deprecated attribute/block warnings for unknown values Reference: https://github.com/hashicorp/terraform-plugin-sdk/pull/1047 Reference: https://github.com/hashicorp/terraform/issues/31730 This change is made to keep terraform-plugin-sdk and terraform-plugin-framework behaviors for deprecation warning handling in sync. --- .changelog/pending.txt | 3 +++ internal/fwserver/attribute_validation.go | 26 +++++------------- .../fwserver/attribute_validation_test.go | 10 +------ internal/fwserver/block_validation.go | 27 +++++-------------- internal/fwserver/block_validation_test.go | 10 +------ 5 files changed, 19 insertions(+), 57 deletions(-) create mode 100644 .changelog/pending.txt diff --git a/.changelog/pending.txt b/.changelog/pending.txt new file mode 100644 index 000000000..5e2118c37 --- /dev/null +++ b/.changelog/pending.txt @@ -0,0 +1,3 @@ +```release-note:bug +internal/fwserver: Delayed deprecated attribute/block warnings for unknown values, which may be null +``` diff --git a/internal/fwserver/attribute_validation.go b/internal/fwserver/attribute_validation.go index 779017c2f..55808d412 100644 --- a/internal/fwserver/attribute_validation.go +++ b/internal/fwserver/attribute_validation.go @@ -116,25 +116,13 @@ func AttributeValidate(ctx context.Context, a fwschema.Attribute, req tfsdk.Vali AttributeValidateNestedAttributes(ctx, a, req, resp) - if a.GetDeprecationMessage() != "" && attributeConfig != nil { - tfValue, err := attributeConfig.ToTerraformValue(ctx) - if err != nil { - resp.Diagnostics.AddAttributeError( - req.AttributePath, - "Attribute Validation Error", - "Attribute validation cannot convert value. Report this to the provider developer:\n\n"+err.Error(), - ) - - return - } - - if !tfValue.IsNull() { - resp.Diagnostics.AddAttributeWarning( - req.AttributePath, - "Attribute Deprecated", - a.GetDeprecationMessage(), - ) - } + // Show deprecation warnings only for known values. + if a.GetDeprecationMessage() != "" && !attributeConfig.IsNull() && !attributeConfig.IsUnknown() { + resp.Diagnostics.AddAttributeWarning( + req.AttributePath, + "Attribute Deprecated", + a.GetDeprecationMessage(), + ) } } diff --git a/internal/fwserver/attribute_validation_test.go b/internal/fwserver/attribute_validation_test.go index bc33e6565..4a966cd3c 100644 --- a/internal/fwserver/attribute_validation_test.go +++ b/internal/fwserver/attribute_validation_test.go @@ -488,15 +488,7 @@ func TestAttributeValidate(t *testing.T) { }, }, }, - resp: tfsdk.ValidateAttributeResponse{ - Diagnostics: diag.Diagnostics{ - diag.NewAttributeWarningDiagnostic( - path.Root("test"), - "Attribute Deprecated", - "Use something else instead.", - ), - }, - }, + resp: tfsdk.ValidateAttributeResponse{}, }, "warnings": { req: tfsdk.ValidateAttributeRequest{ diff --git a/internal/fwserver/block_validation.go b/internal/fwserver/block_validation.go index 1f6b77d20..17e2b85af 100644 --- a/internal/fwserver/block_validation.go +++ b/internal/fwserver/block_validation.go @@ -195,26 +195,13 @@ func BlockValidate(ctx context.Context, b fwschema.Block, req tfsdk.ValidateAttr return } - if b.GetDeprecationMessage() != "" && attributeConfig != nil { - tfValue, err := attributeConfig.ToTerraformValue(ctx) - - if err != nil { - resp.Diagnostics.AddAttributeError( - req.AttributePath, - "Block Validation Error", - "Block validation cannot convert value. Report this to the provider developer:\n\n"+err.Error(), - ) - - return - } - - if !tfValue.IsNull() { - resp.Diagnostics.AddAttributeWarning( - req.AttributePath, - "Block Deprecated", - b.GetDeprecationMessage(), - ) - } + // Show deprecation warning only on known values. + if b.GetDeprecationMessage() != "" && !attributeConfig.IsNull() && !attributeConfig.IsUnknown() { + resp.Diagnostics.AddAttributeWarning( + req.AttributePath, + "Block Deprecated", + b.GetDeprecationMessage(), + ) } } diff --git a/internal/fwserver/block_validation_test.go b/internal/fwserver/block_validation_test.go index 3daa259ae..e776748eb 100644 --- a/internal/fwserver/block_validation_test.go +++ b/internal/fwserver/block_validation_test.go @@ -178,15 +178,7 @@ func TestBlockValidate(t *testing.T) { }, }, }, - resp: tfsdk.ValidateAttributeResponse{ - Diagnostics: diag.Diagnostics{ - diag.NewAttributeWarningDiagnostic( - path.Root("test"), - "Block Deprecated", - "Use something else instead.", - ), - }, - }, + resp: tfsdk.ValidateAttributeResponse{}, }, "warnings": { req: tfsdk.ValidateAttributeRequest{ From 66cdf2c12af80bc11db2155acc8a4293cc207ffe Mon Sep 17 00:00:00 2001 From: Brian Flad Date: Fri, 2 Sep 2022 08:08:41 -0400 Subject: [PATCH 2/2] Update CHANGELOG for #465 --- .changelog/{pending.txt => 465.txt} | 0 1 file changed, 0 insertions(+), 0 deletions(-) rename .changelog/{pending.txt => 465.txt} (100%) diff --git a/.changelog/pending.txt b/.changelog/465.txt similarity index 100% rename from .changelog/pending.txt rename to .changelog/465.txt