terraform: output nodes reference `depends_on` values
This commit is contained in:
parent
10426ba619
commit
70a41c5e15
|
@ -2243,6 +2243,77 @@ func TestContext2Apply_nilDiff(t *testing.T) {
|
|||
}
|
||||
}
|
||||
|
||||
func TestContext2Apply_outputDependsOn(t *testing.T) {
|
||||
m := testModule(t, "apply-output-depends-on")
|
||||
p := testProvider("aws")
|
||||
p.DiffFn = testDiffFn
|
||||
|
||||
{
|
||||
// Create a custom apply function that sleeps a bit (to allow parallel
|
||||
// graph execution) and then returns an error to force a partial state
|
||||
// return. We then verify the output is NOT there.
|
||||
p.ApplyFn = func(
|
||||
info *InstanceInfo,
|
||||
is *InstanceState,
|
||||
id *InstanceDiff) (*InstanceState, error) {
|
||||
|
||||
// Sleep to allow parallel execution
|
||||
time.Sleep(50 * time.Millisecond)
|
||||
|
||||
// Return error to force partial state
|
||||
return nil, fmt.Errorf("abcd")
|
||||
}
|
||||
|
||||
ctx := testContext2(t, &ContextOpts{
|
||||
Module: m,
|
||||
Providers: map[string]ResourceProviderFactory{
|
||||
"aws": testProviderFuncFixed(p),
|
||||
},
|
||||
})
|
||||
|
||||
if _, err := ctx.Plan(); err != nil {
|
||||
t.Fatalf("err: %s", err)
|
||||
}
|
||||
|
||||
state, err := ctx.Apply()
|
||||
if err == nil || !strings.Contains(err.Error(), "abcd") {
|
||||
t.Fatalf("err: %s", err)
|
||||
}
|
||||
|
||||
checkStateString(t, state, `<no state>`)
|
||||
}
|
||||
|
||||
{
|
||||
// Create the standard apply function and verify we get the output
|
||||
p.ApplyFn = testApplyFn
|
||||
|
||||
ctx := testContext2(t, &ContextOpts{
|
||||
Module: m,
|
||||
Providers: map[string]ResourceProviderFactory{
|
||||
"aws": testProviderFuncFixed(p),
|
||||
},
|
||||
})
|
||||
|
||||
if _, err := ctx.Plan(); err != nil {
|
||||
t.Fatalf("err: %s", err)
|
||||
}
|
||||
|
||||
state, err := ctx.Apply()
|
||||
if err != nil {
|
||||
t.Fatalf("err: %s", err)
|
||||
}
|
||||
|
||||
checkStateString(t, state, `
|
||||
aws_instance.foo:
|
||||
ID = foo
|
||||
|
||||
Outputs:
|
||||
|
||||
value = result
|
||||
`)
|
||||
}
|
||||
}
|
||||
|
||||
func TestContext2Apply_outputOrphan(t *testing.T) {
|
||||
m := testModule(t, "apply-output-orphan")
|
||||
p := testProvider("aws")
|
||||
|
|
|
@ -37,6 +37,7 @@ func (n *NodeApplyableOutput) ReferenceableName() []string {
|
|||
// GraphNodeReferencer
|
||||
func (n *NodeApplyableOutput) References() []string {
|
||||
var result []string
|
||||
result = append(result, n.Config.DependsOn...)
|
||||
result = append(result, ReferencesFromConfig(n.Config.RawConfig)...)
|
||||
for _, v := range result {
|
||||
split := strings.Split(v, "/")
|
||||
|
|
|
@ -0,0 +1,7 @@
|
|||
resource "aws_instance" "foo" {}
|
||||
|
||||
output "value" {
|
||||
value = "result"
|
||||
|
||||
depends_on = ["aws_instance.foo"]
|
||||
}
|
Loading…
Reference in New Issue