diff --git a/terraform/context_refresh_test.go b/terraform/context_refresh_test.go index 7c00cf4f4..b29e63679 100644 --- a/terraform/context_refresh_test.go +++ b/terraform/context_refresh_test.go @@ -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, ` + +module.child: + `) +} + func TestContext2Refresh_targeted(t *testing.T) { p := testProvider("aws") m := testModule(t, "refresh-targeted") diff --git a/terraform/interpolate.go b/terraform/interpolate.go index 7a3270fc9..0c5acaa35 100644 --- a/terraform/interpolate.go +++ b/terraform/interpolate.go @@ -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 } diff --git a/terraform/test-fixtures/refresh-data-module-var/child/main.tf b/terraform/test-fixtures/refresh-data-module-var/child/main.tf new file mode 100644 index 000000000..64d21beda --- /dev/null +++ b/terraform/test-fixtures/refresh-data-module-var/child/main.tf @@ -0,0 +1,6 @@ +variable "key" {} + +data "aws_data_source" "foo" { + id = "${var.key}" +} + diff --git a/terraform/test-fixtures/refresh-data-module-var/main.tf b/terraform/test-fixtures/refresh-data-module-var/main.tf new file mode 100644 index 000000000..06f18b1b5 --- /dev/null +++ b/terraform/test-fixtures/refresh-data-module-var/main.tf @@ -0,0 +1,8 @@ +resource "aws_instance" "A" { + foo = "bar" +} + +module "child" { + source = "child" + key = "${aws_instance.A.id}" +}