mirror of
https://github.com/opentofu/opentofu.git
synced 2025-01-19 13:12:58 -06:00
9c87006c34
* checks: filter out check diagnostics during certain plans * wrap diagnostics produced by check blocks in a dedicated check block diagnostic * address comments
74 lines
1.7 KiB
Go
74 lines
1.7 KiB
Go
package tfdiags
|
|
|
|
import (
|
|
"fmt"
|
|
|
|
"github.com/hashicorp/hcl/v2"
|
|
)
|
|
|
|
var _ Diagnostic = CheckBlockDiagnostic{}
|
|
|
|
// CheckBlockDiagnostic is a diagnostic produced by a Terraform config Check block.
|
|
//
|
|
// It only ever returns warnings, and will not be consolidated as part of the
|
|
// Diagnostics.ConsolidateWarnings function.
|
|
type CheckBlockDiagnostic struct {
|
|
diag Diagnostic
|
|
}
|
|
|
|
// AsCheckBlockDiagnostics will wrap every diagnostic in diags in a
|
|
// CheckBlockDiagnostic.
|
|
func AsCheckBlockDiagnostics(diags Diagnostics) Diagnostics {
|
|
if len(diags) == 0 {
|
|
return nil
|
|
}
|
|
|
|
ret := make(Diagnostics, len(diags))
|
|
for i, diag := range diags {
|
|
ret[i] = CheckBlockDiagnostic{diag}
|
|
}
|
|
return ret
|
|
}
|
|
|
|
// AsCheckBlockDiagnostic will wrap a Diagnostic or a hcl.Diagnostic in a
|
|
// CheckBlockDiagnostic.
|
|
func AsCheckBlockDiagnostic(diag interface{}) Diagnostic {
|
|
switch d := diag.(type) {
|
|
case Diagnostic:
|
|
return CheckBlockDiagnostic{d}
|
|
case *hcl.Diagnostic:
|
|
return CheckBlockDiagnostic{hclDiagnostic{d}}
|
|
default:
|
|
panic(fmt.Errorf("can't construct diagnostic from %T", diag))
|
|
}
|
|
}
|
|
|
|
// IsFromCheckBlock returns true if the specified Diagnostic is a
|
|
// CheckBlockDiagnostic.
|
|
func IsFromCheckBlock(diag Diagnostic) bool {
|
|
_, ok := diag.(CheckBlockDiagnostic)
|
|
return ok
|
|
}
|
|
|
|
func (c CheckBlockDiagnostic) Severity() Severity {
|
|
// Regardless of the severity of the underlying diagnostic, check blocks
|
|
// only ever report Warning severity.
|
|
return Warning
|
|
}
|
|
|
|
func (c CheckBlockDiagnostic) Description() Description {
|
|
return c.diag.Description()
|
|
}
|
|
|
|
func (c CheckBlockDiagnostic) Source() Source {
|
|
return c.diag.Source()
|
|
}
|
|
|
|
func (c CheckBlockDiagnostic) FromExpr() *FromExpr {
|
|
return c.diag.FromExpr()
|
|
}
|
|
|
|
func (c CheckBlockDiagnostic) ExtraInfo() interface{} {
|
|
return c.diag.ExtraInfo()
|
|
}
|