mirror of
https://github.com/opentofu/opentofu.git
synced 2024-12-30 10:47:14 -06:00
a103c65140
Evaluate precondition and postcondition blocks in refresh-only mode, but report any failures as warnings instead of errors. This ensures that any deviation from the contract defined by condition blocks is reported as early as possible, without preventing the completion of a state refresh operation. Prior to this commit, Terraform evaluated output preconditions and data source pre/postconditions as normal in refresh-only mode, while managed resource pre/postconditions were not evaluated at all. This omission could lead to confusing partial condition errors, or failure to detect undesired changes which would otherwise cause resources to become invalid. Reporting the failures as errors also meant that changes retrieved during refresh could cause the refresh operation to fail. This is also undesirable, as the primary purpose of the operation is to update local state. Precondition/postcondition checks are still valuable here, but should be informative rather than blocking.
58 lines
1.1 KiB
Go
58 lines
1.1 KiB
Go
package tfdiags
|
|
|
|
import (
|
|
"fmt"
|
|
|
|
"github.com/hashicorp/hcl/v2"
|
|
)
|
|
|
|
type Diagnostic interface {
|
|
Severity() Severity
|
|
Description() Description
|
|
Source() Source
|
|
|
|
// FromExpr returns the expression-related context for the diagnostic, if
|
|
// available. Returns nil if the diagnostic is not related to an
|
|
// expression evaluation.
|
|
FromExpr() *FromExpr
|
|
}
|
|
|
|
type Severity rune
|
|
|
|
//go:generate go run golang.org/x/tools/cmd/stringer -type=Severity
|
|
|
|
const (
|
|
Error Severity = 'E'
|
|
Warning Severity = 'W'
|
|
)
|
|
|
|
// ToHCL converts a Severity to the equivalent HCL diagnostic severity.
|
|
func (s Severity) ToHCL() hcl.DiagnosticSeverity {
|
|
switch s {
|
|
case Warning:
|
|
return hcl.DiagWarning
|
|
case Error:
|
|
return hcl.DiagError
|
|
default:
|
|
// The above should always be exhaustive for all of the valid
|
|
// Severity values in this package.
|
|
panic(fmt.Sprintf("unknown diagnostic severity %s", s))
|
|
}
|
|
}
|
|
|
|
type Description struct {
|
|
Address string
|
|
Summary string
|
|
Detail string
|
|
}
|
|
|
|
type Source struct {
|
|
Subject *SourceRange
|
|
Context *SourceRange
|
|
}
|
|
|
|
type FromExpr struct {
|
|
Expression hcl.Expression
|
|
EvalContext *hcl.EvalContext
|
|
}
|