Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #30752 from hashicorp/alisdair/condition-blocks-re…
…sults-in-plan core: Store condition block results in plan
- Loading branch information
Showing
32 changed files
with
1,682 additions
and
309 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,86 @@ | ||
package addrs | ||
|
||
import "fmt" | ||
|
||
// Check is the address of a check rule within a checkable object. | ||
// | ||
// This represents the check rule globally within a configuration, and is used | ||
// during graph evaluation to identify a condition result object to update with | ||
// the result of check rule evaluation. | ||
// | ||
// The check address is not distinct from resource traversals, and check rule | ||
// values are not intended to be available to the language, so the address is | ||
// not Referenceable. | ||
// | ||
// Note also that the check address is only relevant within the scope of a run, | ||
// as reordering check blocks between runs will result in their addresses | ||
// changing. | ||
type Check struct { | ||
Container Checkable | ||
Type CheckType | ||
Index int | ||
} | ||
|
||
func (c Check) String() string { | ||
container := c.Container.String() | ||
switch c.Type { | ||
case ResourcePrecondition: | ||
return fmt.Sprintf("%s.preconditions[%d]", container, c.Index) | ||
case ResourcePostcondition: | ||
return fmt.Sprintf("%s.postconditions[%d]", container, c.Index) | ||
case OutputPrecondition: | ||
return fmt.Sprintf("%s.preconditions[%d]", container, c.Index) | ||
default: | ||
// This should not happen | ||
return fmt.Sprintf("%s.conditions[%d]", container, c.Index) | ||
} | ||
} | ||
|
||
// Checkable is an interface implemented by all address types that can contain | ||
// condition blocks. | ||
type Checkable interface { | ||
checkableSigil() | ||
|
||
// Check returns the address of an individual check rule of a specified | ||
// type and index within this checkable container. | ||
Check(CheckType, int) Check | ||
String() string | ||
} | ||
|
||
var ( | ||
_ Checkable = AbsResourceInstance{} | ||
_ Checkable = AbsOutputValue{} | ||
) | ||
|
||
type checkable struct { | ||
} | ||
|
||
func (c checkable) checkableSigil() { | ||
} | ||
|
||
// CheckType describes the category of check. | ||
//go:generate go run golang.org/x/tools/cmd/stringer -type=CheckType check.go | ||
type CheckType int | ||
|
||
const ( | ||
InvalidCondition CheckType = 0 | ||
ResourcePrecondition CheckType = 1 | ||
ResourcePostcondition CheckType = 2 | ||
OutputPrecondition CheckType = 3 | ||
) | ||
|
||
// Description returns a human-readable description of the check type. This is | ||
// presented in the user interface through a diagnostic summary. | ||
func (c CheckType) Description() string { | ||
switch c { | ||
case ResourcePrecondition: | ||
return "Resource precondition" | ||
case ResourcePostcondition: | ||
return "Resource postcondition" | ||
case OutputPrecondition: | ||
return "Module output value precondition" | ||
default: | ||
// This should not happen | ||
return "Condition" | ||
} | ||
} |
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
package jsonplan | ||
|
||
// conditionResult is the representation of an evaluated condition block. | ||
type conditionResult struct { | ||
// checkAddress is the globally-unique address of the condition block. This | ||
// is intentionally unexported as it is an implementation detail. | ||
checkAddress string | ||
|
||
// Address is the absolute address of the condition's containing object. | ||
Address string `json:"address,omitempty"` | ||
|
||
// Type is the condition block type, and is one of ResourcePrecondition, | ||
// ResourcePostcondition, or OutputPrecondition. | ||
Type string `json:"condition_type,omitempty"` | ||
|
||
// Result is true if the condition succeeds, and false if it fails or is | ||
// known only at apply time. | ||
Result bool `json:"result"` | ||
|
||
// Unknown is true if the condition can only be evaluated at apply time. | ||
Unknown bool `json:"unknown"` | ||
|
||
// ErrorMessage is the custom error for a failing condition. It is only | ||
// present if the condition fails. | ||
ErrorMessage string `json:"error_message,omitempty"` | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.