terraform: fix outputs on destroy
This commit is contained in:
parent
bd0c3b12cb
commit
1c713878b0
|
@ -3839,7 +3839,6 @@ func TestContext2Apply_destroy(t *testing.T) {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/*
|
|
||||||
func TestContext2Apply_destroyOutputs(t *testing.T) {
|
func TestContext2Apply_destroyOutputs(t *testing.T) {
|
||||||
m := testModule(t, "apply-destroy-outputs")
|
m := testModule(t, "apply-destroy-outputs")
|
||||||
h := new(HookRecordApplyOrder)
|
h := new(HookRecordApplyOrder)
|
||||||
|
@ -3880,7 +3879,6 @@ func TestContext2Apply_destroyOutputs(t *testing.T) {
|
||||||
t.Fatalf("bad: %#v", mod)
|
t.Fatalf("bad: %#v", mod)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
*/
|
|
||||||
|
|
||||||
func TestContext2Apply_destroyOrphan(t *testing.T) {
|
func TestContext2Apply_destroyOrphan(t *testing.T) {
|
||||||
m := testModule(t, "apply-error")
|
m := testModule(t, "apply-error")
|
||||||
|
|
|
@ -10,17 +10,20 @@ import (
|
||||||
// for the given name to the current state.
|
// for the given name to the current state.
|
||||||
type EvalWriteOutput struct {
|
type EvalWriteOutput struct {
|
||||||
Name string
|
Name string
|
||||||
Value EvalNode
|
Value *config.RawConfig
|
||||||
}
|
}
|
||||||
|
|
||||||
func (n *EvalWriteOutput) Args() ([]EvalNode, []EvalType) {
|
func (n *EvalWriteOutput) Args() ([]EvalNode, []EvalType) {
|
||||||
return []EvalNode{n.Value}, []EvalType{EvalTypeConfig}
|
return nil, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
// TODO: test
|
// TODO: test
|
||||||
func (n *EvalWriteOutput) Eval(
|
func (n *EvalWriteOutput) Eval(
|
||||||
ctx EvalContext, args []interface{}) (interface{}, error) {
|
ctx EvalContext, args []interface{}) (interface{}, error) {
|
||||||
cfg := args[0].(*ResourceConfig)
|
cfg, err := ctx.Interpolate(n.Value, nil)
|
||||||
|
if err != nil {
|
||||||
|
// Ignore it
|
||||||
|
}
|
||||||
|
|
||||||
state, lock := ctx.State()
|
state, lock := ctx.State()
|
||||||
if state == nil {
|
if state == nil {
|
||||||
|
@ -38,13 +41,17 @@ func (n *EvalWriteOutput) Eval(
|
||||||
}
|
}
|
||||||
|
|
||||||
// Get the value from the config
|
// Get the value from the config
|
||||||
valueRaw, ok := cfg.Get("value")
|
var valueRaw interface{} = config.UnknownVariableValue
|
||||||
|
if cfg != nil {
|
||||||
|
var ok bool
|
||||||
|
valueRaw, ok = cfg.Get("value")
|
||||||
if !ok {
|
if !ok {
|
||||||
valueRaw = ""
|
valueRaw = ""
|
||||||
}
|
}
|
||||||
if cfg.IsComputed("value") {
|
if cfg.IsComputed("value") {
|
||||||
valueRaw = config.UnknownVariableValue
|
valueRaw = config.UnknownVariableValue
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
// If it is a list of values, get the first one
|
// If it is a list of values, get the first one
|
||||||
if list, ok := valueRaw.([]interface{}); ok {
|
if list, ok := valueRaw.([]interface{}); ok {
|
||||||
|
|
|
@ -124,9 +124,13 @@ func (n *GraphNodeConfigOutput) DependentOn() []string {
|
||||||
func (n *GraphNodeConfigOutput) EvalTree() EvalNode {
|
func (n *GraphNodeConfigOutput) EvalTree() EvalNode {
|
||||||
return &EvalOpFilter{
|
return &EvalOpFilter{
|
||||||
Ops: []walkOperation{walkRefresh, walkPlan, walkApply},
|
Ops: []walkOperation{walkRefresh, walkPlan, walkApply},
|
||||||
Node: &EvalWriteOutput{
|
Node: &EvalSequence{
|
||||||
|
Nodes: []EvalNode{
|
||||||
|
&EvalWriteOutput{
|
||||||
Name: n.Output.Name,
|
Name: n.Output.Name,
|
||||||
Value: &EvalInterpolate{Config: n.Output.RawConfig},
|
Value: n.Output.RawConfig,
|
||||||
|
},
|
||||||
|
},
|
||||||
},
|
},
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue