From b56ee1a1699c5853cb747d6bd5ba2bbf6dc0f8f0 Mon Sep 17 00:00:00 2001 From: Mitchell Hashimoto Date: Fri, 20 Jan 2017 20:05:28 -0800 Subject: [PATCH] terraform: test on_failure with non-destroy provisioners --- terraform/context_apply_test.go | 45 +++++++++++++++++++ .../apply-provisioner-fail-continue/main.tf | 7 +++ 2 files changed, 52 insertions(+) create mode 100644 terraform/test-fixtures/apply-provisioner-fail-continue/main.tf diff --git a/terraform/context_apply_test.go b/terraform/context_apply_test.go index a9b1bc101..0a483fe61 100644 --- a/terraform/context_apply_test.go +++ b/terraform/context_apply_test.go @@ -3998,6 +3998,51 @@ aws_instance.web: `) } +// Verify that a normal provisioner with on_failure "continue" set won't +// taint the resource and continues executing. +func TestContext2Apply_provisionerFailContinue(t *testing.T) { + m := testModule(t, "apply-provisioner-fail-continue") + p := testProvider("aws") + pr := testProvisioner() + p.ApplyFn = testApplyFn + p.DiffFn = testDiffFn + + pr.ApplyFn = func(rs *InstanceState, c *ResourceConfig) error { + return fmt.Errorf("provisioner error") + } + + ctx := testContext2(t, &ContextOpts{ + Module: m, + Providers: map[string]ResourceProviderFactory{ + "aws": testProviderFuncFixed(p), + }, + Provisioners: map[string]ResourceProvisionerFactory{ + "shell": testProvisionerFuncFixed(pr), + }, + }) + + if _, err := ctx.Plan(); err != nil { + t.Fatalf("err: %s", err) + } + + state, err := ctx.Apply() + if err != nil { + t.Fatalf("err: %s", err) + } + + checkStateString(t, state, ` +aws_instance.foo: + ID = foo + foo = bar + type = aws_instance + `) + + // Verify apply was invoked + if !pr.ApplyCalled { + t.Fatalf("provisioner not invoked") + } +} + func TestContext2Apply_provisionerDestroy(t *testing.T) { m := testModule(t, "apply-provisioner-destroy") p := testProvider("aws") diff --git a/terraform/test-fixtures/apply-provisioner-fail-continue/main.tf b/terraform/test-fixtures/apply-provisioner-fail-continue/main.tf new file mode 100644 index 000000000..39587984e --- /dev/null +++ b/terraform/test-fixtures/apply-provisioner-fail-continue/main.tf @@ -0,0 +1,7 @@ +resource "aws_instance" "foo" { + foo = "bar" + + provisioner "shell" { + on_failure = "continue" + } +}