diff --git a/.changelog/465.txt b/.changelog/465.txt new file mode 100644 index 000000000..5e2118c37 --- /dev/null +++ b/.changelog/465.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{