From d0069f721e0c7c19df67d07126698ca2579cb0dc Mon Sep 17 00:00:00 2001 From: Martin Atkins Date: Thu, 20 Sep 2018 11:12:38 -0700 Subject: [PATCH] core: TestContext2Apply_multiDepose_createBeforeDestroy incorrect logic This test was re-using the same context to run three consecutive plan/apply operations, which is not safe because we will accumulate more planned changes with each change, creating duplicate entries in the diff. Instead, to properly simulate a sequence of consecutive runs of Terraform we must start with a fresh context each time, though still pass forward the previous state which would in the real world be persisted via a state manager between these runs. --- terraform/context_apply_test.go | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/terraform/context_apply_test.go b/terraform/context_apply_test.go index 57b305b14..8bf1e8570 100644 --- a/terraform/context_apply_test.go +++ b/terraform/context_apply_test.go @@ -4761,6 +4761,11 @@ aws_instance.web: (2 deposed) } createdInstanceId = "qux" + ctx = testContext2(t, &ContextOpts{ + Config: m, + ProviderResolver: providers.ResolverFixed(ps), + State: state, + }) if _, diags := ctx.Plan(); diags.HasErrors() { t.Fatalf("plan errors: %s", diags.Err()) } @@ -4784,6 +4789,11 @@ aws_instance.web: (1 deposed) } createdInstanceId = "quux" + ctx = testContext2(t, &ContextOpts{ + Config: m, + ProviderResolver: providers.ResolverFixed(ps), + State: state, + }) if _, diags := ctx.Plan(); diags.HasErrors() { t.Fatalf("plan errors: %s", diags.Err()) }