terraform: refresh ignores variables with no values [GH-478]

This commit is contained in:
Mitchell Hashimoto 2014-10-20 23:08:17 -07:00
parent c84af741de
commit 22f09b487b
4 changed files with 46 additions and 7 deletions

View File

@ -1611,18 +1611,24 @@ func (c *walkContext) computeResourceVariable(
// Get the relevant module
module := c.Context.state.ModuleByPath(c.Path)
r, ok := module.Resources[id]
if !ok {
if v.Multi && v.Index == 0 {
var r *ResourceState
if module != nil {
var ok bool
r, ok = module.Resources[id]
if !ok && v.Multi && v.Index == 0 {
r, ok = module.Resources[v.ResourceId()]
}
if !ok {
r = nil
}
}
if r == nil {
return "", fmt.Errorf(
"Resource '%s' not found for variable '%s'",
id,
v.FullKey())
}
}
if r.Primary == nil {
goto MISSING

View File

@ -4110,6 +4110,22 @@ func TestContextRefresh_modules(t *testing.T) {
}
}
func TestContextRefresh_moduleInputComputedOutput(t *testing.T) {
m := testModule(t, "refresh-module-input-computed-output")
p := testProvider("aws")
p.DiffFn = testDiffFn
ctx := testContext(t, &ContextOpts{
Module: m,
Providers: map[string]ResourceProviderFactory{
"aws": testProviderFuncFixed(p),
},
})
if _, err := ctx.Refresh(); err != nil {
t.Fatalf("err: %s", err)
}
}
// GH-70
func TestContextRefresh_noState(t *testing.T) {
p := testProvider("aws")

View File

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

View File

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