mirror of https://github.com/hashicorp/terraform
By observing the sorts of questions people ask in the community, and the ways they ask them, we've inferred that various different people have been confused by Terraform reporting that a value won't be known until apply or that a value is sensitive as part of an error message when that message doesn't actually relate to the known-ness and sensitivity of any value. Quite reasonably, someone who sees Terraform discussing an unfamiliar concept like unknown values can assume that it must be somehow relevant to the problem being discussed, and so in that sense Terraform's current error messages are giving "too much information": information that isn't actually helpful in understanding the problem being described, and in the worst case is a distraction from understanding the problem being described. With that in mind then, here we introduce an explicit annotation on diagnostic objects that are directly talking about unknown values or sensitive values, and then the diagnostic renderer will react to that to avoid using the terminology "known only after apply" or "sensitive" in the generated diagnostic annotations unless we're rendering a message that is explicitly related to one of those topics. This ends up being a bit of a cross-cutting concern because the code that generates these diagnostics and the code that renders them are in separate packages and are not directly aware of each other. With that in mind, the logic for actually deciding for a particular diagnostic whether it's flagged in one of these special ways lives inside the tfdiags package as an intermediation point, which both the diagnostic generator (in the core package) and the diagnostic renderer can both depend on.pull/31321/head
parent
31aee9650e
commit
90ea7b0bc5
@ -0,0 +1,26 @@
|
||||
{
|
||||
"severity": "error",
|
||||
"summary": "Wrong noises",
|
||||
"detail": "Biological sounds are not allowed",
|
||||
"range": {
|
||||
"filename": "test.tf",
|
||||
"start": {
|
||||
"line": 2,
|
||||
"column": 9,
|
||||
"byte": 42
|
||||
},
|
||||
"end": {
|
||||
"line": 2,
|
||||
"column": 26,
|
||||
"byte": 59
|
||||
}
|
||||
},
|
||||
"snippet": {
|
||||
"context": "resource \"test_resource\" \"test\"",
|
||||
"code": " foo = var.boop[\"hello!\"]",
|
||||
"start_line": 2,
|
||||
"highlight_start_offset": 8,
|
||||
"highlight_end_offset": 25,
|
||||
"values": []
|
||||
}
|
||||
}
|
||||
@ -0,0 +1,26 @@
|
||||
{
|
||||
"severity": "error",
|
||||
"summary": "Wrong noises",
|
||||
"detail": "Biological sounds are not allowed",
|
||||
"range": {
|
||||
"filename": "test.tf",
|
||||
"start": {
|
||||
"line": 2,
|
||||
"column": 9,
|
||||
"byte": 42
|
||||
},
|
||||
"end": {
|
||||
"line": 2,
|
||||
"column": 26,
|
||||
"byte": 59
|
||||
}
|
||||
},
|
||||
"snippet": {
|
||||
"context": "resource \"test_resource\" \"test\"",
|
||||
"code": " foo = var.boop[\"hello!\"]",
|
||||
"start_line": 2,
|
||||
"highlight_start_offset": 8,
|
||||
"highlight_end_offset": 25,
|
||||
"values": []
|
||||
}
|
||||
}
|
||||
@ -0,0 +1,42 @@
|
||||
package terraform
|
||||
|
||||
import (
|
||||
"github.com/hashicorp/terraform/internal/tfdiags"
|
||||
)
|
||||
|
||||
// This file contains some package-local helpers for working with diagnostics.
|
||||
// For the main diagnostics API, see the separate "tfdiags" package.
|
||||
|
||||
// diagnosticCausedByUnknown is an implementation of
|
||||
// tfdiags.DiagnosticExtraBecauseUnknown which we can use in the "Extra" field
|
||||
// of a diagnostic to indicate that the problem was caused by unknown values
|
||||
// being involved in an expression evaluation.
|
||||
//
|
||||
// When using this, set the Extra to diagnosticCausedByUnknown(true) and also
|
||||
// populate the EvalContext and Expression fields of the diagnostic so that
|
||||
// the diagnostic renderer can use all of that information together to assist
|
||||
// the user in understanding what was unknown.
|
||||
type diagnosticCausedByUnknown bool
|
||||
|
||||
var _ tfdiags.DiagnosticExtraBecauseUnknown = diagnosticCausedByUnknown(true)
|
||||
|
||||
func (e diagnosticCausedByUnknown) DiagnosticCausedByUnknown() bool {
|
||||
return bool(e)
|
||||
}
|
||||
|
||||
// diagnosticCausedBySensitive is an implementation of
|
||||
// tfdiags.DiagnosticExtraBecauseSensitive which we can use in the "Extra" field
|
||||
// of a diagnostic to indicate that the problem was caused by sensitive values
|
||||
// being involved in an expression evaluation.
|
||||
//
|
||||
// When using this, set the Extra to diagnosticCausedBySensitive(true) and also
|
||||
// populate the EvalContext and Expression fields of the diagnostic so that
|
||||
// the diagnostic renderer can use all of that information together to assist
|
||||
// the user in understanding what was sensitive.
|
||||
type diagnosticCausedBySensitive bool
|
||||
|
||||
var _ tfdiags.DiagnosticExtraBecauseSensitive = diagnosticCausedBySensitive(true)
|
||||
|
||||
func (e diagnosticCausedBySensitive) DiagnosticCausedBySensitive() bool {
|
||||
return bool(e)
|
||||
}
|
||||
Loading…
Reference in new issue