terraform: module w/ computed output works
This commit is contained in:
parent
bfa4e1d7d0
commit
a3b668bf7d
|
@ -473,8 +473,8 @@ func (c *walkContext) Walk() error {
|
|||
if m == nil {
|
||||
return nil
|
||||
}
|
||||
config := m.Config()
|
||||
if len(config.Outputs) == 0 {
|
||||
conf := m.Config()
|
||||
if len(conf.Outputs) == 0 {
|
||||
return nil
|
||||
}
|
||||
|
||||
|
@ -490,11 +490,18 @@ func (c *walkContext) Walk() error {
|
|||
}
|
||||
|
||||
outputs := make(map[string]string)
|
||||
for _, o := range config.Outputs {
|
||||
for _, o := range conf.Outputs {
|
||||
if err := c.computeVars(o.RawConfig); err != nil {
|
||||
return err
|
||||
}
|
||||
vraw := o.RawConfig.Config()["value"]
|
||||
if vraw == nil {
|
||||
// This likely means that the result of the output is
|
||||
// a computed variable.
|
||||
if o.RawConfig.Raw["value"] != nil {
|
||||
vraw = config.UnknownVariableValue
|
||||
}
|
||||
}
|
||||
if vraw != nil {
|
||||
outputs[o.Name] = vraw.(string)
|
||||
}
|
||||
|
|
|
@ -1513,6 +1513,29 @@ func TestContextPlan_moduleVar(t *testing.T) {
|
|||
}
|
||||
}
|
||||
|
||||
func TestContextPlan_moduleVarComputed(t *testing.T) {
|
||||
m := testModule(t, "plan-module-var-computed")
|
||||
p := testProvider("aws")
|
||||
p.DiffFn = testDiffFn
|
||||
ctx := testContext(t, &ContextOpts{
|
||||
Module: m,
|
||||
Providers: map[string]ResourceProviderFactory{
|
||||
"aws": testProviderFuncFixed(p),
|
||||
},
|
||||
})
|
||||
|
||||
plan, err := ctx.Plan(nil)
|
||||
if err != nil {
|
||||
t.Fatalf("err: %s", err)
|
||||
}
|
||||
|
||||
actual := strings.TrimSpace(plan.String())
|
||||
expected := strings.TrimSpace(testTerraformPlanModuleVarComputedStr)
|
||||
if actual != expected {
|
||||
t.Fatalf("bad:\n%s", actual)
|
||||
}
|
||||
}
|
||||
|
||||
func TestContextPlan_nil(t *testing.T) {
|
||||
m := testModule(t, "plan-nil")
|
||||
p := testProvider("aws")
|
||||
|
|
|
@ -545,6 +545,23 @@ STATE:
|
|||
<no state>
|
||||
`
|
||||
|
||||
const testTerraformPlanModuleVarComputedStr = `
|
||||
DIFF:
|
||||
|
||||
CREATE: aws_instance.bar
|
||||
foo: "" => "<computed>"
|
||||
type: "" => "aws_instance"
|
||||
|
||||
module.child:
|
||||
CREATE: aws_instance.foo
|
||||
foo: "" => "<computed>"
|
||||
type: "" => "aws_instance"
|
||||
|
||||
STATE:
|
||||
|
||||
<no state>
|
||||
`
|
||||
|
||||
const testTerraformPlanOrphanStr = `
|
||||
DIFF:
|
||||
|
||||
|
|
|
@ -0,0 +1,7 @@
|
|||
resource "aws_instance" "foo" {
|
||||
compute = "foo"
|
||||
}
|
||||
|
||||
output "num" {
|
||||
value = "${aws_instance.foo.foo}"
|
||||
}
|
|
@ -0,0 +1,7 @@
|
|||
module "child" {
|
||||
source = "./child"
|
||||
}
|
||||
|
||||
resource "aws_instance" "bar" {
|
||||
foo = "${module.child.num}"
|
||||
}
|
Loading…
Reference in New Issue