From f88b4fd1f4573d9890cbbb297c9cd30619b97d85 Mon Sep 17 00:00:00 2001 From: Martin Atkins Date: Wed, 26 Sep 2018 11:40:32 -0700 Subject: [PATCH] core: Fix TestContext2Apply_issue7824 This test was incorrectly amended on the first pass to create a configuration snapshot from the step zero configuration, rather than the step one configuration that the save plan is built from. Along with that, it needed various other minor updates to match with details that have shifted: - "id" and "type" attributes must be explicitly declared in schema - template_file.parent has count = 1, which now causes it to get an index and be a list where before it did not. --- terraform/context_apply_test.go | 21 ++++++++++++--------- 1 file changed, 12 insertions(+), 9 deletions(-) diff --git a/terraform/context_apply_test.go b/terraform/context_apply_test.go index c74dddfcd..e30e32ee1 100644 --- a/terraform/context_apply_test.go +++ b/terraform/context_apply_test.go @@ -8658,7 +8658,8 @@ func TestContext2Apply_issue7824(t *testing.T) { } } -// GH-5254 +// This deals with the situation where a splat expression is used referring +// to another resource whose count is non-constant. func TestContext2Apply_issue5254(t *testing.T) { // Create a provider. We use "template" here just to match the repro // we got from the issue itself. @@ -8671,16 +8672,16 @@ func TestContext2Apply_issue5254(t *testing.T) { Attributes: map[string]*configschema.Attribute{ "template": {Type: cty.String, Optional: true}, "__template_requires_new": {Type: cty.Bool, Optional: true}, + "id": {Type: cty.String, Computed: true}, + "type": {Type: cty.String, Computed: true}, }, }, }, } - m, snap := testModuleWithSnapshot(t, "issue-5254/step-0") - // Apply cleanly step 0 ctx := testContext2(t, &ContextOpts{ - Config: m, + Config: testModule(t, "issue-5254/step-0"), ProviderResolver: providers.ResolverFixed( map[string]providers.Factory{ "template": testProviderFuncFixed(p), @@ -8698,9 +8699,11 @@ func TestContext2Apply_issue5254(t *testing.T) { t.Fatalf("err: %s", diags.Err()) } + m, snap := testModuleWithSnapshot(t, "issue-5254/step-1") + // Application success. Now make the modification and store a plan ctx = testContext2(t, &ContextOpts{ - Config: testModule(t, "issue-5254/step-1"), + Config: m, State: state, ProviderResolver: providers.ResolverFixed( map[string]providers.Factory{ @@ -8744,15 +8747,15 @@ template_file.child: type = template_file Dependencies: - template_file.parent.* -template_file.parent: + template_file.parent +template_file.parent.0: ID = foo provider = provider.template template = Hi type = template_file - `) +`) if actual != expected { - t.Fatalf("expected state: \n%s\ngot: \n%s", expected, actual) + t.Fatalf("wrong final state\ngot:\n%s\n\nwant:\n%s", actual, expected) } }