diff --git a/terraform/context_test.go b/terraform/context_test.go index 4b27e5017c..9ef8b451d0 100644 --- a/terraform/context_test.go +++ b/terraform/context_test.go @@ -507,6 +507,79 @@ func TestContextApply_outputDiffVars(t *testing.T) { } } +func TestContextApply_Provisioner_ConnInfo(t *testing.T) { + c := testConfig(t, "apply-provisioner-conninfo") + p := testProvider("aws") + pr := testProvisioner() + + p.ApplyFn = func(s *ResourceState, d *ResourceDiff) (*ResourceState, error) { + result, _ := testApplyFn(s, d) + result.ConnInfo = &ResourceConnectionInfo{ + Raw: map[string]interface{}{ + "type": "ssh", + "host": "127.0.0.1", + "port": 22, + }, + } + return result, nil + } + p.DiffFn = testDiffFn + + pr.ApplyFn = func(rs *ResourceState, c *ResourceConfig) (*ResourceState, error) { + conn := rs.ConnInfo.Raw + if conn["type"] != "telnet" { + t.Fatalf("Bad: %#v", conn) + } + if conn["host"] != "127.0.0.1" { + t.Fatalf("Bad: %#v", conn) + } + if conn["port"] != 2222 { + t.Fatalf("Bad: %#v", conn) + } + if conn["user"] != "superuser" { + t.Fatalf("Bad: %#v", conn) + } + if conn["pass"] != "test" { + t.Fatalf("Bad: %#v", conn) + } + return rs, nil + } + + ctx := testContext(t, &ContextOpts{ + Config: c, + Providers: map[string]ResourceProviderFactory{ + "aws": testProviderFuncFixed(p), + }, + Provisioners: map[string]ResourceProvisionerFactory{ + "shell": testProvisionerFuncFixed(pr), + }, + Variables: map[string]string{ + "value": "1", + "pass": "test", + }, + }) + + if _, err := ctx.Plan(nil); err != nil { + t.Fatalf("err: %s", err) + } + + state, err := ctx.Apply() + if err != nil { + t.Fatalf("err: %s", err) + } + + actual := strings.TrimSpace(state.String()) + expected := strings.TrimSpace(testTerraformApplyProvisionerStr) + if actual != expected { + t.Fatalf("bad: \n%s", actual) + } + + // Verify apply was invoked + if !pr.ApplyCalled { + t.Fatalf("provisioner not invoked") + } +} + func TestContextApply_destroy(t *testing.T) { c := testConfig(t, "apply-destroy") h := new(HookRecordApplyOrder) diff --git a/terraform/test-fixtures/apply-provisioner-conninfo/main.tf b/terraform/test-fixtures/apply-provisioner-conninfo/main.tf new file mode 100644 index 0000000000..f0bfe43abf --- /dev/null +++ b/terraform/test-fixtures/apply-provisioner-conninfo/main.tf @@ -0,0 +1,20 @@ +resource "aws_instance" "foo" { + num = "2" + compute = "dynamical" + compute_value = "${var.value}" +} + +resource "aws_instance" "bar" { + connection { + type = "telnet" + } + + provisioner "shell" { + foo = "${aws_instance.foo.dynamical}" + connection { + user = "superuser" + port = 2222 + pass = "${var.pass}" + } + } +}