diff --git a/terraform/context_test.go b/terraform/context_test.go index be78ef79b..0c3a0a83e 100644 --- a/terraform/context_test.go +++ b/terraform/context_test.go @@ -777,6 +777,51 @@ func TestContextInput_providerOnly(t *testing.T) { } } +func TestContextInput_providerVars(t *testing.T) { + input := new(MockUIInput) + m := testModule(t, "input-provider-with-vars") + p := testProvider("aws") + p.ApplyFn = testApplyFn + p.DiffFn = testDiffFn + ctx := testContext(t, &ContextOpts{ + Module: m, + Providers: map[string]ResourceProviderFactory{ + "aws": testProviderFuncFixed(p), + }, + Variables: map[string]string{ + "foo": "bar", + }, + UIInput: input, + }) + + input.InputReturnMap = map[string]string{} + + var actual interface{} + p.InputFn = func(i UIInput, c *ResourceConfig) (*ResourceConfig, error) { + return c, nil + } + p.ConfigureFn = func(c *ResourceConfig) error { + actual, _ = c.Get("foo") + return nil + } + + if err := ctx.Input(InputModeStd); err != nil { + t.Fatalf("err: %s", err) + } + + if _, err := ctx.Plan(nil); err != nil { + t.Fatalf("err: %s", err) + } + + if _, err := ctx.Apply(); err != nil { + t.Fatalf("err: %s", err) + } + + if !reflect.DeepEqual(actual, "bar") { + t.Fatalf("bad: %#v", actual) + } +} + func TestContextInput_varOnly(t *testing.T) { input := new(MockUIInput) m := testModule(t, "input-provider-vars") diff --git a/terraform/test-fixtures/input-provider-with-vars/main.tf b/terraform/test-fixtures/input-provider-with-vars/main.tf new file mode 100644 index 000000000..d8f931115 --- /dev/null +++ b/terraform/test-fixtures/input-provider-with-vars/main.tf @@ -0,0 +1,7 @@ +variable "foo" {} + +provider "aws" { + foo = "${var.foo}" +} + +resource "aws_instance" "foo" {}