You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
When creating tfprotov5.Diagnostic or tfprotov6.Diagnostic, it is possible to omit the diagnostic Severity field. While the severity has a fallback "invalid" level and Terraform will generally stop execution, it can cause issues with terraform-exec not reporting the diagnostic in its error return for commands. Provider acceptance testing via terraform-plugin-testing using terraform-exec means tests can have undefined behavior to real usage, such as potentially passing tests unexpectedly and not alerting provider developers to a real issue.
Attempted solutions
If there was something to be done here, it would likely be creating static analysis tooling to catch the issue.
Proposal
Rather than a more drastic change in this Go module of making it not possible to create diagnostics without a severity, we can consider augmenting the toproto implementations to raise their own error diagnostic if they detect response diagnostics missing a severity.
Potentially something like:
funcDiagnostics(in []*tfprotov5.Diagnostic) ([]*tfplugin5.Diagnostic, error) {
diagnostics:=make([]*tfplugin5.Diagnostic, 0, len(in))
for_, diag:=rangein {
ifdiag==nil {
diagnostics=append(diagnostics, nil)
continue
}
d, err:=Diagnostic(diag)
iferr!=nil {
returndiagnostics, err
}
diagnostics=append(diagnostics, d)
ifdiag.Severity==tfprotov5.DiagnosticSeverityInvalid { // new logicdiagnostics=append(
diagnostics,
tfplugin5.Diagnostic{
Severity: tfplugin5.Diagnostic_ERROR,
Summary: "Diagnostic Missing Severity",
Detail: "A response diagnostic was missing a severity level. "+"This can cause consumers of Terraform command outputs to miss the diagnostic, which can cause unexpected behavior. "+"Please report this issue to the provider developers.\n\n"+"Summary for Diagnostic Missing Severity: "+diag.Summary,
},
)
}
}
returndiagnostics, nil
}
terraform-plugin-go version
Use cases
When creating
tfprotov5.Diagnostic
ortfprotov6.Diagnostic
, it is possible to omit the diagnosticSeverity
field. While the severity has a fallback "invalid" level and Terraform will generally stop execution, it can cause issues withterraform-exec
not reporting the diagnostic in itserror
return for commands. Provider acceptance testing via terraform-plugin-testing usingterraform-exec
means tests can have undefined behavior to real usage, such as potentially passing tests unexpectedly and not alerting provider developers to a real issue.Attempted solutions
If there was something to be done here, it would likely be creating static analysis tooling to catch the issue.
Proposal
Rather than a more drastic change in this Go module of making it not possible to create diagnostics without a severity, we can consider augmenting the
toproto
implementations to raise their own error diagnostic if they detect response diagnostics missing a severity.Potentially something like:
References
The text was updated successfully, but these errors were encountered: