From f59e89ccb8ebcde812c4cde15d8b4821b5e2982f Mon Sep 17 00:00:00 2001 From: Mitchell Hashimoto Date: Sun, 12 Oct 2014 09:41:27 -0700 Subject: [PATCH] terraform: add count tainted apply test --- terraform/context_test.go | 48 +++++++++++++++++++ terraform/terraform_test.go | 4 ++ .../test-fixtures/apply-count-tainted/main.tf | 4 ++ 3 files changed, 56 insertions(+) create mode 100644 terraform/test-fixtures/apply-count-tainted/main.tf diff --git a/terraform/context_test.go b/terraform/context_test.go index 7aba50395..dfe5cf0a9 100644 --- a/terraform/context_test.go +++ b/terraform/context_test.go @@ -1108,6 +1108,54 @@ func TestContextApply_countDecreaseToOne(t *testing.T) { } } +func TestContextApply_countTainted(t *testing.T) { + m := testModule(t, "apply-count-tainted") + p := testProvider("aws") + p.DiffFn = testDiffFn + s := &State{ + Modules: []*ModuleState{ + &ModuleState{ + Path: rootModulePath, + Resources: map[string]*ResourceState{ + "aws_instance.foo.0": &ResourceState{ + Type: "aws_instance", + Tainted: []*InstanceState{ + &InstanceState{ + ID: "bar", + Attributes: map[string]string{ + "foo": "foo", + "type": "aws_instance", + }, + }, + }, + }, + }, + }, + }, + } + ctx := testContext(t, &ContextOpts{ + Module: m, + Providers: map[string]ResourceProviderFactory{ + "aws": testProviderFuncFixed(p), + }, + State: s, + }) + + 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(testTerraformApplyCountTaintedStr) + if actual != expected { + t.Fatalf("bad: \n%s", actual) + } +} func TestContextApply_module(t *testing.T) { m := testModule(t, "apply-module") p := testProvider("aws") diff --git a/terraform/terraform_test.go b/terraform/terraform_test.go index 98c078a73..51e1324cf 100644 --- a/terraform/terraform_test.go +++ b/terraform/terraform_test.go @@ -224,6 +224,10 @@ aws_instance.foo.0: type = aws_instance ` +const testTerraformApplyCountTaintedStr = ` + +` + const testTerraformApplyMinimalStr = ` aws_instance.bar: ID = foo diff --git a/terraform/test-fixtures/apply-count-tainted/main.tf b/terraform/test-fixtures/apply-count-tainted/main.tf new file mode 100644 index 000000000..ba35b0343 --- /dev/null +++ b/terraform/test-fixtures/apply-count-tainted/main.tf @@ -0,0 +1,4 @@ +resource "aws_instance" "foo" { + count = 2 + foo = "foo" +}