From 68b38b4904cc5f0e5fc7ed6203aca5bd6e466dad Mon Sep 17 00:00:00 2001 From: Mitchell Hashimoto Date: Tue, 23 Sep 2014 16:55:19 -0700 Subject: [PATCH] terraform: test case for cascading input variables (variable to variable) --- terraform/context_test.go | 25 +++++++++++++++++++ terraform/terraform_test.go | 17 +++++++++++++ .../plan-module-input-var/child/main.tf | 5 ++++ .../plan-module-input-var/main.tf | 10 ++++++++ 4 files changed, 57 insertions(+) create mode 100644 terraform/test-fixtures/plan-module-input-var/child/main.tf create mode 100644 terraform/test-fixtures/plan-module-input-var/main.tf diff --git a/terraform/context_test.go b/terraform/context_test.go index c5c70d114..6ee02a3b9 100644 --- a/terraform/context_test.go +++ b/terraform/context_test.go @@ -1474,6 +1474,31 @@ func TestContextPlan_moduleInput(t *testing.T) { } } +func TestContextPlan_moduleInputFromVar(t *testing.T) { + m := testModule(t, "plan-module-input-var") + p := testProvider("aws") + p.DiffFn = testDiffFn + ctx := testContext(t, &ContextOpts{ + Module: m, + Providers: map[string]ResourceProviderFactory{ + "aws": testProviderFuncFixed(p), + }, + Variables: map[string]string{ + "foo": "52", + }, + }) + + plan, err := ctx.Plan(nil) + if err != nil { + t.Fatalf("err: %s", err) + } + + actual := strings.TrimSpace(plan.String()) + expected := strings.TrimSpace(testTerraformPlanModuleInputVarStr) + if actual != expected { + t.Fatalf("bad:\n%s", actual) + } +} func TestContextPlan_moduleOrphans(t *testing.T) { m := testModule(t, "plan-modules-remove") p := testProvider("aws") diff --git a/terraform/terraform_test.go b/terraform/terraform_test.go index c37700569..3914e478f 100644 --- a/terraform/terraform_test.go +++ b/terraform/terraform_test.go @@ -528,6 +528,23 @@ STATE: ` +const testTerraformPlanModuleInputVarStr = ` +DIFF: + +CREATE: aws_instance.bar + foo: "" => "2" + type: "" => "aws_instance" + +module.child: + CREATE: aws_instance.foo + foo: "" => "52" + type: "" => "aws_instance" + +STATE: + + +` + const testTerraformPlanModuleOrphansStr = ` DIFF: diff --git a/terraform/test-fixtures/plan-module-input-var/child/main.tf b/terraform/test-fixtures/plan-module-input-var/child/main.tf new file mode 100644 index 000000000..c1a00c5a3 --- /dev/null +++ b/terraform/test-fixtures/plan-module-input-var/child/main.tf @@ -0,0 +1,5 @@ +variable "input" {} + +resource "aws_instance" "foo" { + foo = "${var.input}" +} diff --git a/terraform/test-fixtures/plan-module-input-var/main.tf b/terraform/test-fixtures/plan-module-input-var/main.tf new file mode 100644 index 000000000..3fba315ee --- /dev/null +++ b/terraform/test-fixtures/plan-module-input-var/main.tf @@ -0,0 +1,10 @@ +variable "foo" {} + +module "child" { + input = "${var.foo}" + source = "./child" +} + +resource "aws_instance" "bar" { + foo = "2" +}