mirror of https://github.com/hashicorp/terraform
Add support for unknown/computed values in the structured renderer (#32378)
* prep for processing the structured run output * undo unwanted change to a json key * Add skeleton functions and API for refactored renderer * goimports * Fix documentation of the RenderOpts struct * Add rendering functionality for primitives to the structured renderer * add test case for override * Add support for parsing and rendering sensitive values in the renderer * Add support for unknown/computed values in the structured renderer * delete missing unit testspull/32391/head^2
parent
6ab277f6ba
commit
b8b1a8d430
@ -0,0 +1,29 @@
|
||||
package change
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
|
||||
"github.com/hashicorp/terraform/internal/plans"
|
||||
)
|
||||
|
||||
func Computed(before Change) Renderer {
|
||||
return &computedRenderer{
|
||||
before: before,
|
||||
}
|
||||
}
|
||||
|
||||
type computedRenderer struct {
|
||||
NoWarningsRenderer
|
||||
|
||||
before Change
|
||||
}
|
||||
|
||||
func (renderer computedRenderer) Render(change Change, indent int, opts RenderOpts) string {
|
||||
if change.action == plans.Create {
|
||||
return "(known after apply)"
|
||||
}
|
||||
|
||||
// Never render null suffix for children of computed changes.
|
||||
opts.overrideNullSuffix = true
|
||||
return fmt.Sprintf("%s -> (known after apply)", renderer.before.Render(indent, opts))
|
||||
}
|
||||
@ -0,0 +1,41 @@
|
||||
package differ
|
||||
|
||||
import (
|
||||
"github.com/zclconf/go-cty/cty"
|
||||
|
||||
"github.com/hashicorp/terraform/internal/command/jsonformat/change"
|
||||
)
|
||||
|
||||
func (v Value) checkForComputed(ctyType cty.Type) (change.Change, bool) {
|
||||
unknown := v.isUnknown()
|
||||
|
||||
if !unknown {
|
||||
return change.Change{}, false
|
||||
}
|
||||
|
||||
// No matter what we do here, we want to treat the after value as explicit.
|
||||
// This is because it is going to be null in the value, and we don't want
|
||||
// the functions in this package to assume this means it has been deleted.
|
||||
v.AfterExplicit = true
|
||||
|
||||
if v.Before == nil {
|
||||
return v.AsChange(change.Computed(change.Change{})), true
|
||||
}
|
||||
|
||||
// If we get here, then we have a before value. We're going to model a
|
||||
// delete operation and our renderer later can render the overall change
|
||||
// accurately.
|
||||
|
||||
beforeValue := Value{
|
||||
Before: v.Before,
|
||||
BeforeSensitive: v.BeforeSensitive,
|
||||
}
|
||||
return v.AsChange(change.Computed(beforeValue.ComputeChangeForType(ctyType))), true
|
||||
}
|
||||
|
||||
func (v Value) isUnknown() bool {
|
||||
if unknown, ok := v.Unknown.(bool); ok {
|
||||
return unknown
|
||||
}
|
||||
return false
|
||||
}
|
||||
Loading…
Reference in new issue