Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

internal/fwserver: Delay deprecated attribute/block warnings for unknown values #465

Merged
merged 2 commits into from Sep 6, 2022
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
3 changes: 3 additions & 0 deletions .changelog/pending.txt
@@ -0,0 +1,3 @@
```release-note:bug
internal/fwserver: Delayed deprecated attribute/block warnings for unknown values, which may be null
```
26 changes: 7 additions & 19 deletions internal/fwserver/attribute_validation.go
Expand Up @@ -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(),
)
}
}

Expand Down
10 changes: 1 addition & 9 deletions internal/fwserver/attribute_validation_test.go
Expand Up @@ -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{
Expand Down
27 changes: 7 additions & 20 deletions internal/fwserver/block_validation.go
Expand Up @@ -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(),
)
}
}

Expand Down
10 changes: 1 addition & 9 deletions internal/fwserver/block_validation_test.go
Expand Up @@ -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{
Expand Down