terraform: unknown value for variables not set

Fixes #12836

Realistically, these should be caught during validation anyways. In this
case, this was causing 12386 because refresh with a data source will
attempt to use module variables. I don't see any clear logic to prune
those module variables or not add them so its easier to return unknown
to cause the data to be computed and not run.
This commit is contained in:
Mitchell Hashimoto 2017-03-17 15:29:10 -07:00
parent 14e07b136e
commit e8b3062629
No known key found for this signature in database
GPG Key ID: 744E147AA52F5B0A
4 changed files with 41 additions and 1 deletions

View File

@ -60,6 +60,32 @@ func TestContext2Refresh(t *testing.T) {
}
}
func TestContext2Refresh_dataComputedModuleVar(t *testing.T) {
p := testProvider("aws")
m := testModule(t, "refresh-data-module-var")
ctx := testContext2(t, &ContextOpts{
Module: m,
Providers: map[string]ResourceProviderFactory{
"aws": testProviderFuncFixed(p),
},
})
p.RefreshFn = nil
p.RefreshReturn = &InstanceState{
ID: "foo",
}
s, err := ctx.Refresh()
if err != nil {
t.Fatalf("err: %s", err)
}
checkStateString(t, s, `
<no state>
module.child:
<no state>`)
}
func TestContext2Refresh_targeted(t *testing.T) {
p := testProvider("aws")
m := testModule(t, "refresh-targeted")

View File

@ -262,7 +262,7 @@ func (i *Interpolater) valueResourceVar(
// If it truly is missing, we'll catch it on a later walk.
// This applies only to graph nodes that interpolate during the
// config walk, e.g. providers.
if i.Operation == walkInput {
if i.Operation == walkInput || i.Operation == walkRefresh {
result[n] = unknownVariable()
return nil
}

View File

@ -0,0 +1,6 @@
variable "key" {}
data "aws_data_source" "foo" {
id = "${var.key}"
}

View File

@ -0,0 +1,8 @@
resource "aws_instance" "A" {
foo = "bar"
}
module "child" {
source = "child"
key = "${aws_instance.A.id}"
}