terraform: computed input variables work to modules

This commit is contained in:
Mitchell Hashimoto 2014-09-23 17:05:44 -07:00
parent 68b38b4904
commit e8dfcdbe7b
5 changed files with 58 additions and 0 deletions

View File

@ -889,6 +889,11 @@ func (c *walkContext) genericWalkFn(cb genericWalkFunc) depgraph.WalkFunc {
for k, v := range rc.Config {
wc.Variables[k] = v.(string)
}
for k, _ := range rc.Raw {
if _, ok := wc.Variables[k]; !ok {
wc.Variables[k] = config.UnknownVariableValue
}
}
}
return wc.Walk()

View File

@ -1474,6 +1474,29 @@ func TestContextPlan_moduleInput(t *testing.T) {
}
}
func TestContextPlan_moduleInputComputed(t *testing.T) {
m := testModule(t, "plan-module-input-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(testTerraformPlanModuleInputComputedStr)
if actual != expected {
t.Fatalf("bad:\n%s", actual)
}
}
func TestContextPlan_moduleInputFromVar(t *testing.T) {
m := testModule(t, "plan-module-input-var")
p := testProvider("aws")

View File

@ -528,6 +528,23 @@ STATE:
<no state>
`
const testTerraformPlanModuleInputComputedStr = `
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 testTerraformPlanModuleInputVarStr = `
DIFF:

View File

@ -0,0 +1,5 @@
variable "input" {}
resource "aws_instance" "foo" {
foo = "${var.input}"
}

View File

@ -0,0 +1,8 @@
module "child" {
input = "${aws_instance.bar.foo}"
source = "./child"
}
resource "aws_instance" "bar" {
compute = "foo"
}