From 826ccdd12393214ef8e60f9ad9c40e684884a2d0 Mon Sep 17 00:00:00 2001 From: James Bardin Date: Wed, 7 Oct 2020 10:44:41 -0400 Subject: [PATCH 1/9] re-enable test --- backend/local/backend_plan_test.go | 6 ------ 1 file changed, 6 deletions(-) diff --git a/backend/local/backend_plan_test.go b/backend/local/backend_plan_test.go index 2c337870c..f275d20b1 100644 --- a/backend/local/backend_plan_test.go +++ b/backend/local/backend_plan_test.go @@ -478,12 +478,6 @@ Plan: 1 to add, 0 to change, 1 to destroy.` } func TestLocal_planRefreshFalse(t *testing.T) { - // since there is no longer a separate Refresh walk, `-refresh=false - // doesn't do anything. - // FIXME: determine if we need a refresh option for the new plan, or remove - // this test - t.Skip() - b, cleanup := TestLocal(t) defer cleanup() From 8d5e844158ef06eb3993b6d3a28fbaf63fc610b0 Mon Sep 17 00:00:00 2001 From: James Bardin Date: Wed, 7 Oct 2020 10:47:09 -0400 Subject: [PATCH 2/9] no need to loop this test any longer --- terraform/context_apply_test.go | 24 ++++++++---------------- 1 file changed, 8 insertions(+), 16 deletions(-) diff --git a/terraform/context_apply_test.go b/terraform/context_apply_test.go index 640a2041b..f060dc443 100644 --- a/terraform/context_apply_test.go +++ b/terraform/context_apply_test.go @@ -1593,7 +1593,6 @@ func TestContext2Apply_destroyModuleVarProviderConfig(t *testing.T) { } } -// https://github.com/hashicorp/terraform/issues/2892 func TestContext2Apply_destroyCrossProviders(t *testing.T) { m := testModule(t, "apply-destroy-cross-providers") @@ -1629,23 +1628,16 @@ func TestContext2Apply_destroyCrossProviders(t *testing.T) { addrs.NewDefaultProvider("aws"): testProviderFuncFixed(p_aws), } - // Bug only appears from time to time, - // so we run this test multiple times - // to check for the race-condition + ctx := getContextForApply_destroyCrossProviders(t, m, providers) - // FIXME: this test flaps now, so run it more times - for i := 0; i <= 100; i++ { - ctx := getContextForApply_destroyCrossProviders(t, m, providers) + if _, diags := ctx.Plan(); diags.HasErrors() { + logDiagnostics(t, diags) + t.Fatal("plan failed") + } - if _, diags := ctx.Plan(); diags.HasErrors() { - logDiagnostics(t, diags) - t.Fatal("plan failed") - } - - if _, diags := ctx.Apply(); diags.HasErrors() { - logDiagnostics(t, diags) - t.Fatal("apply failed") - } + if _, diags := ctx.Apply(); diags.HasErrors() { + logDiagnostics(t, diags) + t.Fatal("apply failed") } } From ca7b5bc28b7c0bbc0dec45459f8c432ccce790bf Mon Sep 17 00:00:00 2001 From: James Bardin Date: Wed, 7 Oct 2020 10:50:21 -0400 Subject: [PATCH 3/9] dead code --- terraform/eval_diff.go | 20 -------------------- 1 file changed, 20 deletions(-) diff --git a/terraform/eval_diff.go b/terraform/eval_diff.go index 669ff6687..053220f93 100644 --- a/terraform/eval_diff.go +++ b/terraform/eval_diff.go @@ -731,26 +731,6 @@ func processIgnoreChangesIndividual(prior, config cty.Value, ignoreChanges []hcl return ret, nil } -// a group of key-*ResourceAttrDiff pairs from the same flatmapped container -type flatAttrDiff map[string]*ResourceAttrDiff - -// we need to keep all keys if any of them have a diff that's not ignored -func (f flatAttrDiff) keepDiff(ignoreChanges map[string]bool) bool { - for k, v := range f { - ignore := false - for attr := range ignoreChanges { - if strings.HasPrefix(k, attr) { - ignore = true - } - } - - if !v.Empty() && !v.NewComputed && !ignore { - return true - } - } - return false -} - // EvalDiffDestroy is an EvalNode implementation that returns a plain // destroy diff. type EvalDiffDestroy struct { From 0a6853a3f88956d687293fea973e5c0c5af0348f Mon Sep 17 00:00:00 2001 From: James Bardin Date: Thu, 8 Oct 2020 08:56:03 -0400 Subject: [PATCH 4/9] replace testDiffFn and testApplyFn Replace the old mock provider test functions with modern equivalents. There were a lot of inconsistencies in how they were used, so we needed to update a lot of tests to match the correct behavior. --- terraform/context_apply_test.go | 744 +++++++----------- terraform/context_input_test.go | 46 +- terraform/context_plan_test.go | 463 ++++------- terraform/context_refresh_test.go | 1 + terraform/context_test.go | 338 ++------ terraform/provider_mock.go | 138 +--- terraform/terraform_test.go | 30 +- .../main.tf | 6 +- terraform/testdata/apply-unknown/main.tf | 1 - 9 files changed, 590 insertions(+), 1177 deletions(-) diff --git a/terraform/context_apply_test.go b/terraform/context_apply_test.go index f060dc443..4c585b73c 100644 --- a/terraform/context_apply_test.go +++ b/terraform/context_apply_test.go @@ -26,7 +26,6 @@ import ( "github.com/hashicorp/terraform/providers" "github.com/hashicorp/terraform/provisioners" "github.com/hashicorp/terraform/states" - "github.com/hashicorp/terraform/states/statefile" "github.com/hashicorp/terraform/tfdiags" "github.com/zclconf/go-cty/cty" "github.com/zclconf/go-cty/cty/gocty" @@ -231,12 +230,10 @@ func TestContext2Apply_resourceDependsOnModule(t *testing.T) { var mu sync.Mutex var order []string - p.ApplyFn = func( - info *InstanceInfo, - is *InstanceState, - id *InstanceDiff) (*InstanceState, error) { - - if id.Attributes["ami"].New == "child" { + p.ApplyFn = func(req providers.ApplyResourceChangeRequest) (resp providers.ApplyResourceChangeResponse) { + ami := req.PlannedState.GetAttr("ami").AsString() + switch ami { + case "child": // make the child slower than the parent time.Sleep(50 * time.Millisecond) @@ -244,13 +241,13 @@ func TestContext2Apply_resourceDependsOnModule(t *testing.T) { mu.Lock() order = append(order, "child") mu.Unlock() - } else { + case "parent": mu.Lock() order = append(order, "parent") mu.Unlock() } - return testApplyFn(info, is, id) + return testApplyFn(req) } ctx := testContext2(t, &ContextOpts{ @@ -270,6 +267,7 @@ func TestContext2Apply_resourceDependsOnModule(t *testing.T) { } if !reflect.DeepEqual(order, []string{"child", "parent"}) { + fmt.Println("ORDER:", order) t.Fatal("resources applied out of order") } @@ -309,12 +307,9 @@ func TestContext2Apply_resourceDependsOnModuleStateOnly(t *testing.T) { var mu sync.Mutex var order []string - p.ApplyFn = func( - info *InstanceInfo, - is *InstanceState, - id *InstanceDiff) (*InstanceState, error) { - - if is.ID == "parent" { + p.ApplyFn = func(req providers.ApplyResourceChangeRequest) (resp providers.ApplyResourceChangeResponse) { + id := req.PriorState.GetAttr("id") + if id.IsKnown() && id.AsString() == "parent" { // make the dep slower than the parent time.Sleep(50 * time.Millisecond) @@ -327,7 +322,7 @@ func TestContext2Apply_resourceDependsOnModuleStateOnly(t *testing.T) { mu.Unlock() } - return testApplyFn(info, is, id) + return testApplyFn(req) } ctx := testContext2(t, &ContextOpts{ @@ -385,12 +380,9 @@ func TestContext2Apply_resourceDependsOnModuleDestroy(t *testing.T) { // called a child. var called int32 var checked bool - p.ApplyFn = func( - info *InstanceInfo, - is *InstanceState, - id *InstanceDiff) (*InstanceState, error) { - - if is.Attributes["ami"] == "parent" { + p.ApplyFn = func(req providers.ApplyResourceChangeRequest) (resp providers.ApplyResourceChangeResponse) { + ami := req.PriorState.GetAttr("ami").AsString() + if ami == "parent" { checked = true // Sleep to allow parallel execution @@ -398,12 +390,13 @@ func TestContext2Apply_resourceDependsOnModuleDestroy(t *testing.T) { // Verify that called is 0 (dep not called) if atomic.LoadInt32(&called) != 0 { - return nil, fmt.Errorf("module child should not be called") + resp.Diagnostics = resp.Diagnostics.Append(fmt.Errorf("module child should not be called")) + return resp } } atomic.AddInt32(&called, 1) - return testApplyFn(info, is, id) + return testApplyFn(req) } ctx := testContext2(t, &ContextOpts{ @@ -442,12 +435,9 @@ func TestContext2Apply_resourceDependsOnModuleGrandchild(t *testing.T) { // called a child. var called int32 var checked bool - p.ApplyFn = func( - info *InstanceInfo, - is *InstanceState, - id *InstanceDiff) (*InstanceState, error) { - - if id.Attributes["ami"].New == "grandchild" { + p.ApplyFn = func(req providers.ApplyResourceChangeRequest) (resp providers.ApplyResourceChangeResponse) { + planned := req.PlannedState.AsValueMap() + if ami, ok := planned["ami"]; ok && ami.AsString() == "grandchild" { checked = true // Sleep to allow parallel execution @@ -455,12 +445,13 @@ func TestContext2Apply_resourceDependsOnModuleGrandchild(t *testing.T) { // Verify that called is 0 (dep not called) if atomic.LoadInt32(&called) != 0 { - return nil, fmt.Errorf("aws_instance.a should not be called") + resp.Diagnostics = resp.Diagnostics.Append(fmt.Errorf("aws_instance.a should not be called")) + return resp } } atomic.AddInt32(&called, 1) - return testApplyFn(info, is, id) + return testApplyFn(req) } ctx := testContext2(t, &ContextOpts{ @@ -497,8 +488,9 @@ func TestContext2Apply_resourceDependsOnModuleInModule(t *testing.T) { // called a child. var called int32 var checked bool - p.ApplyFn = func(info *InstanceInfo, is *InstanceState, id *InstanceDiff) (*InstanceState, error) { - if id.Attributes["ami"].New == "grandchild" { + p.ApplyFn = func(req providers.ApplyResourceChangeRequest) (resp providers.ApplyResourceChangeResponse) { + planned := req.PlannedState.AsValueMap() + if ami, ok := planned["ami"]; ok && ami.AsString() == "grandchild" { checked = true // Sleep to allow parallel execution @@ -506,12 +498,13 @@ func TestContext2Apply_resourceDependsOnModuleInModule(t *testing.T) { // Verify that called is 0 (dep not called) if atomic.LoadInt32(&called) != 0 { - return nil, fmt.Errorf("something else was applied before grandchild; grandchild should be first") + resp.Diagnostics = resp.Diagnostics.Append(fmt.Errorf("something else was applied before grandchild; grandchild should be first")) + return resp } } atomic.AddInt32(&called, 1) - return testApplyFn(info, is, id) + return testApplyFn(req) } ctx := testContext2(t, &ContextOpts{ @@ -729,6 +722,7 @@ func TestContext2Apply_providerWarning(t *testing.T) { aws_instance.foo: ID = foo provider = provider["registry.terraform.io/hashicorp/aws"] + type = aws_instance `) if actual != expected { t.Fatalf("got: \n%s\n\nexpected:\n%s", actual, expected) @@ -1117,6 +1111,7 @@ func TestContext2Apply_createBeforeDestroy_deposedOnly(t *testing.T) { aws_instance.bar: ID = bar provider = provider["registry.terraform.io/hashicorp/aws"] + type = aws_instance `) } @@ -1195,12 +1190,13 @@ func testContext2Apply_destroyDependsOn(t *testing.T) { // Record the order we see Apply var actual []string var actualLock sync.Mutex - p.ApplyFn = func( - _ *InstanceInfo, is *InstanceState, _ *InstanceDiff) (*InstanceState, error) { + p.ApplyFn = func(req providers.ApplyResourceChangeRequest) providers.ApplyResourceChangeResponse { actualLock.Lock() defer actualLock.Unlock() - actual = append(actual, is.ID) - return nil, nil + id := req.PriorState.GetAttr("id").AsString() + actual = append(actual, id) + + return testApplyFn(req) } ctx := testContext2(t, &ContextOpts{ @@ -1291,12 +1287,12 @@ func testContext2Apply_destroyDependsOnStateOnly(t *testing.T, state *states.Sta // Record the order we see Apply var actual []string var actualLock sync.Mutex - p.ApplyFn = func( - _ *InstanceInfo, is *InstanceState, _ *InstanceDiff) (*InstanceState, error) { + p.ApplyFn = func(req providers.ApplyResourceChangeRequest) providers.ApplyResourceChangeResponse { actualLock.Lock() defer actualLock.Unlock() - actual = append(actual, is.ID) - return nil, nil + id := req.PriorState.GetAttr("id").AsString() + actual = append(actual, id) + return testApplyFn(req) } ctx := testContext2(t, &ContextOpts{ @@ -1388,12 +1384,12 @@ func testContext2Apply_destroyDependsOnStateOnlyModule(t *testing.T, state *stat // Record the order we see Apply var actual []string var actualLock sync.Mutex - p.ApplyFn = func( - _ *InstanceInfo, is *InstanceState, _ *InstanceDiff) (*InstanceState, error) { + p.ApplyFn = func(req providers.ApplyResourceChangeRequest) providers.ApplyResourceChangeResponse { actualLock.Lock() defer actualLock.Unlock() - actual = append(actual, is.ID) - return nil, nil + id := req.PriorState.GetAttr("id").AsString() + actual = append(actual, id) + return testApplyFn(req) } ctx := testContext2(t, &ContextOpts{ @@ -1700,39 +1696,6 @@ func TestContext2Apply_minimal(t *testing.T) { } } -func TestContext2Apply_badDiff(t *testing.T) { - m := testModule(t, "apply-good") - p := testProvider("aws") - p.ApplyFn = testApplyFn - p.DiffFn = testDiffFn - ctx := testContext2(t, &ContextOpts{ - Config: m, - Providers: map[addrs.Provider]providers.Factory{ - addrs.NewDefaultProvider("aws"): testProviderFuncFixed(p), - }, - }) - - if _, diags := ctx.Plan(); diags.HasErrors() { - t.Fatalf("plan errors: %s", diags.Err()) - } - - p.DiffFn = func(*InstanceInfo, *InstanceState, *ResourceConfig) (*InstanceDiff, error) { - return &InstanceDiff{ - Attributes: map[string]*ResourceAttrDiff{ - "newp": &ResourceAttrDiff{ - Old: "", - New: "", - NewComputed: true, - }, - }, - }, nil - } - - if _, diags := ctx.Apply(); diags == nil { - t.Fatal("should error") - } -} - func TestContext2Apply_cancel(t *testing.T) { stopped := false @@ -1745,7 +1708,7 @@ func TestContext2Apply_cancel(t *testing.T) { }, }) - p.ApplyFn = func(*InstanceInfo, *InstanceState, *InstanceDiff) (*InstanceState, error) { + p.ApplyFn = func(req providers.ApplyResourceChangeRequest) providers.ApplyResourceChangeResponse { if !stopped { stopped = true go ctx.Stop() @@ -1757,30 +1720,9 @@ func TestContext2Apply_cancel(t *testing.T) { time.Sleep(10 * time.Millisecond) } } - - return &InstanceState{ - ID: "foo", - Attributes: map[string]string{ - "value": "2", - }, - }, nil - } - p.DiffFn = func(info *InstanceInfo, s *InstanceState, rc *ResourceConfig) (*InstanceDiff, error) { - d := &InstanceDiff{ - Attributes: map[string]*ResourceAttrDiff{}, - } - if new, ok := rc.Get("value"); ok { - d.Attributes["value"] = &ResourceAttrDiff{ - New: new.(string), - } - } - if new, ok := rc.Get("foo"); ok { - d.Attributes["foo"] = &ResourceAttrDiff{ - New: new.(string), - } - } - return d, nil + return testApplyFn(req) } + p.DiffFn = testDiffFn if _, diags := ctx.Plan(); diags.HasErrors() { t.Fatalf("plan errors: %s", diags.Err()) @@ -1823,19 +1765,8 @@ func TestContext2Apply_cancelBlock(t *testing.T) { }) applyCh := make(chan struct{}) - p.DiffFn = func(*InstanceInfo, *InstanceState, *ResourceConfig) (*InstanceDiff, error) { - return &InstanceDiff{ - Attributes: map[string]*ResourceAttrDiff{ - "id": &ResourceAttrDiff{ - New: "foo", - }, - "num": &ResourceAttrDiff{ - New: "2", - }, - }, - }, nil - } - p.ApplyFn = func(*InstanceInfo, *InstanceState, *InstanceDiff) (*InstanceState, error) { + p.DiffFn = testDiffFn + p.ApplyFn = func(req providers.ApplyResourceChangeRequest) providers.ApplyResourceChangeResponse { close(applyCh) for !ctx.sh.Stopped() { @@ -1846,13 +1777,7 @@ func TestContext2Apply_cancelBlock(t *testing.T) { // Sleep time.Sleep(100 * time.Millisecond) - - return &InstanceState{ - ID: "foo", - Attributes: map[string]string{ - "num": "2", - }, - }, nil + return testApplyFn(req) } if _, diags := ctx.Plan(); diags.HasErrors() { @@ -1901,6 +1826,7 @@ aws_instance.foo: ID = foo provider = provider["registry.terraform.io/hashicorp/aws"] num = 2 + type = aws_instance `) } @@ -2249,11 +2175,11 @@ func TestContext2Apply_countTainted(t *testing.T) { DESTROY/CREATE: aws_instance.foo[0] foo: "foo" => "foo" id: "bar" => "" - type: "aws_instance" => "aws_instance" + type: "aws_instance" => "" CREATE: aws_instance.foo[1] foo: "" => "foo" id: "" => "" - type: "" => "aws_instance" + type: "" => "" `) if got != want { t.Fatalf("wrong plan\n\ngot:\n%s\n\nwant:\n%s", got, want) @@ -2463,12 +2389,10 @@ func TestContext2Apply_moduleDestroyOrder(t *testing.T) { // Create a custom apply function to track the order they were destroyed var order []string var orderLock sync.Mutex - p.ApplyFn = func( - info *InstanceInfo, - is *InstanceState, - id *InstanceDiff) (*InstanceState, error) { + p.ApplyFn = func(req providers.ApplyResourceChangeRequest) (resp providers.ApplyResourceChangeResponse) { + id := req.PriorState.GetAttr("id").AsString() - if is.ID == "b" { + if id == "b" { // Pause briefly to make any race conditions more visible, since // missing edges here can cause undeterministic ordering. time.Sleep(100 * time.Millisecond) @@ -2477,8 +2401,9 @@ func TestContext2Apply_moduleDestroyOrder(t *testing.T) { orderLock.Lock() defer orderLock.Unlock() - order = append(order, is.ID) - return nil, nil + order = append(order, id) + resp.NewState = req.PlannedState + return resp } p.GetSchemaReturn = &ProviderSchema{ @@ -2586,6 +2511,7 @@ module.child: aws_instance.foo: ID = foo provider = provider["registry.terraform.io/hashicorp/aws"].eu + type = aws_instance `) } @@ -2601,7 +2527,12 @@ func TestContext2Apply_orphanResource(t *testing.T) { p.DiffFn = testDiffFn p.GetSchemaReturn = &ProviderSchema{ ResourceTypes: map[string]*configschema.Block{ - "test_thing": {}, + "test_thing": { + Attributes: map[string]*configschema.Attribute{ + "id": {Type: cty.String, Computed: true}, + "foo": {Type: cty.String, Optional: true}, + }, + }, }, } @@ -2633,12 +2564,11 @@ func TestContext2Apply_orphanResource(t *testing.T) { s.SetResourceProvider(oneAddr, providerAddr) s.SetResourceInstanceCurrent(oneAddr.Instance(addrs.IntKey(0)), &states.ResourceInstanceObjectSrc{ Status: states.ObjectReady, - AttrsJSON: []byte(`{}`), + AttrsJSON: []byte(`{"id":"foo"}`), }, providerAddr) }) - // compare the marshaled form to easily remove empty and nil slices - if !statefile.StatesMarshalEqual(state, want) { + if state.String() != want.String() { t.Fatalf("wrong state after step 1\n%s", cmp.Diff(want, state)) } @@ -3214,6 +3144,7 @@ func TestContext2Apply_multiProviderDestroy(t *testing.T) { ResourceTypes: map[string]*configschema.Block{ "aws_instance": { Attributes: map[string]*configschema.Attribute{ + "id": {Type: cty.String, Computed: true}, "foo": {Type: cty.String, Optional: true}, }, }, @@ -3263,14 +3194,11 @@ func TestContext2Apply_multiProviderDestroy(t *testing.T) { var checked bool var called int32 var lock sync.Mutex - applyFn := func( - info *InstanceInfo, - is *InstanceState, - id *InstanceDiff) (*InstanceState, error) { + applyFn := func(req providers.ApplyResourceChangeRequest) (resp providers.ApplyResourceChangeResponse) { lock.Lock() defer lock.Unlock() - if info.Type == "aws_instance" { + if req.TypeName == "aws_instance" { checked = true // Sleep to allow parallel execution @@ -3278,12 +3206,13 @@ func TestContext2Apply_multiProviderDestroy(t *testing.T) { // Verify that called is 0 (dep not called) if atomic.LoadInt32(&called) != 0 { - return nil, fmt.Errorf("nothing else should be called") + resp.Diagnostics = resp.Diagnostics.Append(fmt.Errorf("nothing else should be called")) + return resp } } atomic.AddInt32(&called, 1) - return testApplyFn(info, is, id) + return testApplyFn(req) } // Set the apply functions @@ -3336,6 +3265,7 @@ func TestContext2Apply_multiProviderDestroyChild(t *testing.T) { ResourceTypes: map[string]*configschema.Block{ "aws_instance": { Attributes: map[string]*configschema.Attribute{ + "id": {Type: cty.String, Computed: true}, "foo": {Type: cty.String, Optional: true}, }, }, @@ -3386,14 +3316,11 @@ func TestContext2Apply_multiProviderDestroyChild(t *testing.T) { var checked bool var called int32 var lock sync.Mutex - applyFn := func( - info *InstanceInfo, - is *InstanceState, - id *InstanceDiff) (*InstanceState, error) { + applyFn := func(req providers.ApplyResourceChangeRequest) (resp providers.ApplyResourceChangeResponse) { lock.Lock() defer lock.Unlock() - if info.Type == "aws_instance" { + if req.TypeName == "aws_instance" { checked = true // Sleep to allow parallel execution @@ -3401,12 +3328,13 @@ func TestContext2Apply_multiProviderDestroyChild(t *testing.T) { // Verify that called is 0 (dep not called) if atomic.LoadInt32(&called) != 0 { - return nil, fmt.Errorf("nothing else should be called") + resp.Diagnostics = resp.Diagnostics.Append(fmt.Errorf("nothing else should be called")) + return resp } } atomic.AddInt32(&called, 1) - return testApplyFn(info, is, id) + return testApplyFn(req) } // Set the apply functions @@ -3842,38 +3770,37 @@ func TestContext2Apply_multiVarCountDec(t *testing.T) { // Decrease the count by 1 and verify that everything happens in the // right order. - { - m := testModule(t, "apply-multi-var-count-dec") - p := testProvider("aws") - p.ApplyFn = testApplyFn - p.DiffFn = testDiffFn + m := testModule(t, "apply-multi-var-count-dec") + p := testProvider("aws") + p.DiffFn = testDiffFn - // Verify that aws_instance.bar is modified first and nothing - // else happens at the same time. + // Verify that aws_instance.bar is modified first and nothing + // else happens at the same time. + { var checked bool var called int32 var lock sync.Mutex - p.ApplyFn = func( - info *InstanceInfo, - is *InstanceState, - id *InstanceDiff) (*InstanceState, error) { + p.ApplyFn = func(req providers.ApplyResourceChangeRequest) (resp providers.ApplyResourceChangeResponse) { lock.Lock() defer lock.Unlock() - if id != nil && id.Attributes != nil && id.Attributes["ami"] != nil && id.Attributes["ami"].New == "special" { - checked = true + if !req.PlannedState.IsNull() { + s := req.PlannedState.AsValueMap() + if ami, ok := s["ami"]; ok && !ami.IsNull() && ami.AsString() == "special" { + checked = true - // Sleep to allow parallel execution - time.Sleep(50 * time.Millisecond) + // Sleep to allow parallel execution + time.Sleep(50 * time.Millisecond) - // Verify that called is 0 (dep not called) - if atomic.LoadInt32(&called) != 1 { - return nil, fmt.Errorf("nothing else should be called") + // Verify that called is 0 (dep not called) + if atomic.LoadInt32(&called) != 1 { + resp.Diagnostics = resp.Diagnostics.Append(fmt.Errorf("nothing else should be called")) + return + } } } - atomic.AddInt32(&called, 1) - return testApplyFn(info, is, id) + return testApplyFn(req) } ctx := testContext2(t, &ContextOpts{ @@ -3899,7 +3826,7 @@ func TestContext2Apply_multiVarCountDec(t *testing.T) { t.Logf("Step 2 plan:\n%s", legacyDiffComparisonString(plan.Changes)) log.Print("\n========\nStep 2 Apply\n========") - state, diags := ctx.Apply() + _, diags = ctx.Apply() if diags.HasErrors() { t.Fatalf("apply errors: %s", diags.Err()) } @@ -3907,10 +3834,6 @@ func TestContext2Apply_multiVarCountDec(t *testing.T) { if !checked { t.Error("apply never called") } - - t.Logf("Step 2 state:\n%s", state) - - s = state } } @@ -3954,31 +3877,6 @@ func TestContext2Apply_multiVarMissingState(t *testing.T) { // If we get here with no errors or panics then our test was successful. } -func TestContext2Apply_nilDiff(t *testing.T) { - m := testModule(t, "apply-good") - p := testProvider("aws") - p.ApplyFn = testApplyFn - p.DiffFn = testDiffFn - ctx := testContext2(t, &ContextOpts{ - Config: m, - Providers: map[addrs.Provider]providers.Factory{ - addrs.NewDefaultProvider("aws"): testProviderFuncFixed(p), - }, - }) - - if _, diags := ctx.Plan(); diags.HasErrors() { - t.Fatalf("plan errors: %s", diags.Err()) - } - - p.DiffFn = func(*InstanceInfo, *InstanceState, *ResourceConfig) (*InstanceDiff, error) { - return nil, nil - } - - if _, diags := ctx.Apply(); diags == nil { - t.Fatal("should error") - } -} - func TestContext2Apply_outputOrphan(t *testing.T) { m := testModule(t, "apply-output-orphan") p := testProvider("aws") @@ -4253,9 +4151,11 @@ func TestContext2Apply_provisionerCreateFail(t *testing.T) { pr := testProvisioner() p.DiffFn = testDiffFn - p.ApplyFn = func(info *InstanceInfo, is *InstanceState, id *InstanceDiff) (*InstanceState, error) { - is.ID = "foo" - return is, fmt.Errorf("error") + p.ApplyFn = func(req providers.ApplyResourceChangeRequest) providers.ApplyResourceChangeResponse { + resp := testApplyFn(req) + resp.Diagnostics = resp.Diagnostics.Append(fmt.Errorf("error")) + + return resp } ctx := testContext2(t, &ContextOpts{ @@ -4290,11 +4190,9 @@ func TestContext2Apply_provisionerCreateFailNoId(t *testing.T) { pr := testProvisioner() p.DiffFn = testDiffFn - p.ApplyFn = func( - info *InstanceInfo, - is *InstanceState, - id *InstanceDiff) (*InstanceState, error) { - return nil, fmt.Errorf("error") + p.ApplyFn = func(req providers.ApplyResourceChangeRequest) (resp providers.ApplyResourceChangeResponse) { + resp.Diagnostics = resp.Diagnostics.Append(fmt.Errorf("error")) + return } ctx := testContext2(t, &ContextOpts{ @@ -4327,9 +4225,8 @@ func TestContext2Apply_provisionerFail(t *testing.T) { m := testModule(t, "apply-provisioner-fail") p := testProvider("aws") pr := testProvisioner() - p.ApplyFn = testApplyFn p.DiffFn = testDiffFn - + p.ApplyFn = testApplyFn pr.ApplyFn = func(*InstanceState, *ResourceConfig) error { return fmt.Errorf("EXPLOSION") } @@ -4376,7 +4273,7 @@ func TestContext2Apply_provisionerFail_createBeforeDestroy(t *testing.T) { mustResourceInstanceAddr("aws_instance.bar").Resource, &states.ResourceInstanceObjectSrc{ Status: states.ObjectReady, - AttrsJSON: []byte(`{"id":"bar", "require_new": "abc"}`), + AttrsJSON: []byte(`{"id":"bar","require_new":"abc"}`), }, mustProviderConfig(`provider["registry.terraform.io/hashicorp/aws"]`), ) @@ -4418,7 +4315,7 @@ func TestContext2Apply_error_createBeforeDestroy(t *testing.T) { mustResourceInstanceAddr("aws_instance.bar").Resource, &states.ResourceInstanceObjectSrc{ Status: states.ObjectReady, - AttrsJSON: []byte(`{"id":"bar", "require_new": "abc"}`), + AttrsJSON: []byte(`{"id":"bar", "require_new": "abc","type":"aws_instance"}`), }, mustProviderConfig(`provider["registry.terraform.io/hashicorp/aws"]`), ) @@ -4430,8 +4327,9 @@ func TestContext2Apply_error_createBeforeDestroy(t *testing.T) { }, State: state, }) - p.ApplyFn = func(info *InstanceInfo, is *InstanceState, id *InstanceDiff) (*InstanceState, error) { - return nil, fmt.Errorf("placeholder error from ApplyFn") + p.ApplyFn = func(req providers.ApplyResourceChangeRequest) (resp providers.ApplyResourceChangeResponse) { + resp.Diagnostics = resp.Diagnostics.Append(fmt.Errorf("placeholder error from ApplyFn")) + return } p.DiffFn = testDiffFn @@ -4478,21 +4376,15 @@ func TestContext2Apply_errorDestroy_createBeforeDestroy(t *testing.T) { }, State: state, }) - p.ApplyFn = func(info *InstanceInfo, is *InstanceState, id *InstanceDiff) (*InstanceState, error) { + p.ApplyFn = func(req providers.ApplyResourceChangeRequest) (resp providers.ApplyResourceChangeResponse) { // Fail the destroy! - if id.Destroy { - return is, fmt.Errorf("error") + if req.PlannedState.IsNull() { + resp.NewState = req.PriorState + resp.Diagnostics = resp.Diagnostics.Append(fmt.Errorf("error")) + return } - // Create should work - is = &InstanceState{ - ID: "foo", - Attributes: map[string]string{ - "type": "aws_instance", - "require_new": "xyz", - }, - } - return is, nil + return testApplyFn(req) } p.DiffFn = testDiffFn @@ -4538,54 +4430,38 @@ func TestContext2Apply_multiDepose_createBeforeDestroy(t *testing.T) { mustProviderConfig(`provider["registry.terraform.io/hashicorp/aws"]`), ) - p.DiffFn = func(info *InstanceInfo, s *InstanceState, rc *ResourceConfig) (*InstanceDiff, error) { - if rc == nil { - return &InstanceDiff{ - Destroy: true, - }, nil - } - - rn, _ := rc.Get("require_new") - return &InstanceDiff{ - Attributes: map[string]*ResourceAttrDiff{ - "id": { - New: hcl2shim.UnknownVariableValue, - NewComputed: true, - RequiresNew: true, - }, - "require_new": { - Old: s.Attributes["require_new"], - New: rn.(string), - RequiresNew: true, - }, - }, - }, nil - } + p.DiffFn = testDiffFn ctx := testContext2(t, &ContextOpts{ Config: m, Providers: ps, State: state, + Variables: InputValues{ + "require_new": &InputValue{ + Value: cty.StringVal("yes"), + }, + }, }) createdInstanceId := "bar" // Create works - createFunc := func(is *InstanceState, id *InstanceDiff) (*InstanceState, error) { - return &InstanceState{ - ID: createdInstanceId, - Attributes: map[string]string{ - "require_new": id.Attributes["require_new"].New, - }, - }, nil + createFunc := func(req providers.ApplyResourceChangeRequest) (resp providers.ApplyResourceChangeResponse) { + s := req.PlannedState.AsValueMap() + s["id"] = cty.StringVal(createdInstanceId) + resp.NewState = cty.ObjectVal(s) + return } + // Destroy starts broken - destroyFunc := func(is *InstanceState) (*InstanceState, error) { - return is, fmt.Errorf("destroy failed") + destroyFunc := func(req providers.ApplyResourceChangeRequest) (resp providers.ApplyResourceChangeResponse) { + resp.NewState = req.PriorState + resp.Diagnostics = resp.Diagnostics.Append(fmt.Errorf("destroy failed")) + return } - p.ApplyFn = func(info *InstanceInfo, is *InstanceState, id *InstanceDiff) (*InstanceState, error) { - if id.Destroy { - return destroyFunc(is) + p.ApplyFn = func(req providers.ApplyResourceChangeRequest) (resp providers.ApplyResourceChangeResponse) { + if req.PlannedState.IsNull() { + return destroyFunc(req) } else { - return createFunc(is, id) + return createFunc(req) } } @@ -4613,6 +4489,11 @@ aws_instance.web: (1 deposed) Config: m, Providers: ps, State: state, + Variables: InputValues{ + "require_new": &InputValue{ + Value: cty.StringVal("baz"), + }, + }, }) if _, diags := ctx.Plan(); diags.HasErrors() { @@ -4631,7 +4512,6 @@ aws_instance.web: (1 deposed) // we will probe the state object directly. { is := state.RootModule().Resources["aws_instance.web"].Instances[addrs.NoKey] - t.Logf("aws_instance.web is %s", spew.Sdump(is)) if is.Current == nil { t.Fatalf("no current object for aws_instance web; should have one") } @@ -4659,12 +4539,16 @@ aws_instance.web: (1 deposed) } // Destroy partially fixed! - destroyFunc = func(is *InstanceState) (*InstanceState, error) { - if is.ID == "foo" || is.ID == "baz" { - return nil, nil + destroyFunc = func(req providers.ApplyResourceChangeRequest) (resp providers.ApplyResourceChangeResponse) { + s := req.PriorState.AsValueMap() + id := s["id"].AsString() + if id == "foo" || id == "baz" { + resp.NewState = cty.NullVal(req.PriorState.Type()) } else { - return is, fmt.Errorf("destroy partially failed") + resp.NewState = req.PriorState + resp.Diagnostics = resp.Diagnostics.Append(fmt.Errorf("destroy partially failed")) } + return } createdInstanceId = "qux" @@ -4672,10 +4556,16 @@ aws_instance.web: (1 deposed) Config: m, Providers: ps, State: state, + Variables: InputValues{ + "require_new": &InputValue{ + Value: cty.StringVal("qux"), + }, + }, }) if _, diags := ctx.Plan(); diags.HasErrors() { t.Fatalf("plan errors: %s", diags.Err()) } + state, diags = ctx.Apply() // Expect error because 1/2 of Deposed destroys failed if diags == nil { @@ -4687,13 +4577,14 @@ aws_instance.web: (1 deposed) aws_instance.web: (1 deposed) ID = qux provider = provider["registry.terraform.io/hashicorp/aws"] - require_new = yes + require_new = qux Deposed ID 1 = bar `) // Destroy working fully! - destroyFunc = func(is *InstanceState) (*InstanceState, error) { - return nil, nil + destroyFunc = func(req providers.ApplyResourceChangeRequest) (resp providers.ApplyResourceChangeResponse) { + resp.NewState = cty.NullVal(req.PriorState.Type()) + return } createdInstanceId = "quux" @@ -4701,6 +4592,11 @@ aws_instance.web: (1 deposed) Config: m, Providers: ps, State: state, + Variables: InputValues{ + "require_new": &InputValue{ + Value: cty.StringVal("quux"), + }, + }, }) if _, diags := ctx.Plan(); diags.HasErrors() { t.Fatalf("plan errors: %s", diags.Err()) @@ -4715,7 +4611,7 @@ aws_instance.web: (1 deposed) aws_instance.web: ID = quux provider = provider["registry.terraform.io/hashicorp/aws"] - require_new = yes + require_new = quux `) } @@ -5571,41 +5467,34 @@ func TestContext2Apply_outputDiffVars(t *testing.T) { State: state, }) - p.ApplyFn = func(info *InstanceInfo, s *InstanceState, d *InstanceDiff) (*InstanceState, error) { - if d.Destroy { - return nil, nil - } - - result := s.MergeDiff(d) - result.ID = "foo" - return result, nil - } - p.DiffFn = func(info *InstanceInfo, s *InstanceState, rc *ResourceConfig) (*InstanceDiff, error) { - d := &InstanceDiff{ - Attributes: map[string]*ResourceAttrDiff{}, - } - if new, ok := rc.Get("value"); ok { - d.Attributes["value"] = &ResourceAttrDiff{ - New: new.(string), - } - } - if new, ok := rc.Get("foo"); ok { - d.Attributes["foo"] = &ResourceAttrDiff{ - New: new.(string), - } - } else if rc.IsComputed("foo") { - d.Attributes["foo"] = &ResourceAttrDiff{ - NewComputed: true, - Type: DiffAttrOutput, // This doesn't actually really do anything anymore, but this test originally set it. - } - } - if new, ok := rc.Get("num"); ok { - d.Attributes["num"] = &ResourceAttrDiff{ - New: fmt.Sprintf("%#v", new), - } - } - return d, nil - } + p.ApplyFn = testApplyFn + p.DiffFn = testDiffFn + //func(info *InstanceInfo, s *InstanceState, rc *ResourceConfig) (*InstanceDiff, error) { + // d := &InstanceDiff{ + // Attributes: map[string]*ResourceAttrDiff{}, + // } + // if new, ok := rc.Get("value"); ok { + // d.Attributes["value"] = &ResourceAttrDiff{ + // New: new.(string), + // } + // } + // if new, ok := rc.Get("foo"); ok { + // d.Attributes["foo"] = &ResourceAttrDiff{ + // New: new.(string), + // } + // } else if rc.IsComputed("foo") { + // d.Attributes["foo"] = &ResourceAttrDiff{ + // NewComputed: true, + // Type: DiffAttrOutput, // This doesn't actually really do anything anymore, but this test originally set it. + // } + // } + // if new, ok := rc.Get("num"); ok { + // d.Attributes["num"] = &ResourceAttrDiff{ + // New: fmt.Sprintf("%#v", new), + // } + // } + // return d, nil + //} if _, diags := ctx.Plan(); diags.HasErrors() { logDiagnostics(t, diags) @@ -6291,31 +6180,8 @@ func TestContext2Apply_destroyOrphan(t *testing.T) { State: state, }) - p.ApplyFn = func(info *InstanceInfo, s *InstanceState, d *InstanceDiff) (*InstanceState, error) { - if d.Destroy { - return nil, nil - } - - result := s.MergeDiff(d) - result.ID = "foo" - return result, nil - } - p.DiffFn = func(info *InstanceInfo, s *InstanceState, rc *ResourceConfig) (*InstanceDiff, error) { - d := &InstanceDiff{ - Attributes: map[string]*ResourceAttrDiff{}, - } - if new, ok := rc.Get("value"); ok { - d.Attributes["value"] = &ResourceAttrDiff{ - New: new.(string), - } - } - if new, ok := rc.Get("foo"); ok { - d.Attributes["foo"] = &ResourceAttrDiff{ - New: new.(string), - } - } - return d, nil - } + p.ApplyFn = testApplyFn + p.DiffFn = testDiffFn if _, diags := ctx.Plan(); diags.HasErrors() { t.Fatalf("plan errors: %s", diags.Err()) @@ -6400,38 +6266,17 @@ func TestContext2Apply_error(t *testing.T) { }, }) - p.ApplyFn = func(*InstanceInfo, *InstanceState, *InstanceDiff) (*InstanceState, error) { + p.ApplyFn = func(req providers.ApplyResourceChangeRequest) (resp providers.ApplyResourceChangeResponse) { if errored { - state := &InstanceState{ - ID: "bar", - } - return state, fmt.Errorf("error") + resp.NewState = req.PlannedState + resp.Diagnostics = resp.Diagnostics.Append(fmt.Errorf("error")) + return } errored = true - return &InstanceState{ - ID: "foo", - Attributes: map[string]string{ - "value": "2", - }, - }, nil - } - p.DiffFn = func(info *InstanceInfo, s *InstanceState, rc *ResourceConfig) (*InstanceDiff, error) { - d := &InstanceDiff{ - Attributes: map[string]*ResourceAttrDiff{}, - } - if new, ok := rc.Get("value"); ok { - d.Attributes["value"] = &ResourceAttrDiff{ - New: new.(string), - } - } - if new, ok := rc.Get("foo"); ok { - d.Attributes["foo"] = &ResourceAttrDiff{ - New: new.(string), - } - } - return d, nil + return testApplyFn(req) } + p.DiffFn = testDiffFn if _, diags := ctx.Plan(); diags.HasErrors() { t.Fatalf("plan errors: %s", diags.Err()) @@ -6684,7 +6529,7 @@ func TestContext2Apply_errorPartial(t *testing.T) { mustResourceInstanceAddr("aws_instance.bar").Resource, &states.ResourceInstanceObjectSrc{ Status: states.ObjectReady, - AttrsJSON: []byte(`{"id":"bar"}`), + AttrsJSON: []byte(`{"id":"bar","type":"aws_instance"}`), }, mustProviderConfig(`provider["registry.terraform.io/hashicorp/aws"]`), ) @@ -6697,35 +6542,16 @@ func TestContext2Apply_errorPartial(t *testing.T) { State: state, }) - p.ApplyFn = func(info *InstanceInfo, s *InstanceState, d *InstanceDiff) (*InstanceState, error) { + p.ApplyFn = func(req providers.ApplyResourceChangeRequest) (resp providers.ApplyResourceChangeResponse) { if errored { - return s, fmt.Errorf("error") + resp.Diagnostics = resp.Diagnostics.Append(fmt.Errorf("error")) + return } errored = true - return &InstanceState{ - ID: "foo", - Attributes: map[string]string{ - "value": "2", - }, - }, nil - } - p.DiffFn = func(info *InstanceInfo, s *InstanceState, rc *ResourceConfig) (*InstanceDiff, error) { - d := &InstanceDiff{ - Attributes: map[string]*ResourceAttrDiff{}, - } - if new, ok := rc.Get("value"); ok { - d.Attributes["value"] = &ResourceAttrDiff{ - New: new.(string), - } - } - if new, ok := rc.Get("foo"); ok { - d.Attributes["foo"] = &ResourceAttrDiff{ - New: new.(string), - } - } - return d, nil + return testApplyFn(req) } + p.DiffFn = testDiffFn if _, diags := ctx.Plan(); diags.HasErrors() { t.Fatalf("plan errors: %s", diags.Err()) @@ -6837,25 +6663,8 @@ func TestContext2Apply_idAttr(t *testing.T) { }, }) - p.ApplyFn = func(info *InstanceInfo, s *InstanceState, d *InstanceDiff) (*InstanceState, error) { - result := s.MergeDiff(d) - result.ID = "foo" - result.Attributes = map[string]string{ - "id": "bar", - "num": "42", - } - - return result, nil - } - p.DiffFn = func(*InstanceInfo, *InstanceState, *ResourceConfig) (*InstanceDiff, error) { - return &InstanceDiff{ - Attributes: map[string]*ResourceAttrDiff{ - "num": &ResourceAttrDiff{ - New: "42", - }, - }, - }, nil - } + p.ApplyFn = testApplyFn + p.DiffFn = testDiffFn if _, diags := ctx.Plan(); diags.HasErrors() { t.Fatalf("plan errors: %s", diags.Err()) @@ -7054,12 +6863,12 @@ func TestContext2Apply_taintX(t *testing.T) { time.Sleep(10 * time.Millisecond) } - p.ApplyFn = func(info *InstanceInfo, s *InstanceState, d *InstanceDiff) (*InstanceState, error) { + p.ApplyFn = func(req providers.ApplyResourceChangeRequest) providers.ApplyResourceChangeResponse { once.Do(simulateProviderDelay) - if d.Destroy { + if req.PlannedState.IsNull() { atomic.AddInt32(&destroyCount, 1) } - return testApplyFn(info, s, d) + return testApplyFn(req) } p.DiffFn = testDiffFn @@ -7278,12 +7087,15 @@ func TestContext2Apply_targetedCount(t *testing.T) { aws_instance.foo.0: ID = foo provider = provider["registry.terraform.io/hashicorp/aws"] + type = aws_instance aws_instance.foo.1: ID = foo provider = provider["registry.terraform.io/hashicorp/aws"] + type = aws_instance aws_instance.foo.2: ID = foo provider = provider["registry.terraform.io/hashicorp/aws"] + type = aws_instance `) } @@ -7317,6 +7129,7 @@ func TestContext2Apply_targetedCountIndex(t *testing.T) { aws_instance.foo.1: ID = foo provider = provider["registry.terraform.io/hashicorp/aws"] + type = aws_instance `) } @@ -7716,6 +7529,7 @@ module.child: aws_instance.mod: ID = foo provider = provider["registry.terraform.io/hashicorp/aws"] + type = aws_instance Outputs: @@ -7768,6 +7582,7 @@ module.child2: aws_instance.foo: ID = foo provider = provider["registry.terraform.io/hashicorp/aws"] + type = aws_instance Outputs: @@ -7860,7 +7675,27 @@ func TestContext2Apply_unknownAttribute(t *testing.T) { m := testModule(t, "apply-unknown") p := testProvider("aws") p.ApplyFn = testApplyFn - p.DiffFn = testDiffFn + p.DiffFn = func(req providers.PlanResourceChangeRequest) (resp providers.PlanResourceChangeResponse) { + resp = testDiffFn(req) + planned := resp.PlannedState.AsValueMap() + planned["unknown"] = cty.UnknownVal(cty.String) + resp.PlannedState = cty.ObjectVal(planned) + return resp + } + + p.GetSchemaReturn = &ProviderSchema{ + ResourceTypes: map[string]*configschema.Block{ + "aws_instance": { + Attributes: map[string]*configschema.Attribute{ + "id": {Type: cty.String, Computed: true}, + "num": {Type: cty.Number, Optional: true}, + "unknown": {Type: cty.String, Computed: true}, + "type": {Type: cty.String, Computed: true}, + }, + }, + }, + } + ctx := testContext2(t, &ContextOpts{ Config: m, Providers: map[addrs.Provider]providers.Factory{ @@ -8108,35 +7943,33 @@ func TestContext2Apply_singleDestroy(t *testing.T) { h := new(HookRecordApplyOrder) p := testProvider("aws") invokeCount := 0 - p.ApplyFn = func(info *InstanceInfo, s *InstanceState, d *InstanceDiff) (*InstanceState, error) { + p.ApplyFn = func(req providers.ApplyResourceChangeRequest) providers.ApplyResourceChangeResponse { invokeCount++ switch invokeCount { case 1: - if d.Destroy { + if req.PlannedState.IsNull() { t.Fatalf("should not destroy") } - if s.ID != "" { + if id := req.PlannedState.GetAttr("id"); id.IsKnown() { t.Fatalf("should not have ID") } case 2: - if d.Destroy { + if req.PlannedState.IsNull() { t.Fatalf("should not destroy") } - if s.ID != "baz" { + if id := req.PlannedState.GetAttr("id"); id.AsString() != "baz" { t.Fatalf("should have id") } case 3: - if !d.Destroy { + if !req.PlannedState.IsNull() { t.Fatalf("should destroy") } - if s.ID == "" { - t.Fatalf("should have ID") - } default: t.Fatalf("bad invoke count %d", invokeCount) } - return testApplyFn(info, s, d) + return testApplyFn(req) } + p.DiffFn = testDiffFn state := states.NewState() root := state.EnsureModule(addrs.RootModuleInstance) @@ -8416,6 +8249,7 @@ func TestContext2Apply_targetedWithTaintedInState(t *testing.T) { aws_instance.iambeingadded: ID = foo provider = provider["registry.terraform.io/hashicorp/aws"] + type = aws_instance aws_instance.ifailedprovisioners: (tainted) ID = ifailedprovisioners provider = provider["registry.terraform.io/hashicorp/aws"] @@ -8481,25 +8315,18 @@ func TestContext2Apply_ignoreChangesWithDep(t *testing.T) { p := testProvider("aws") p.ApplyFn = testApplyFn - p.DiffFn = func(i *InstanceInfo, s *InstanceState, c *ResourceConfig) (*InstanceDiff, error) { - switch i.Type { + p.DiffFn = func(req providers.PlanResourceChangeRequest) (resp providers.PlanResourceChangeResponse) { + resp.PlannedState = req.ProposedNewState + + switch req.TypeName { case "aws_instance": - newAmi, _ := c.Get("ami") - return &InstanceDiff{ - Attributes: map[string]*ResourceAttrDiff{ - "ami": &ResourceAttrDiff{ - Old: s.Attributes["ami"], - New: newAmi.(string), - RequiresNew: true, - }, - }, - }, nil + resp.RequiresReplace = append(resp.RequiresReplace, cty.Path{cty.GetAttrStep{Name: "ami"}}) case "aws_eip": - return testDiffFn(i, s, c) + return testDiffFn(req) default: - t.Fatalf("Unexpected type: %s", i.Type) - return nil, nil + t.Fatalf("Unexpected type: %s", req.TypeName) } + return } state := states.NewState() @@ -8726,10 +8553,10 @@ resource "null_instance" "depends" { // solely on the configuration providing "depends_on" provisionerOutput := "" - p.ApplyFn = func(info *InstanceInfo, s *InstanceState, d *InstanceDiff) (*InstanceState, error) { + p.ApplyFn = func(req providers.ApplyResourceChangeRequest) providers.ApplyResourceChangeResponse { // the side effect of the resource being applied provisionerOutput = "APPLIED" - return testApplyFn(info, s, d) + return testApplyFn(req) } p.DiffFn = testDiffFn @@ -8796,10 +8623,10 @@ resource "null_instance" "depends" { } `}) - p.ApplyFn = func(info *InstanceInfo, s *InstanceState, d *InstanceDiff) (*InstanceState, error) { + p.ApplyFn = func(req providers.ApplyResourceChangeRequest) providers.ApplyResourceChangeResponse { // the side effect of the resource being applied provisionerOutput = "APPLIED_AGAIN" - return testApplyFn(info, s, d) + return testApplyFn(req) } ctx = testContext2(t, &ContextOpts{ @@ -8962,10 +8789,7 @@ func TestContext2Apply_destroyWithLocals(t *testing.T) { m := testModule(t, "apply-destroy-with-locals") p := testProvider("aws") p.ApplyFn = testApplyFn - p.DiffFn = func(info *InstanceInfo, s *InstanceState, c *ResourceConfig) (*InstanceDiff, error) { - d, err := testDiffFn(info, s, c) - return d, err - } + p.DiffFn = testDiffFn state := states.NewState() root := state.EnsureModule(addrs.RootModuleInstance) @@ -9787,17 +9611,24 @@ func TestContext2Apply_taintedDestroyFailure(t *testing.T) { m := testModule(t, "apply-destroy-tainted") p := testProvider("test") p.DiffFn = testDiffFn - p.ApplyFn = func(info *InstanceInfo, s *InstanceState, d *InstanceDiff) (*InstanceState, error) { + p.ApplyFn = func(req providers.ApplyResourceChangeRequest) (resp providers.ApplyResourceChangeResponse) { // All destroys fail. + if req.PlannedState.IsNull() { + resp.Diagnostics = resp.Diagnostics.Append(errors.New("failure")) + return + } + // c will also fail to create, meaning the existing tainted instance // becomes deposed, ans is then promoted back to current. // only C has a foo attribute - attr := d.Attributes["foo"] - if d.Destroy || (attr != nil && attr.New == "c") { - return nil, errors.New("failure") + planned := req.PlannedState.AsValueMap() + foo, ok := planned["foo"] + if ok && !foo.IsNull() && foo.AsString() == "c" { + resp.Diagnostics = resp.Diagnostics.Append(errors.New("failure")) + return } - return testApplyFn(info, s, d) + return testApplyFn(req) } p.GetSchemaReturn = &ProviderSchema{ ResourceTypes: map[string]*configschema.Block{ @@ -9953,6 +9784,9 @@ func TestContext2Apply_plannedConnectionRefs(t *testing.T) { } s["id"] = cty.StringVal("ID") + if ty, ok := s["type"]; ok && !ty.IsKnown() { + s["type"] = cty.StringVal(req.TypeName) + } resp.NewState = cty.ObjectVal(s) return resp } @@ -10138,6 +9972,9 @@ func TestContext2Apply_ProviderMeta_apply_set(t *testing.T) { s := req.PlannedState.AsValueMap() s["id"] = cty.StringVal("ID") + if ty, ok := s["type"]; ok && !ty.IsKnown() { + s["type"] = cty.StringVal(req.TypeName) + } return providers.ApplyResourceChangeResponse{ NewState: cty.ObjectVal(s), } @@ -10216,6 +10053,9 @@ func TestContext2Apply_ProviderMeta_apply_unset(t *testing.T) { s := req.PlannedState.AsValueMap() s["id"] = cty.StringVal("ID") + if ty, ok := s["type"]; ok && !ty.IsKnown() { + s["type"] = cty.StringVal(req.TypeName) + } return providers.ApplyResourceChangeResponse{ NewState: cty.ObjectVal(s), } @@ -11122,6 +10962,7 @@ func TestContext2Apply_moduleDependsOn(t *testing.T) { } state["id"] = cty.StringVal(fmt.Sprintf("test_%d", ord)) + state["type"] = cty.StringVal("test_instance") resp.NewState = cty.ObjectVal(state) return resp @@ -11377,9 +11218,7 @@ locals { ) p := testProvider("test") - p.ApplyFn = func(info *InstanceInfo, s *InstanceState, d *InstanceDiff) (*InstanceState, error) { - return testApplyFn(info, s, d) - } + p.ApplyFn = testApplyFn p.PlanResourceChangeFn = func(r providers.PlanResourceChangeRequest) (resp providers.PlanResourceChangeResponse) { n := r.ProposedNewState.AsValueMap() @@ -11555,11 +11394,12 @@ output "output" { } return resp } - testP.ApplyFn = func(info *InstanceInfo, s *InstanceState, d *InstanceDiff) (*InstanceState, error) { + testP.ApplyFn = func(req providers.ApplyResourceChangeRequest) (resp providers.ApplyResourceChangeResponse) { if providerConfig != "valid" { - return nil, fmt.Errorf("provider config is %q", providerConfig) + resp.Diagnostics = resp.Diagnostics.Append(fmt.Errorf("provider config is %q", providerConfig)) + return } - return testApplyFn(info, s, d) + return testApplyFn(req) } testP.DiffFn = testDiffFn diff --git a/terraform/context_input_test.go b/terraform/context_input_test.go index 836130579..cb63b6906 100644 --- a/terraform/context_input_test.go +++ b/terraform/context_input_test.go @@ -30,7 +30,14 @@ func TestContext2Input_provider(t *testing.T) { }, }, ResourceTypes: map[string]*configschema.Block{ - "aws_instance": {}, + "aws_instance": { + Attributes: map[string]*configschema.Attribute{ + "id": { + Type: cty.String, + Computed: true, + }, + }, + }, }, } @@ -98,7 +105,14 @@ func TestContext2Input_providerMulti(t *testing.T) { }, }, ResourceTypes: map[string]*configschema.Block{ - "aws_instance": {}, + "aws_instance": { + Attributes: map[string]*configschema.Attribute{ + "id": { + Type: cty.String, + Computed: true, + }, + }, + }, }, } @@ -159,25 +173,6 @@ func TestContext2Input_providerOnce(t *testing.T) { }, }) - //count := 0 - /*p.InputFn = func(i UIInput, c *ResourceConfig) (*ResourceConfig, error) { - count++ - _, set := c.Config["from_input"] - - if count == 1 { - if set { - return nil, errors.New("from_input should not be set") - } - c.Config["from_input"] = "x" - } - - if count > 1 && !set { - return nil, errors.New("from_input should be set") - } - - return c, nil - }*/ - if diags := ctx.Input(InputModeStd); diags.HasErrors() { t.Fatalf("input errors: %s", diags.Err()) } @@ -202,7 +197,14 @@ func TestContext2Input_providerId(t *testing.T) { }, }, ResourceTypes: map[string]*configschema.Block{ - "aws_instance": {}, + "aws_instance": { + Attributes: map[string]*configschema.Attribute{ + "id": { + Type: cty.String, + Computed: true, + }, + }, + }, }, } diff --git a/terraform/context_plan_test.go b/terraform/context_plan_test.go index 52d5b4df3..a1c6258df 100644 --- a/terraform/context_plan_test.go +++ b/terraform/context_plan_test.go @@ -91,7 +91,7 @@ func TestContext2Plan_createBefore_deposed(t *testing.T) { mustResourceInstanceAddr("aws_instance.foo").Resource, &states.ResourceInstanceObjectSrc{ Status: states.ObjectReady, - AttrsJSON: []byte(`{"id":"baz"}`), + AttrsJSON: []byte(`{"id":"baz","type":"aws_instance"}`), }, mustProviderConfig(`provider["registry.terraform.io/hashicorp/aws"]`), ) @@ -123,6 +123,7 @@ func TestContext2Plan_createBefore_deposed(t *testing.T) { aws_instance.foo: (1 deposed) ID = baz provider = provider["registry.terraform.io/hashicorp/aws"] + type = aws_instance Deposed ID 1 = foo`) if ctx.State().String() != expectedState { @@ -171,7 +172,10 @@ func TestContext2Plan_createBefore_deposed(t *testing.T) { } // the existing instance should only have an unchanged id - expected, err := schema.CoerceValue(cty.ObjectVal(map[string]cty.Value{"id": cty.StringVal("baz")})) + expected, err := schema.CoerceValue(cty.ObjectVal(map[string]cty.Value{ + "id": cty.StringVal("baz"), + "type": cty.StringVal("aws_instance"), + })) if err != nil { t.Fatal(err) } @@ -226,11 +230,9 @@ func TestContext2Plan_createBefore_maintainRoot(t *testing.T) { func TestContext2Plan_emptyDiff(t *testing.T) { m := testModule(t, "plan-empty") p := testProvider("aws") - p.DiffFn = func( - info *InstanceInfo, - s *InstanceState, - c *ResourceConfig) (*InstanceDiff, error) { - return nil, nil + p.DiffFn = func(req providers.PlanResourceChangeRequest) (resp providers.PlanResourceChangeResponse) { + resp.PlannedState = req.ProposedNewState + return resp } ctx := testContext2(t, &ContextOpts{ @@ -304,8 +306,8 @@ func TestContext2Plan_escapedVar(t *testing.T) { expected := objectVal(t, schema, map[string]cty.Value{ "id": cty.UnknownVal(cty.String), "foo": cty.StringVal("bar-${baz}"), - "type": cty.StringVal("aws_instance")}, - ) + "type": cty.UnknownVal(cty.String), + }) checkVals(t, expected, ric.After) } @@ -375,14 +377,14 @@ func TestContext2Plan_modules(t *testing.T) { expectFoo := objectVal(t, schema, map[string]cty.Value{ "id": cty.UnknownVal(cty.String), "foo": cty.StringVal("2"), - "type": cty.StringVal("aws_instance")}, - ) + "type": cty.UnknownVal(cty.String), + }) expectNum := objectVal(t, schema, map[string]cty.Value{ "id": cty.UnknownVal(cty.String), "num": cty.NumberIntVal(2), - "type": cty.StringVal("aws_instance")}, - ) + "type": cty.UnknownVal(cty.String), + }) for _, res := range plan.Changes.Resources { if res.Action != plans.Create { @@ -507,13 +509,14 @@ func TestContext2Plan_moduleCycle(t *testing.T) { switch i := ric.Addr.String(); i { case "aws_instance.b": expected = objectVal(t, schema, map[string]cty.Value{ - "id": cty.UnknownVal(cty.String), + "id": cty.UnknownVal(cty.String), + "type": cty.UnknownVal(cty.String), }) case "aws_instance.c": expected = objectVal(t, schema, map[string]cty.Value{ "id": cty.UnknownVal(cty.String), "some_input": cty.UnknownVal(cty.String), - "type": cty.StringVal("aws_instance"), + "type": cty.UnknownVal(cty.String), }) default: t.Fatal("unknown instance:", i) @@ -554,7 +557,8 @@ func TestContext2Plan_moduleDeadlock(t *testing.T) { } expected := objectVal(t, schema, map[string]cty.Value{ - "id": cty.UnknownVal(cty.String), + "id": cty.UnknownVal(cty.String), + "type": cty.UnknownVal(cty.String), }) switch i := ric.Addr.String(); i { case "module.child.aws_instance.foo[0]": @@ -608,13 +612,13 @@ func TestContext2Plan_moduleInput(t *testing.T) { expected = objectVal(t, schema, map[string]cty.Value{ "id": cty.UnknownVal(cty.String), "foo": cty.StringVal("2"), - "type": cty.StringVal("aws_instance"), + "type": cty.UnknownVal(cty.String), }) case "module.child.aws_instance.foo": expected = objectVal(t, schema, map[string]cty.Value{ "id": cty.UnknownVal(cty.String), "foo": cty.StringVal("42"), - "type": cty.StringVal("aws_instance"), + "type": cty.UnknownVal(cty.String), }) default: t.Fatal("unknown instance:", i) @@ -661,14 +665,14 @@ func TestContext2Plan_moduleInputComputed(t *testing.T) { checkVals(t, objectVal(t, schema, map[string]cty.Value{ "id": cty.UnknownVal(cty.String), "foo": cty.UnknownVal(cty.String), - "type": cty.StringVal("aws_instance"), + "type": cty.UnknownVal(cty.String), "compute": cty.StringVal("foo"), }), ric.After) case "module.child.aws_instance.foo": checkVals(t, objectVal(t, schema, map[string]cty.Value{ "id": cty.UnknownVal(cty.String), "foo": cty.UnknownVal(cty.String), - "type": cty.StringVal("aws_instance"), + "type": cty.UnknownVal(cty.String), }), ric.After) default: t.Fatal("unknown instance:", i) @@ -719,13 +723,13 @@ func TestContext2Plan_moduleInputFromVar(t *testing.T) { checkVals(t, objectVal(t, schema, map[string]cty.Value{ "id": cty.UnknownVal(cty.String), "foo": cty.StringVal("2"), - "type": cty.StringVal("aws_instance"), + "type": cty.UnknownVal(cty.String), }), ric.After) case "module.child.aws_instance.foo": checkVals(t, objectVal(t, schema, map[string]cty.Value{ "id": cty.UnknownVal(cty.String), "foo": cty.StringVal("52"), - "type": cty.StringVal("aws_instance"), + "type": cty.UnknownVal(cty.String), }), ric.After) default: t.Fatal("unknown instance:", i) @@ -858,7 +862,7 @@ func TestContext2Plan_moduleOrphans(t *testing.T) { checkVals(t, objectVal(t, schema, map[string]cty.Value{ "id": cty.UnknownVal(cty.String), "num": cty.NumberIntVal(2), - "type": cty.StringVal("aws_instance"), + "type": cty.UnknownVal(cty.String), }), ric.After) case "module.child.aws_instance.foo": if res.Action != plans.Delete { @@ -893,7 +897,7 @@ func TestContext2Plan_moduleOrphansWithProvisioner(t *testing.T) { mustResourceInstanceAddr("aws_instance.top").Resource, &states.ResourceInstanceObjectSrc{ Status: states.ObjectReady, - AttrsJSON: []byte(`{"id":"top"}`), + AttrsJSON: []byte(`{"id":"top","type":"aws_instance"}`), }, mustProviderConfig(`provider["registry.terraform.io/hashicorp/aws"]`), ) @@ -902,7 +906,7 @@ func TestContext2Plan_moduleOrphansWithProvisioner(t *testing.T) { mustResourceInstanceAddr("aws_instance.foo").Resource, &states.ResourceInstanceObjectSrc{ Status: states.ObjectReady, - AttrsJSON: []byte(`{"id":"baz"}`), + AttrsJSON: []byte(`{"id":"baz","type":"aws_instance"}`), }, mustProviderConfig(`provider["registry.terraform.io/hashicorp/aws"]`), ) @@ -911,7 +915,7 @@ func TestContext2Plan_moduleOrphansWithProvisioner(t *testing.T) { mustResourceInstanceAddr("aws_instance.foo").Resource, &states.ResourceInstanceObjectSrc{ Status: states.ObjectReady, - AttrsJSON: []byte(`{"id":"baz"}`), + AttrsJSON: []byte(`{"id":"baz","type":"aws_instance"}`), }, mustProviderConfig(`provider["registry.terraform.io/hashicorp/aws"]`), ) @@ -967,15 +971,18 @@ func TestContext2Plan_moduleOrphansWithProvisioner(t *testing.T) { expectedState := `aws_instance.top: ID = top provider = provider["registry.terraform.io/hashicorp/aws"] + type = aws_instance module.parent.child1: aws_instance.foo: ID = baz provider = provider["registry.terraform.io/hashicorp/aws"] + type = aws_instance module.parent.child2: aws_instance.foo: ID = baz - provider = provider["registry.terraform.io/hashicorp/aws"]` + provider = provider["registry.terraform.io/hashicorp/aws"] + type = aws_instance` if expectedState != ctx.State().String() { t.Fatalf("\nexpect state:\n%s\n\ngot state:\n%s\n", expectedState, ctx.State().String()) @@ -1016,16 +1023,13 @@ func TestContext2Plan_moduleProviderInherit(t *testing.T) { return nil } - p.DiffFn = func( - info *InstanceInfo, - state *InstanceState, - c *ResourceConfig) (*InstanceDiff, error) { - v, _ := c.Get("from") + p.DiffFn = func(req providers.PlanResourceChangeRequest) (resp providers.PlanResourceChangeResponse) { + from := req.Config.GetAttr("from").AsString() l.Lock() defer l.Unlock() - calls = append(calls, v.(string)) - return testDiffFn(info, state, c) + calls = append(calls, from) + return testDiffFn(req) } return p, nil }, @@ -1084,15 +1088,13 @@ func TestContext2Plan_moduleProviderInheritDeep(t *testing.T) { return nil } - p.DiffFn = func( - info *InstanceInfo, - state *InstanceState, - c *ResourceConfig) (*InstanceDiff, error) { + p.DiffFn = func(req providers.PlanResourceChangeRequest) (resp providers.PlanResourceChangeResponse) { if from != "root" { - return nil, fmt.Errorf("bad resource") + resp.Diagnostics = resp.Diagnostics.Append(fmt.Errorf("bad resource")) + return } - return testDiffFn(info, state, c) + return testDiffFn(req) } return p, nil }, @@ -1271,13 +1273,13 @@ func TestContext2Plan_moduleVar(t *testing.T) { expected = objectVal(t, schema, map[string]cty.Value{ "id": cty.UnknownVal(cty.String), "foo": cty.StringVal("2"), - "type": cty.StringVal("aws_instance"), + "type": cty.UnknownVal(cty.String), }) case "module.child.aws_instance.foo": expected = objectVal(t, schema, map[string]cty.Value{ "id": cty.UnknownVal(cty.String), "num": cty.NumberIntVal(2), - "type": cty.StringVal("aws_instance"), + "type": cty.UnknownVal(cty.String), }) default: t.Fatal("unknown instance:", i) @@ -1374,13 +1376,13 @@ func TestContext2Plan_moduleVarComputed(t *testing.T) { checkVals(t, objectVal(t, schema, map[string]cty.Value{ "id": cty.UnknownVal(cty.String), "foo": cty.UnknownVal(cty.String), - "type": cty.StringVal("aws_instance"), + "type": cty.UnknownVal(cty.String), }), ric.After) case "module.child.aws_instance.foo": checkVals(t, objectVal(t, schema, map[string]cty.Value{ "id": cty.UnknownVal(cty.String), "foo": cty.UnknownVal(cty.String), - "type": cty.StringVal("aws_instance"), + "type": cty.UnknownVal(cty.String), "compute": cty.StringVal("foo"), }), ric.After) default: @@ -1434,7 +1436,7 @@ func TestContext2Plan_preventDestroy_good(t *testing.T) { mustResourceInstanceAddr("aws_instance.foo").Resource, &states.ResourceInstanceObjectSrc{ Status: states.ObjectReady, - AttrsJSON: []byte(`{"id":"i-abc123"}`), + AttrsJSON: []byte(`{"id":"i-abc123","type":"aws_instance"}`), }, mustProviderConfig(`provider["registry.terraform.io/hashicorp/aws"]`), ) @@ -1560,7 +1562,7 @@ func TestContext2Plan_preventDestroy_countGoodNoChange(t *testing.T) { "aws_instance": { Attributes: map[string]*configschema.Attribute{ "current": {Type: cty.String, Optional: true}, - "type": {Type: cty.String, Optional: true}, + "type": {Type: cty.String, Optional: true, Computed: true}, "id": {Type: cty.String, Computed: true}, }, }, @@ -1691,14 +1693,14 @@ func TestContext2Plan_computed(t *testing.T) { checkVals(t, objectVal(t, schema, map[string]cty.Value{ "id": cty.UnknownVal(cty.String), "foo": cty.UnknownVal(cty.String), - "type": cty.StringVal("aws_instance"), + "type": cty.UnknownVal(cty.String), }), ric.After) case "aws_instance.foo": checkVals(t, objectVal(t, schema, map[string]cty.Value{ "id": cty.UnknownVal(cty.String), "foo": cty.UnknownVal(cty.String), "num": cty.NumberIntVal(2), - "type": cty.StringVal("aws_instance"), + "type": cty.UnknownVal(cty.String), "compute": cty.StringVal("foo"), }), ric.After) default: @@ -2075,60 +2077,7 @@ func TestContext2Plan_computedList(t *testing.T) { }, }, } - p.DiffFn = func(info *InstanceInfo, s *InstanceState, c *ResourceConfig) (*InstanceDiff, error) { - diff := &InstanceDiff{ - Attributes: map[string]*ResourceAttrDiff{}, - } - - computedKeys := map[string]bool{} - for _, k := range c.ComputedKeys { - computedKeys[k] = true - } - - compute, _ := c.Raw["compute"].(string) - if compute != "" { - diff.Attributes[compute] = &ResourceAttrDiff{ - Old: "", - New: "", - NewComputed: true, - } - diff.Attributes["compute"] = &ResourceAttrDiff{ - Old: "", - New: compute, - } - } - - fooOld := s.Attributes["foo"] - fooNew, _ := c.Raw["foo"].(string) - if fooOld != fooNew { - diff.Attributes["foo"] = &ResourceAttrDiff{ - Old: fooOld, - New: fooNew, - NewComputed: computedKeys["foo"], - } - } - - numOld := s.Attributes["num"] - numNew, _ := c.Raw["num"].(string) - if numOld != numNew { - diff.Attributes["num"] = &ResourceAttrDiff{ - Old: numOld, - New: numNew, - NewComputed: computedKeys["num"], - } - } - - listOld := s.Attributes["list.#"] - if listOld == "" { - diff.Attributes["list.#"] = &ResourceAttrDiff{ - Old: "", - New: "", - NewComputed: true, - } - } - - return diff, nil - } + p.DiffFn = testDiffFn ctx := testContext2(t, &ContextOpts{ Config: m, @@ -2161,8 +2110,7 @@ func TestContext2Plan_computedList(t *testing.T) { switch i := ric.Addr.String(); i { case "aws_instance.bar": checkVals(t, objectVal(t, schema, map[string]cty.Value{ - "list": cty.UnknownVal(cty.List(cty.String)), - "foo": cty.UnknownVal(cty.String), + "foo": cty.UnknownVal(cty.String), }), ric.After) case "aws_instance.foo": checkVals(t, objectVal(t, schema, map[string]cty.Value{ @@ -2195,50 +2143,7 @@ func TestContext2Plan_computedMultiIndex(t *testing.T) { }, } - p.DiffFn = func(info *InstanceInfo, s *InstanceState, c *ResourceConfig) (*InstanceDiff, error) { - diff := &InstanceDiff{ - Attributes: map[string]*ResourceAttrDiff{}, - } - - compute, _ := c.Raw["compute"].(string) - if compute != "" { - diff.Attributes[compute] = &ResourceAttrDiff{ - Old: "", - New: "", - NewComputed: true, - } - diff.Attributes["compute"] = &ResourceAttrDiff{ - Old: "", - New: compute, - } - } - - fooOld := s.Attributes["foo"] - fooNew, _ := c.Raw["foo"].(string) - fooComputed := false - for _, k := range c.ComputedKeys { - if k == "foo" { - fooComputed = true - } - } - if fooNew != "" { - diff.Attributes["foo"] = &ResourceAttrDiff{ - Old: fooOld, - New: fooNew, - NewComputed: fooComputed, - } - } - - ipOld := s.Attributes["ip"] - ipComputed := ipOld == "" - diff.Attributes["ip"] = &ResourceAttrDiff{ - Old: ipOld, - New: "", - NewComputed: ipComputed, - } - - return diff, nil - } + p.DiffFn = testDiffFn ctx := testContext2(t, &ContextOpts{ Config: m, @@ -2283,7 +2188,6 @@ func TestContext2Plan_computedMultiIndex(t *testing.T) { }), ric.After) case "aws_instance.bar[0]": checkVals(t, objectVal(t, schema, map[string]cty.Value{ - "ip": cty.UnknownVal(cty.List(cty.String)), "foo": cty.UnknownVal(cty.List(cty.String)), }), ric.After) default: @@ -2329,37 +2233,37 @@ func TestContext2Plan_count(t *testing.T) { checkVals(t, objectVal(t, schema, map[string]cty.Value{ "id": cty.UnknownVal(cty.String), "foo": cty.StringVal("foo,foo,foo,foo,foo"), - "type": cty.StringVal("aws_instance"), + "type": cty.UnknownVal(cty.String), }), ric.After) case "aws_instance.foo[0]": checkVals(t, objectVal(t, schema, map[string]cty.Value{ "id": cty.UnknownVal(cty.String), "foo": cty.StringVal("foo"), - "type": cty.StringVal("aws_instance"), + "type": cty.UnknownVal(cty.String), }), ric.After) case "aws_instance.foo[1]": checkVals(t, objectVal(t, schema, map[string]cty.Value{ "id": cty.UnknownVal(cty.String), "foo": cty.StringVal("foo"), - "type": cty.StringVal("aws_instance"), + "type": cty.UnknownVal(cty.String), }), ric.After) case "aws_instance.foo[2]": checkVals(t, objectVal(t, schema, map[string]cty.Value{ "id": cty.UnknownVal(cty.String), "foo": cty.StringVal("foo"), - "type": cty.StringVal("aws_instance"), + "type": cty.UnknownVal(cty.String), }), ric.After) case "aws_instance.foo[3]": checkVals(t, objectVal(t, schema, map[string]cty.Value{ "id": cty.UnknownVal(cty.String), "foo": cty.StringVal("foo"), - "type": cty.StringVal("aws_instance"), + "type": cty.UnknownVal(cty.String), }), ric.After) case "aws_instance.foo[4]": checkVals(t, objectVal(t, schema, map[string]cty.Value{ "id": cty.UnknownVal(cty.String), "foo": cty.StringVal("foo"), - "type": cty.StringVal("aws_instance"), + "type": cty.UnknownVal(cty.String), }), ric.After) default: t.Fatal("unknown instance:", i) @@ -2439,15 +2343,18 @@ func TestContext2Plan_countModuleStatic(t *testing.T) { switch i := ric.Addr.String(); i { case "module.child.aws_instance.foo[0]": checkVals(t, objectVal(t, schema, map[string]cty.Value{ - "id": cty.UnknownVal(cty.String), + "id": cty.UnknownVal(cty.String), + "type": cty.UnknownVal(cty.String), }), ric.After) case "module.child.aws_instance.foo[1]": checkVals(t, objectVal(t, schema, map[string]cty.Value{ - "id": cty.UnknownVal(cty.String), + "id": cty.UnknownVal(cty.String), + "type": cty.UnknownVal(cty.String), }), ric.After) case "module.child.aws_instance.foo[2]": checkVals(t, objectVal(t, schema, map[string]cty.Value{ - "id": cty.UnknownVal(cty.String), + "id": cty.UnknownVal(cty.String), + "type": cty.UnknownVal(cty.String), }), ric.After) default: t.Fatal("unknown instance:", i) @@ -2490,15 +2397,18 @@ func TestContext2Plan_countModuleStaticGrandchild(t *testing.T) { switch i := ric.Addr.String(); i { case "module.child.module.child.aws_instance.foo[0]": checkVals(t, objectVal(t, schema, map[string]cty.Value{ - "id": cty.UnknownVal(cty.String), + "id": cty.UnknownVal(cty.String), + "type": cty.UnknownVal(cty.String), }), ric.After) case "module.child.module.child.aws_instance.foo[1]": checkVals(t, objectVal(t, schema, map[string]cty.Value{ - "id": cty.UnknownVal(cty.String), + "id": cty.UnknownVal(cty.String), + "type": cty.UnknownVal(cty.String), }), ric.After) case "module.child.module.child.aws_instance.foo[2]": checkVals(t, objectVal(t, schema, map[string]cty.Value{ - "id": cty.UnknownVal(cty.String), + "id": cty.UnknownVal(cty.String), + "type": cty.UnknownVal(cty.String), }), ric.After) default: t.Fatal("unknown instance:", i) @@ -2543,13 +2453,13 @@ func TestContext2Plan_countIndex(t *testing.T) { checkVals(t, objectVal(t, schema, map[string]cty.Value{ "id": cty.UnknownVal(cty.String), "foo": cty.StringVal("0"), - "type": cty.StringVal("aws_instance"), + "type": cty.UnknownVal(cty.String), }), ric.After) case "aws_instance.foo[1]": checkVals(t, objectVal(t, schema, map[string]cty.Value{ "id": cty.UnknownVal(cty.String), "foo": cty.StringVal("1"), - "type": cty.StringVal("aws_instance"), + "type": cty.UnknownVal(cty.String), }), ric.After) default: t.Fatal("unknown instance:", i) @@ -2599,25 +2509,25 @@ func TestContext2Plan_countVar(t *testing.T) { checkVals(t, objectVal(t, schema, map[string]cty.Value{ "id": cty.UnknownVal(cty.String), "foo": cty.StringVal("foo,foo,foo"), - "type": cty.StringVal("aws_instance"), + "type": cty.UnknownVal(cty.String), }), ric.After) case "aws_instance.foo[0]": checkVals(t, objectVal(t, schema, map[string]cty.Value{ "id": cty.UnknownVal(cty.String), "foo": cty.StringVal("foo"), - "type": cty.StringVal("aws_instance"), + "type": cty.UnknownVal(cty.String), }), ric.After) case "aws_instance.foo[1]": checkVals(t, objectVal(t, schema, map[string]cty.Value{ "id": cty.UnknownVal(cty.String), "foo": cty.StringVal("foo"), - "type": cty.StringVal("aws_instance"), + "type": cty.UnknownVal(cty.String), }), ric.After) case "aws_instance.foo[2]": checkVals(t, objectVal(t, schema, map[string]cty.Value{ "id": cty.UnknownVal(cty.String), "foo": cty.StringVal("foo"), - "type": cty.StringVal("aws_instance"), + "type": cty.UnknownVal(cty.String), }), ric.After) default: t.Fatal("unknown instance:", i) @@ -2719,13 +2629,13 @@ func TestContext2Plan_countOneIndex(t *testing.T) { checkVals(t, objectVal(t, schema, map[string]cty.Value{ "id": cty.UnknownVal(cty.String), "foo": cty.StringVal("foo"), - "type": cty.StringVal("aws_instance"), + "type": cty.UnknownVal(cty.String), }), ric.After) case "aws_instance.foo[0]": checkVals(t, objectVal(t, schema, map[string]cty.Value{ "id": cty.UnknownVal(cty.String), "foo": cty.StringVal("foo"), - "type": cty.StringVal("aws_instance"), + "type": cty.UnknownVal(cty.String), }), ric.After) default: t.Fatal("unknown instance:", i) @@ -2799,7 +2709,7 @@ func TestContext2Plan_countDecreaseToOne(t *testing.T) { checkVals(t, objectVal(t, schema, map[string]cty.Value{ "id": cty.UnknownVal(cty.String), "foo": cty.StringVal("bar"), - "type": cty.StringVal("aws_instance"), + "type": cty.UnknownVal(cty.String), }), ric.After) case "aws_instance.foo": if res.Action != plans.NoOp { @@ -2885,7 +2795,7 @@ func TestContext2Plan_countIncreaseFromNotSet(t *testing.T) { checkVals(t, objectVal(t, schema, map[string]cty.Value{ "id": cty.UnknownVal(cty.String), "foo": cty.StringVal("bar"), - "type": cty.StringVal("aws_instance"), + "type": cty.UnknownVal(cty.String), }), ric.After) case "aws_instance.foo[0]": if res.Action != plans.NoOp { @@ -2898,7 +2808,7 @@ func TestContext2Plan_countIncreaseFromNotSet(t *testing.T) { checkVals(t, objectVal(t, schema, map[string]cty.Value{ "id": cty.UnknownVal(cty.String), "foo": cty.StringVal("foo"), - "type": cty.StringVal("aws_instance"), + "type": cty.UnknownVal(cty.String), }), ric.After) case "aws_instance.foo[2]": if res.Action != plans.Create { @@ -2907,7 +2817,7 @@ func TestContext2Plan_countIncreaseFromNotSet(t *testing.T) { checkVals(t, objectVal(t, schema, map[string]cty.Value{ "id": cty.UnknownVal(cty.String), "foo": cty.StringVal("foo"), - "type": cty.StringVal("aws_instance"), + "type": cty.UnknownVal(cty.String), }), ric.After) default: t.Fatal("unknown instance:", i) @@ -2964,7 +2874,7 @@ func TestContext2Plan_countIncreaseFromOne(t *testing.T) { checkVals(t, objectVal(t, schema, map[string]cty.Value{ "id": cty.UnknownVal(cty.String), "foo": cty.StringVal("bar"), - "type": cty.StringVal("aws_instance"), + "type": cty.UnknownVal(cty.String), }), ric.After) case "aws_instance.foo[0]": if res.Action != plans.NoOp { @@ -2977,7 +2887,7 @@ func TestContext2Plan_countIncreaseFromOne(t *testing.T) { checkVals(t, objectVal(t, schema, map[string]cty.Value{ "id": cty.UnknownVal(cty.String), "foo": cty.StringVal("foo"), - "type": cty.StringVal("aws_instance"), + "type": cty.UnknownVal(cty.String), }), ric.After) case "aws_instance.foo[2]": if res.Action != plans.Create { @@ -2986,7 +2896,7 @@ func TestContext2Plan_countIncreaseFromOne(t *testing.T) { checkVals(t, objectVal(t, schema, map[string]cty.Value{ "id": cty.UnknownVal(cty.String), "foo": cty.StringVal("foo"), - "type": cty.StringVal("aws_instance"), + "type": cty.UnknownVal(cty.String), }), ric.After) default: t.Fatal("unknown instance:", i) @@ -3057,7 +2967,7 @@ func TestContext2Plan_countIncreaseFromOneCorrupted(t *testing.T) { checkVals(t, objectVal(t, schema, map[string]cty.Value{ "id": cty.UnknownVal(cty.String), "foo": cty.StringVal("bar"), - "type": cty.StringVal("aws_instance"), + "type": cty.UnknownVal(cty.String), }), ric.After) case "aws_instance.foo": if res.Action != plans.Delete { @@ -3074,7 +2984,7 @@ func TestContext2Plan_countIncreaseFromOneCorrupted(t *testing.T) { checkVals(t, objectVal(t, schema, map[string]cty.Value{ "id": cty.UnknownVal(cty.String), "foo": cty.StringVal("foo"), - "type": cty.StringVal("aws_instance"), + "type": cty.UnknownVal(cty.String), }), ric.After) case "aws_instance.foo[2]": if res.Action != plans.Create { @@ -3083,7 +2993,7 @@ func TestContext2Plan_countIncreaseFromOneCorrupted(t *testing.T) { checkVals(t, objectVal(t, schema, map[string]cty.Value{ "id": cty.UnknownVal(cty.String), "foo": cty.StringVal("foo"), - "type": cty.StringVal("aws_instance"), + "type": cty.UnknownVal(cty.String), }), ric.After) default: t.Fatal("unknown instance:", i) @@ -3595,7 +3505,7 @@ func TestContext2Plan_diffVar(t *testing.T) { mustResourceInstanceAddr("aws_instance.foo").Resource, &states.ResourceInstanceObjectSrc{ Status: states.ObjectReady, - AttrsJSON: []byte(`{"id":"bar","num":"2"}`), + AttrsJSON: []byte(`{"id":"bar","num":"2","type":"aws_instance"}`), }, mustProviderConfig(`provider["registry.terraform.io/hashicorp/aws"]`), ) @@ -3608,23 +3518,7 @@ func TestContext2Plan_diffVar(t *testing.T) { State: state, }) - p.DiffFn = func( - info *InstanceInfo, - s *InstanceState, - c *ResourceConfig) (*InstanceDiff, error) { - if s.ID != "bar" { - return testDiffFn(info, s, c) - } - - return &InstanceDiff{ - Attributes: map[string]*ResourceAttrDiff{ - "num": &ResourceAttrDiff{ - Old: "2", - New: "3", - }, - }, - }, nil - } + p.DiffFn = testDiffFn plan, diags := ctx.Plan() if diags.HasErrors() { @@ -3652,19 +3546,21 @@ func TestContext2Plan_diffVar(t *testing.T) { checkVals(t, objectVal(t, schema, map[string]cty.Value{ "id": cty.UnknownVal(cty.String), "num": cty.NumberIntVal(3), - "type": cty.StringVal("aws_instance"), + "type": cty.UnknownVal(cty.String), }), ric.After) case "aws_instance.foo": if res.Action != plans.Update { t.Fatalf("resource %s should be updated", i) } checkVals(t, objectVal(t, schema, map[string]cty.Value{ - "id": cty.StringVal("bar"), - "num": cty.NumberIntVal(2), + "id": cty.StringVal("bar"), + "num": cty.NumberIntVal(2), + "type": cty.StringVal("aws_instance"), }), ric.Before) checkVals(t, objectVal(t, schema, map[string]cty.Value{ - "id": cty.StringVal("bar"), - "num": cty.NumberIntVal(3), + "id": cty.StringVal("bar"), + "num": cty.NumberIntVal(3), + "type": cty.StringVal("aws_instance"), }), ric.After) default: t.Fatal("unknown instance:", i) @@ -3775,7 +3671,7 @@ func TestContext2Plan_orphan(t *testing.T) { checkVals(t, objectVal(t, schema, map[string]cty.Value{ "id": cty.UnknownVal(cty.String), "num": cty.NumberIntVal(2), - "type": cty.StringVal("aws_instance"), + "type": cty.UnknownVal(cty.String), }), ric.After) default: t.Fatal("unknown instance:", i) @@ -3853,7 +3749,7 @@ func TestContext2Plan_state(t *testing.T) { checkVals(t, objectVal(t, schema, map[string]cty.Value{ "id": cty.UnknownVal(cty.String), "foo": cty.StringVal("2"), - "type": cty.StringVal("aws_instance"), + "type": cty.UnknownVal(cty.String), }), ric.After) case "aws_instance.foo": if res.Action != plans.Update { @@ -3867,7 +3763,7 @@ func TestContext2Plan_state(t *testing.T) { checkVals(t, objectVal(t, schema, map[string]cty.Value{ "id": cty.StringVal("bar"), "num": cty.NumberIntVal(2), - "type": cty.StringVal("aws_instance"), + "type": cty.UnknownVal(cty.String), }), ric.After) default: t.Fatal("unknown instance:", i) @@ -3885,7 +3781,7 @@ func TestContext2Plan_taint(t *testing.T) { mustResourceInstanceAddr("aws_instance.foo").Resource, &states.ResourceInstanceObjectSrc{ Status: states.ObjectReady, - AttrsJSON: []byte(`{"id":"bar","num":"2"}`), + AttrsJSON: []byte(`{"id":"bar","num":"2","type":"aws_instance"}`), }, mustProviderConfig(`provider["registry.terraform.io/hashicorp/aws"]`), ) @@ -3932,7 +3828,7 @@ func TestContext2Plan_taint(t *testing.T) { checkVals(t, objectVal(t, schema, map[string]cty.Value{ "id": cty.UnknownVal(cty.String), "foo": cty.StringVal("2"), - "type": cty.StringVal("aws_instance"), + "type": cty.UnknownVal(cty.String), }), ric.After) case "aws_instance.foo": if res.Action != plans.NoOp { @@ -4011,7 +3907,7 @@ func TestContext2Plan_taintIgnoreChanges(t *testing.T) { checkVals(t, objectVal(t, schema, map[string]cty.Value{ "id": cty.UnknownVal(cty.String), "vars": cty.StringVal("foo"), - "type": cty.StringVal("aws_instance"), + "type": cty.UnknownVal(cty.String), }), ric.After) default: t.Fatal("unknown instance:", i) @@ -4030,7 +3926,7 @@ func TestContext2Plan_taintDestroyInterpolatedCountRace(t *testing.T) { mustResourceInstanceAddr("aws_instance.foo[0]").Resource, &states.ResourceInstanceObjectSrc{ Status: states.ObjectTainted, - AttrsJSON: []byte(`{"id":"bar"}`), + AttrsJSON: []byte(`{"id":"bar","type":"aws_instance"}`), }, mustProviderConfig(`provider["registry.terraform.io/hashicorp/aws"]`), ) @@ -4038,7 +3934,7 @@ func TestContext2Plan_taintDestroyInterpolatedCountRace(t *testing.T) { mustResourceInstanceAddr("aws_instance.foo[1]").Resource, &states.ResourceInstanceObjectSrc{ Status: states.ObjectReady, - AttrsJSON: []byte(`{"id":"bar"}`), + AttrsJSON: []byte(`{"id":"bar","type":"aws_instance"}`), }, mustProviderConfig(`provider["registry.terraform.io/hashicorp/aws"]`), ) @@ -4046,7 +3942,7 @@ func TestContext2Plan_taintDestroyInterpolatedCountRace(t *testing.T) { mustResourceInstanceAddr("aws_instance.foo[2]").Resource, &states.ResourceInstanceObjectSrc{ Status: states.ObjectReady, - AttrsJSON: []byte(`{"id":"bar"}`), + AttrsJSON: []byte(`{"id":"bar","type":"aws_instance"}`), }, mustProviderConfig(`provider["registry.terraform.io/hashicorp/aws"]`), ) @@ -4084,10 +3980,12 @@ func TestContext2Plan_taintDestroyInterpolatedCountRace(t *testing.T) { t.Fatalf("resource %s should be replaced, not %s", i, res.Action) } checkVals(t, objectVal(t, schema, map[string]cty.Value{ - "id": cty.StringVal("bar"), + "id": cty.StringVal("bar"), + "type": cty.StringVal("aws_instance"), }), ric.Before) checkVals(t, objectVal(t, schema, map[string]cty.Value{ - "id": cty.UnknownVal(cty.String), + "id": cty.UnknownVal(cty.String), + "type": cty.UnknownVal(cty.String), }), ric.After) case "aws_instance.foo[1]", "aws_instance.foo[2]": if res.Action != plans.NoOp { @@ -4141,7 +4039,7 @@ func TestContext2Plan_targeted(t *testing.T) { checkVals(t, objectVal(t, schema, map[string]cty.Value{ "id": cty.UnknownVal(cty.String), "num": cty.NumberIntVal(2), - "type": cty.StringVal("aws_instance"), + "type": cty.UnknownVal(cty.String), }), ric.After) default: t.Fatal("unknown instance:", i) @@ -4189,13 +4087,13 @@ func TestContext2Plan_targetedCrossModule(t *testing.T) { checkVals(t, objectVal(t, schema, map[string]cty.Value{ "id": cty.UnknownVal(cty.String), "foo": cty.StringVal("bar"), - "type": cty.StringVal("aws_instance"), + "type": cty.UnknownVal(cty.String), }), ric.After) case "module.B.aws_instance.bar": checkVals(t, objectVal(t, schema, map[string]cty.Value{ "id": cty.UnknownVal(cty.String), "foo": cty.UnknownVal(cty.String), - "type": cty.StringVal("aws_instance"), + "type": cty.UnknownVal(cty.String), }), ric.After) default: t.Fatal("unknown instance:", i) @@ -4425,13 +4323,14 @@ func TestContext2Plan_targetedModuleUntargetedVariable(t *testing.T) { switch i := ric.Addr.String(); i { case "aws_instance.blue": checkVals(t, objectVal(t, schema, map[string]cty.Value{ - "id": cty.UnknownVal(cty.String), + "id": cty.UnknownVal(cty.String), + "type": cty.UnknownVal(cty.String), }), ric.After) case "module.blue_mod.aws_instance.mod": checkVals(t, objectVal(t, schema, map[string]cty.Value{ "id": cty.UnknownVal(cty.String), "value": cty.UnknownVal(cty.String), - "type": cty.StringVal("aws_instance"), + "type": cty.UnknownVal(cty.String), }), ric.After) default: t.Fatal("unknown instance:", i) @@ -4484,7 +4383,7 @@ func TestContext2Plan_targetedOverTen(t *testing.T) { for i := 0; i < 13; i++ { key := fmt.Sprintf("aws_instance.foo[%d]", i) id := fmt.Sprintf("i-abc%d", i) - attrs := fmt.Sprintf("{\"id\":\"%s\"}", id) + attrs := fmt.Sprintf(`{"id":"%s","type":"aws_instance"}`, id) root.SetResourceInstanceCurrent( mustResourceInstanceAddr(key).Resource, @@ -4590,7 +4489,7 @@ func TestContext2Plan_ignoreChanges(t *testing.T) { mustResourceInstanceAddr("aws_instance.foo").Resource, &states.ResourceInstanceObjectSrc{ Status: states.ObjectReady, - AttrsJSON: []byte(`{"id":"bar","ami":"ami-abcd1234"}`), + AttrsJSON: []byte(`{"id":"bar","ami":"ami-abcd1234","type":"aws_instance"}`), }, mustProviderConfig(`provider["registry.terraform.io/hashicorp/aws"]`), ) @@ -4632,8 +4531,9 @@ func TestContext2Plan_ignoreChanges(t *testing.T) { } checkVals(t, objectVal(t, schema, map[string]cty.Value{ - "id": cty.StringVal("bar"), - "ami": cty.StringVal("ami-abcd1234"), + "id": cty.StringVal("bar"), + "ami": cty.StringVal("ami-abcd1234"), + "type": cty.StringVal("aws_instance"), }), ric.After) } @@ -4648,7 +4548,7 @@ func TestContext2Plan_ignoreChangesWildcard(t *testing.T) { mustResourceInstanceAddr("aws_instance.foo").Resource, &states.ResourceInstanceObjectSrc{ Status: states.ObjectReady, - AttrsJSON: []byte(`{"id":"bar","ami":"ami-abcd1234","instance":"t2.micro"}`), + AttrsJSON: []byte(`{"id":"bar","ami":"ami-abcd1234","instance":"t2.micro","type":"aws_instance"}`), }, mustProviderConfig(`provider["registry.terraform.io/hashicorp/aws"]`), ) @@ -4712,7 +4612,7 @@ func TestContext2Plan_ignoreChangesInMap(t *testing.T) { }.Instance(addrs.NoKey).Absolute(addrs.RootModuleInstance), &states.ResourceInstanceObjectSrc{ Status: states.ObjectReady, - AttrsJSON: []byte(`{"tags":{"ignored":"from state","other":"from state"}}`), + AttrsJSON: []byte(`{"id":"foo","tags":{"ignored":"from state","other":"from state"},"type":"aws_instance"}`), }, addrs.AbsProviderConfig{ Provider: addrs.NewDefaultProvider("test"), @@ -4777,28 +4677,19 @@ func TestContext2Plan_moduleMapLiteral(t *testing.T) { }, } p.ApplyFn = testApplyFn - p.DiffFn = func(i *InstanceInfo, s *InstanceState, c *ResourceConfig) (*InstanceDiff, error) { - // Here we verify that both the populated and empty map literals made it - // through to the resource attributes - val, _ := c.Get("tags") - m, ok := val.(map[string]interface{}) - if !ok { - t.Fatalf("Tags attr not map: %#v", val) - } - if m["foo"] != "bar" { + p.DiffFn = func(req providers.PlanResourceChangeRequest) (resp providers.PlanResourceChangeResponse) { + s := req.ProposedNewState.AsValueMap() + m := s["tags"].AsValueMap() + + if m["foo"].AsString() != "bar" { t.Fatalf("Bad value in tags attr: %#v", m) } - { - val, _ := c.Get("meta") - m, ok := val.(map[string]interface{}) - if !ok { - t.Fatalf("Meta attr not map: %#v", val) - } - if len(m) != 0 { - t.Fatalf("Meta attr not empty: %#v", val) - } + + meta := s["meta"].AsValueMap() + if len(meta) != 0 { + t.Fatalf("Meta attr not empty: %#v", meta) } - return nil, nil + return testDiffFn(req) } ctx := testContext2(t, &ContextOpts{ Config: m, @@ -4830,19 +4721,18 @@ func TestContext2Plan_computedValueInMap(t *testing.T) { }, }, } - p.DiffFn = func(info *InstanceInfo, state *InstanceState, c *ResourceConfig) (*InstanceDiff, error) { - switch info.Type { - case "aws_computed_source": - return &InstanceDiff{ - Attributes: map[string]*ResourceAttrDiff{ - "computed_read_only": &ResourceAttrDiff{ - NewComputed: true, - }, - }, - }, nil + p.DiffFn = testDiffFn + p.DiffFn = func(req providers.PlanResourceChangeRequest) (resp providers.PlanResourceChangeResponse) { + resp = testDiffFn(req) + + if req.TypeName != "aws_computed_source" { + return } - return testDiffFn(info, state, c) + planned := resp.PlannedState.AsValueMap() + planned["computed_read_only"] = cty.UnknownVal(cty.String) + resp.PlannedState = cty.ObjectVal(planned) + return resp } ctx := testContext2(t, &ContextOpts{ @@ -5200,7 +5090,7 @@ func TestContext2Plan_resourceNestedCount(t *testing.T) { mustResourceInstanceAddr("aws_instance.foo[0]").Resource, &states.ResourceInstanceObjectSrc{ Status: states.ObjectReady, - AttrsJSON: []byte(`{"id":"foo0"}`), + AttrsJSON: []byte(`{"id":"foo0","type":"aws_instance"}`), }, mustProviderConfig(`provider["registry.terraform.io/hashicorp/aws"]`), ) @@ -5208,7 +5098,7 @@ func TestContext2Plan_resourceNestedCount(t *testing.T) { mustResourceInstanceAddr("aws_instance.foo[1]").Resource, &states.ResourceInstanceObjectSrc{ Status: states.ObjectReady, - AttrsJSON: []byte(`{"id":"foo1"}`), + AttrsJSON: []byte(`{"id":"foo1","type":"aws_instance"}`), }, mustProviderConfig(`provider["registry.terraform.io/hashicorp/aws"]`), ) @@ -5216,7 +5106,7 @@ func TestContext2Plan_resourceNestedCount(t *testing.T) { mustResourceInstanceAddr("aws_instance.bar[0]").Resource, &states.ResourceInstanceObjectSrc{ Status: states.ObjectReady, - AttrsJSON: []byte(`{"id":"bar0"}`), + AttrsJSON: []byte(`{"id":"bar0","type":"aws_instance"}`), Dependencies: []addrs.ConfigResource{mustConfigResourceAddr("aws_instance.foo")}, }, mustProviderConfig(`provider["registry.terraform.io/hashicorp/aws"]`), @@ -5225,7 +5115,7 @@ func TestContext2Plan_resourceNestedCount(t *testing.T) { mustResourceInstanceAddr("aws_instance.bar[1]").Resource, &states.ResourceInstanceObjectSrc{ Status: states.ObjectReady, - AttrsJSON: []byte(`{"id":"bar1"}`), + AttrsJSON: []byte(`{"id":"bar1","type":"aws_instance"}`), Dependencies: []addrs.ConfigResource{mustConfigResourceAddr("aws_instance.foo")}, }, mustProviderConfig(`provider["registry.terraform.io/hashicorp/aws"]`), @@ -5234,7 +5124,7 @@ func TestContext2Plan_resourceNestedCount(t *testing.T) { mustResourceInstanceAddr("aws_instance.baz[0]").Resource, &states.ResourceInstanceObjectSrc{ Status: states.ObjectReady, - AttrsJSON: []byte(`{"id":"baz0"}`), + AttrsJSON: []byte(`{"id":"baz0","type":"aws_instance"}`), Dependencies: []addrs.ConfigResource{mustConfigResourceAddr("aws_instance.bar")}, }, mustProviderConfig(`provider["registry.terraform.io/hashicorp/aws"]`), @@ -5243,7 +5133,7 @@ func TestContext2Plan_resourceNestedCount(t *testing.T) { mustResourceInstanceAddr("aws_instance.baz[1]").Resource, &states.ResourceInstanceObjectSrc{ Status: states.ObjectReady, - AttrsJSON: []byte(`{"id":"baz1"}`), + AttrsJSON: []byte(`{"id":"baz1","type":"aws_instance"}`), Dependencies: []addrs.ConfigResource{mustConfigResourceAddr("aws_instance.bar")}, }, mustProviderConfig(`provider["registry.terraform.io/hashicorp/aws"]`), @@ -5273,7 +5163,7 @@ func TestContext2Plan_resourceNestedCount(t *testing.T) { for _, res := range plan.Changes.Resources { if res.Action != plans.NoOp { - t.Fatalf("resource %s should now change, plan returned %s", res.Addr, res.Action) + t.Fatalf("resource %s should not change, plan returned %s", res.Addr, res.Action) } } } @@ -5295,38 +5185,21 @@ func TestContext2Plan_computedAttrRefTypeMismatch(t *testing.T) { Diagnostics: diags, } } - p.DiffFn = func( - info *InstanceInfo, - state *InstanceState, - c *ResourceConfig) (*InstanceDiff, error) { - switch info.Type { - case "aws_ami_list": - // Emulate a diff that says "we'll create this list and ids will be populated" - return &InstanceDiff{ - Attributes: map[string]*ResourceAttrDiff{ - "ids.#": &ResourceAttrDiff{NewComputed: true}, - }, - }, nil - case "aws_instance": - // If we get to the diff for instance, we should be able to assume types - ami, _ := c.Get("ami") - _ = ami.(string) - } - return nil, nil - } - p.ApplyFn = func(info *InstanceInfo, s *InstanceState, d *InstanceDiff) (*InstanceState, error) { - if info.Type != "aws_ami_list" { - t.Fatalf("Reached apply for unexpected resource type! %s", info.Type) + p.DiffFn = testDiffFn + p.ApplyFn = func(req providers.ApplyResourceChangeRequest) (resp providers.ApplyResourceChangeResponse) { + if req.TypeName != "aws_ami_list" { + t.Fatalf("Reached apply for unexpected resource type! %s", req.TypeName) } // Pretend like we make a thing and the computed list "ids" is populated - return &InstanceState{ - ID: "someid", - Attributes: map[string]string{ - "ids.#": "2", - "ids.0": "ami-abc123", - "ids.1": "ami-bcd345", - }, - }, nil + s := req.PlannedState.AsValueMap() + s["id"] = cty.StringVal("someid") + s["ids"] = cty.ListVal([]cty.Value{ + cty.StringVal("ami-abc123"), + cty.StringVal("ami-bcd345"), + }) + + resp.NewState = cty.ObjectVal(s) + return } ctx := testContext2(t, &ContextOpts{ Config: m, @@ -5877,7 +5750,7 @@ resource "aws_instance" "foo" { mustResourceInstanceAddr("aws_instance.foo").Resource, &states.ResourceInstanceObjectSrc{ Status: states.ObjectReady, - AttrsJSON: []byte(`{"id":"child"}`), + AttrsJSON: []byte(`{"id":"child","type":"aws_instance"}`), }, mustProviderConfig(`provider["registry.terraform.io/hashicorp/aws"]`), ) @@ -5885,7 +5758,7 @@ resource "aws_instance" "foo" { mustResourceInstanceAddr("aws_instance.foo").Resource, &states.ResourceInstanceObjectSrc{ Status: states.ObjectReady, - AttrsJSON: []byte(`{"id":"child"}`), + AttrsJSON: []byte(`{"id":"child","type":"aws_instance"}`), }, mustProviderConfig(`provider["registry.terraform.io/hashicorp/aws"]`), ) @@ -6288,7 +6161,7 @@ func TestContext2Plan_targetedModuleInstance(t *testing.T) { checkVals(t, objectVal(t, schema, map[string]cty.Value{ "id": cty.UnknownVal(cty.String), "num": cty.NumberIntVal(2), - "type": cty.StringVal("aws_instance"), + "type": cty.UnknownVal(cty.String), }), ric.After) default: t.Fatal("unknown instance:", i) @@ -6399,7 +6272,7 @@ resource "test_instance" "a" { mustResourceInstanceAddr("test_instance.a").Resource, &states.ResourceInstanceObjectSrc{ Status: states.ObjectReady, - AttrsJSON: []byte(`{"id":"a"}`), + AttrsJSON: []byte(`{"id":"a","type":"test_instance"}`), Dependencies: []addrs.ConfigResource{}, }, mustProviderConfig(`provider["registry.terraform.io/hashicorp/test"]`), diff --git a/terraform/context_refresh_test.go b/terraform/context_refresh_test.go index c38084ab4..f91627437 100644 --- a/terraform/context_refresh_test.go +++ b/terraform/context_refresh_test.go @@ -726,6 +726,7 @@ func TestContext2Refresh_output(t *testing.T) { "foo": { Type: cty.String, Optional: true, + Computed: true, }, }, }, diff --git a/terraform/context_test.go b/terraform/context_test.go index c0e33d7fd..dea83a790 100644 --- a/terraform/context_test.go +++ b/terraform/context_test.go @@ -5,16 +5,13 @@ import ( "bytes" "fmt" "io/ioutil" - "log" "os" "path/filepath" "sort" - "strconv" "strings" "testing" "time" - "github.com/davecgh/go-spew/spew" "github.com/google/go-cmp/cmp" "github.com/google/go-cmp/cmp/cmpopts" "github.com/hashicorp/go-version" @@ -22,7 +19,6 @@ import ( "github.com/hashicorp/terraform/configs/configload" "github.com/hashicorp/terraform/configs/configschema" "github.com/hashicorp/terraform/configs/hcl2shim" - "github.com/hashicorp/terraform/flatmap" "github.com/hashicorp/terraform/plans" "github.com/hashicorp/terraform/plans/planfile" "github.com/hashicorp/terraform/providers" @@ -132,300 +128,98 @@ func testContext2(t *testing.T, opts *ContextOpts) *Context { return ctx } -func testDataApplyFn( - info *InstanceInfo, - d *InstanceDiff) (*InstanceState, error) { - return testApplyFn(info, new(InstanceState), d) -} - -func testDataDiffFn( - info *InstanceInfo, - c *ResourceConfig) (*InstanceDiff, error) { - return testDiffFn(info, new(InstanceState), c) -} - -func testApplyFn( - info *InstanceInfo, - s *InstanceState, - d *InstanceDiff) (*InstanceState, error) { - if d.Destroy { - return nil, nil +func testApplyFn(req providers.ApplyResourceChangeRequest) (resp providers.ApplyResourceChangeResponse) { + resp.NewState = req.PlannedState + if req.PlannedState.IsNull() { + resp.NewState = cty.NullVal(req.PriorState.Type()) + return } - // find the OLD id, which is probably in the ID field for now, but eventually - // ID should only be in one place. - id := s.ID - if id == "" { - id = s.Attributes["id"] - } - if idAttr, ok := d.Attributes["id"]; ok && !idAttr.NewComputed { - id = idAttr.New + planned := req.PlannedState.AsValueMap() + if planned == nil { + planned = map[string]cty.Value{} } - if id == "" || id == hcl2shim.UnknownVariableValue { - id = "foo" + id, ok := planned["id"] + if !ok || id.IsNull() || !id.IsKnown() { + planned["id"] = cty.StringVal("foo") } - result := &InstanceState{ - ID: id, - Attributes: make(map[string]string), + // our default schema has a computed "type" attr + if ty, ok := planned["type"]; ok && !ty.IsNull() { + planned["type"] = cty.StringVal(req.TypeName) } - // Copy all the prior attributes - for k, v := range s.Attributes { - result.Attributes[k] = v + if cmp, ok := planned["compute"]; ok && !cmp.IsNull() { + computed := cmp.AsString() + if val, ok := planned[computed]; ok && !val.IsKnown() { + planned[computed] = cty.StringVal("computed_value") + } } - if d != nil { - result = result.MergeDiff(d) - } + for k, v := range planned { + if k == "unknown" { + // "unknown" should cause an error + continue + } - // The id attribute always matches ID for the sake of this mock - // implementation, since it's following the pre-0.12 assumptions where - // these two were treated as synonyms. - result.Attributes["id"] = result.ID - return result, nil -} - -func testDiffFn( - info *InstanceInfo, - s *InstanceState, - c *ResourceConfig) (*InstanceDiff, error) { - diff := new(InstanceDiff) - diff.Attributes = make(map[string]*ResourceAttrDiff) - - defer func() { - log.Printf("[TRACE] testDiffFn: generated diff is:\n%s", spew.Sdump(diff)) - }() - - if s != nil { - diff.DestroyTainted = s.Tainted - } - - for k, v := range c.Raw { - // Ignore __-prefixed keys since they're used for magic - if k[0] == '_' && k[1] == '_' { - // ...though we do still need to include them in the diff, to - // simulate normal provider behaviors. - old := s.Attributes[k] - var new string - switch tv := v.(type) { - case string: - new = tv + if !v.IsKnown() { + switch k { + case "type": + planned[k] = cty.StringVal(req.TypeName) default: - new = fmt.Sprintf("%#v", v) - } - if new == hcl2shim.UnknownVariableValue { - diff.Attributes[k] = &ResourceAttrDiff{ - Old: old, - New: "", - NewComputed: true, - } - } else { - diff.Attributes[k] = &ResourceAttrDiff{ - Old: old, - New: new, - } - } - continue - } - - if k == "nil" { - return nil, nil - } - - // This key is used for other purposes - if k == "compute_value" { - if old, ok := s.Attributes["compute_value"]; !ok || old != v.(string) { - diff.Attributes["compute_value"] = &ResourceAttrDiff{ - Old: old, - New: v.(string), - } - } - continue - } - - if k == "compute" { - // The "compute" value itself must be included in the diff if it - // has changed since prior. - if old, ok := s.Attributes["compute"]; !ok || old != v.(string) { - diff.Attributes["compute"] = &ResourceAttrDiff{ - Old: old, - New: v.(string), - } - } - - if v == hcl2shim.UnknownVariableValue || v == "unknown" { - // compute wasn't set in the config, so don't use these - // computed values from the schema. - delete(c.Raw, k) - delete(c.Raw, "compute_value") - - // we need to remove this from the list of ComputedKeys too, - // since it would get re-added to the diff further down - newComputed := make([]string, 0, len(c.ComputedKeys)) - for _, ck := range c.ComputedKeys { - if ck == "compute" || ck == "compute_value" { - continue - } - newComputed = append(newComputed, ck) - } - c.ComputedKeys = newComputed - - if v == "unknown" { - diff.Attributes["unknown"] = &ResourceAttrDiff{ - Old: "", - New: "", - NewComputed: true, - } - - c.ComputedKeys = append(c.ComputedKeys, "unknown") - } - - continue - } - - attrDiff := &ResourceAttrDiff{ - Old: "", - New: "", - NewComputed: true, - } - - if cv, ok := c.Config["compute_value"]; ok { - if cv.(string) == "1" { - attrDiff.NewComputed = false - attrDiff.New = fmt.Sprintf("computed_%s", v.(string)) - } - } - - diff.Attributes[v.(string)] = attrDiff - continue - } - - // If this key is not computed, then look it up in the - // cleaned config. - found := false - for _, ck := range c.ComputedKeys { - if ck == k { - found = true - break - } - } - if !found { - v = c.Config[k] - } - - for k, attrDiff := range testFlatAttrDiffs(k, v) { - // we need to ignore 'id' for now, since it's always inferred to be - // computed. - if k == "id" { - continue - } - - if k == "require_new" { - attrDiff.RequiresNew = true - } - if _, ok := c.Raw["__"+k+"_requires_new"]; ok { - attrDiff.RequiresNew = true - } - - if attr, ok := s.Attributes[k]; ok { - attrDiff.Old = attr - } - - diff.Attributes[k] = attrDiff - } - } - - for _, k := range c.ComputedKeys { - if k == "id" { - continue - } - old := "" - if s != nil { - old = s.Attributes[k] - } - diff.Attributes[k] = &ResourceAttrDiff{ - Old: old, - NewComputed: true, - } - } - - // If we recreate this resource because it's tainted, we keep all attrs - if !diff.RequiresNew() { - for k, v := range diff.Attributes { - if v.NewComputed { - continue - } - - old, ok := s.Attributes[k] - if !ok { - continue - } - - if old == v.New { - delete(diff.Attributes, k) + planned[k] = cty.NullVal(v.Type()) } } } - if !diff.Empty() { - diff.Attributes["type"] = &ResourceAttrDiff{ - Old: "", - New: info.Type, - } - if s != nil && s.Attributes != nil { - diff.Attributes["type"].Old = s.Attributes["type"] - } - } - - return diff, nil + resp.NewState = cty.ObjectVal(planned) + return } -// generate ResourceAttrDiffs for nested data structures in tests -func testFlatAttrDiffs(k string, i interface{}) map[string]*ResourceAttrDiff { - diffs := make(map[string]*ResourceAttrDiff) - // check for strings and empty containers first - switch t := i.(type) { - case string: - diffs[k] = &ResourceAttrDiff{New: t} - return diffs - case map[string]interface{}: - if len(t) == 0 { - diffs[k] = &ResourceAttrDiff{New: ""} - return diffs - } - case []interface{}: - if len(t) == 0 { - diffs[k] = &ResourceAttrDiff{New: ""} - return diffs +func testDiffFn(req providers.PlanResourceChangeRequest) (resp providers.PlanResourceChangeResponse) { + var planned map[string]cty.Value + if !req.ProposedNewState.IsNull() { + planned = req.ProposedNewState.AsValueMap() + } + if planned == nil { + planned = map[string]cty.Value{} + } + + // id is always computed for the tests + if id, ok := planned["id"]; ok && id.IsNull() { + planned["id"] = cty.UnknownVal(cty.String) + } + + // the old tests have require_new replace on every plan + if _, ok := planned["require_new"]; ok { + resp.RequiresReplace = append(resp.RequiresReplace, cty.Path{cty.GetAttrStep{Name: "require_new"}}) + } + + for k := range planned { + requiresNewKey := "__" + k + "_requires_new" + _, ok := planned[requiresNewKey] + if ok { + resp.RequiresReplace = append(resp.RequiresReplace, cty.Path{cty.GetAttrStep{Name: requiresNewKey}}) } } - flat := flatmap.Flatten(map[string]interface{}{k: i}) - - for k, v := range flat { - attrDiff := &ResourceAttrDiff{ - Old: "", - New: v, + if v, ok := planned["compute"]; ok && !v.IsNull() { + k := v.AsString() + unknown := cty.UnknownVal(cty.String) + if strings.HasSuffix(k, ".#") { + k = k[:len(k)-2] + unknown = cty.UnknownVal(cty.List(cty.String)) } - diffs[k] = attrDiff + planned[k] = unknown } - // The legacy flatmap-based diff producing done by helper/schema would - // additionally insert a k+".%" key here recording the length of the map, - // which is for some reason not also done by flatmap.Flatten. To make our - // mock shims helper/schema-compatible, we'll just fake that up here. - switch t := i.(type) { - case map[string]interface{}: - attrDiff := &ResourceAttrDiff{ - Old: "", - New: strconv.Itoa(len(t)), - } - diffs[k+".%"] = attrDiff + if t, ok := planned["type"]; ok && t.IsNull() { + planned["type"] = cty.UnknownVal(cty.String) } - return diffs + resp.PlannedState = cty.ObjectVal(planned) + return } func testProvider(prefix string) *MockProvider { diff --git a/terraform/provider_mock.go b/terraform/provider_mock.go index b3d857dbf..f30a4adf8 100644 --- a/terraform/provider_mock.go +++ b/terraform/provider_mock.go @@ -2,7 +2,6 @@ package terraform import ( "encoding/json" - "fmt" "sync" "github.com/zclconf/go-cty/cty" @@ -89,14 +88,12 @@ type MockProvider struct { CloseCalled bool CloseError error - // Legacy callbacks: if these are set, we will shim incoming calls for - // new-style methods to these old-fashioned terraform.ResourceProvider - // mock callbacks, for the benefit of older tests that were written against - // the old mock API. ValidateFn func(c *ResourceConfig) (ws []string, es []error) ConfigureFn func(c *ResourceConfig) error - DiffFn func(info *InstanceInfo, s *InstanceState, c *ResourceConfig) (*InstanceDiff, error) - ApplyFn func(info *InstanceInfo, s *InstanceState, d *InstanceDiff) (*InstanceState, error) + //ValidateFn func(providers.ValidateResourceTypeConfigRequest) providers.ValidateResourceTypeConfigResponse + //ConfigureFn func(providers.ConfigureRequest) providers.ConfigureResponse + DiffFn func(providers.PlanResourceChangeRequest) providers.PlanResourceChangeResponse + ApplyFn func(providers.ApplyResourceChangeRequest) providers.ApplyResourceChangeResponse } func (p *MockProvider) GetSchema() providers.GetSchemaResponse { @@ -297,47 +294,7 @@ func (p *MockProvider) PlanResourceChange(r providers.PlanResourceChangeRequest) p.PlanResourceChangeRequest = r if p.DiffFn != nil { - ps := p.getSchema() - if ps.ResourceTypes == nil || ps.ResourceTypes[r.TypeName].Block == nil { - return providers.PlanResourceChangeResponse{ - Diagnostics: tfdiags.Diagnostics(nil).Append(fmt.Printf("mock provider has no schema for resource type %s", r.TypeName)), - } - } - schema := ps.ResourceTypes[r.TypeName].Block - info := &InstanceInfo{ - Type: r.TypeName, - } - priorState := NewInstanceStateShimmedFromValue(r.PriorState, 0) - cfg := NewResourceConfigShimmed(r.ProposedNewState, schema) - - legacyDiff, err := p.DiffFn(info, priorState, cfg) - - var res providers.PlanResourceChangeResponse - res.PlannedState = r.ProposedNewState - if err != nil { - res.Diagnostics = res.Diagnostics.Append(err) - } - if legacyDiff != nil { - newVal, err := legacyDiff.ApplyToValue(r.PriorState, schema) - if err != nil { - res.Diagnostics = res.Diagnostics.Append(err) - } - - res.PlannedState = newVal - - var requiresNew []string - for attr, d := range legacyDiff.Attributes { - if d.RequiresNew { - requiresNew = append(requiresNew, attr) - } - } - requiresReplace, err := hcl2shim.RequiresReplace(requiresNew, schema.ImpliedType()) - if err != nil { - res.Diagnostics = res.Diagnostics.Append(err) - } - res.RequiresReplace = requiresReplace - } - return res + return p.DiffFn(r) } if p.PlanResourceChangeFn != nil { return p.PlanResourceChangeFn(r) @@ -353,90 +310,7 @@ func (p *MockProvider) ApplyResourceChange(r providers.ApplyResourceChangeReques p.Unlock() if p.ApplyFn != nil { - // ApplyFn is a special callback fashioned after our old provider - // interface, which expected to be given an actual diff rather than - // separate old/new values to apply. Therefore we need to approximate - // a diff here well enough that _most_ of our legacy ApplyFns in old - // tests still see the behavior they are expecting. New tests should - // not use this, and should instead use ApplyResourceChangeFn directly. - providerSchema := p.getSchema() - schema, ok := providerSchema.ResourceTypes[r.TypeName] - if !ok { - return providers.ApplyResourceChangeResponse{ - Diagnostics: tfdiags.Diagnostics(nil).Append(fmt.Errorf("no mocked schema available for resource type %s", r.TypeName)), - } - } - - info := &InstanceInfo{ - Type: r.TypeName, - } - - priorVal := r.PriorState - plannedVal := r.PlannedState - priorMap := hcl2shim.FlatmapValueFromHCL2(priorVal) - plannedMap := hcl2shim.FlatmapValueFromHCL2(plannedVal) - s := NewInstanceStateShimmedFromValue(priorVal, 0) - d := &InstanceDiff{ - Attributes: make(map[string]*ResourceAttrDiff), - } - if plannedMap == nil { // destroying, then - d.Destroy = true - // Destroy diffs don't have any attribute diffs - } else { - if priorMap == nil { // creating, then - // We'll just make an empty prior map to make things easier below. - priorMap = make(map[string]string) - } - - for k, new := range plannedMap { - old := priorMap[k] - newComputed := false - if new == hcl2shim.UnknownVariableValue { - new = "" - newComputed = true - } - d.Attributes[k] = &ResourceAttrDiff{ - Old: old, - New: new, - NewComputed: newComputed, - Type: DiffAttrInput, // not generally used in tests, so just hard-coded - } - } - // Also need any attributes that were removed in "planned" - for k, old := range priorMap { - if _, ok := plannedMap[k]; ok { - continue - } - d.Attributes[k] = &ResourceAttrDiff{ - Old: old, - NewRemoved: true, - Type: DiffAttrInput, - } - } - } - newState, err := p.ApplyFn(info, s, d) - resp := providers.ApplyResourceChangeResponse{} - if err != nil { - resp.Diagnostics = resp.Diagnostics.Append(err) - } - if newState != nil { - var newVal cty.Value - if newState != nil { - var err error - newVal, err = newState.AttrsAsObjectValue(schema.Block.ImpliedType()) - if err != nil { - resp.Diagnostics = resp.Diagnostics.Append(err) - } - } else { - // If apply returned a nil new state then that's the old way to - // indicate that the object was destroyed. Our new interface calls - // for that to be signalled as a null value. - newVal = cty.NullVal(schema.Block.ImpliedType()) - } - resp.NewState = newVal - } - - return resp + return p.ApplyFn(r) } if p.ApplyResourceChangeFn != nil { return p.ApplyResourceChangeFn(r) diff --git a/terraform/terraform_test.go b/terraform/terraform_test.go index c655d741b..00788f546 100644 --- a/terraform/terraform_test.go +++ b/terraform/terraform_test.go @@ -414,12 +414,15 @@ aws_instance.bar: aws_instance.foo.0: ID = foo provider = provider["registry.terraform.io/hashicorp/aws"] + type = aws_instance aws_instance.foo.1: ID = foo provider = provider["registry.terraform.io/hashicorp/aws"] + type = aws_instance aws_instance.foo.2: ID = foo provider = provider["registry.terraform.io/hashicorp/aws"] + type = aws_instance ` const testTerraformApplyProviderAliasStr = ` @@ -439,9 +442,11 @@ const testTerraformApplyProviderAliasConfigStr = ` another_instance.bar: ID = foo provider = provider["registry.terraform.io/hashicorp/another"].two + type = another_instance another_instance.foo: ID = foo provider = provider["registry.terraform.io/hashicorp/another"] + type = another_instance ` const testTerraformApplyEmptyModuleStr = ` @@ -487,6 +492,7 @@ const testTerraformApplyCancelStr = ` aws_instance.foo: ID = foo provider = provider["registry.terraform.io/hashicorp/aws"] + type = aws_instance value = 2 ` @@ -590,9 +596,11 @@ aws_instance.bar: aws_instance.foo.0: ID = foo provider = provider["registry.terraform.io/hashicorp/aws"] + type = aws_instance aws_instance.foo.1: ID = foo provider = provider["registry.terraform.io/hashicorp/aws"] + type = aws_instance ` const testTerraformApplyForEachVariableStr = ` aws_instance.foo["b15c6d616d6143248c575900dff57325eb1de498"]: @@ -613,18 +621,22 @@ aws_instance.foo["e30a7edcc42a846684f2a4eea5f3cd261d33c46d"]: aws_instance.one["a"]: ID = foo provider = provider["registry.terraform.io/hashicorp/aws"] + type = aws_instance aws_instance.one["b"]: ID = foo provider = provider["registry.terraform.io/hashicorp/aws"] + type = aws_instance aws_instance.two["a"]: ID = foo provider = provider["registry.terraform.io/hashicorp/aws"] + type = aws_instance Dependencies: aws_instance.one aws_instance.two["b"]: ID = foo provider = provider["registry.terraform.io/hashicorp/aws"] + type = aws_instance Dependencies: aws_instance.one` @@ -632,9 +644,11 @@ const testTerraformApplyMinimalStr = ` aws_instance.bar: ID = foo provider = provider["registry.terraform.io/hashicorp/aws"] + type = aws_instance aws_instance.foo: ID = foo provider = provider["registry.terraform.io/hashicorp/aws"] + type = aws_instance ` const testTerraformApplyModuleStr = ` @@ -688,9 +702,11 @@ module.child: aws_instance.foo: ID = foo provider = provider["registry.terraform.io/hashicorp/aws"] + type = aws_instance test_instance.foo: ID = foo provider = provider["registry.terraform.io/hashicorp/test"] + type = test_instance ` const testTerraformApplyModuleProviderAliasStr = ` @@ -699,6 +715,7 @@ module.child: aws_instance.foo: ID = foo provider = module.child.provider["registry.terraform.io/hashicorp/aws"].eu + type = aws_instance ` const testTerraformApplyModuleVarRefExistingStr = ` @@ -706,6 +723,7 @@ aws_instance.foo: ID = foo provider = provider["registry.terraform.io/hashicorp/aws"] foo = bar + type = aws_instance module.child: aws_instance.foo: @@ -733,6 +751,7 @@ const testTerraformApplyProvisionerStr = ` aws_instance.bar: ID = foo provider = provider["registry.terraform.io/hashicorp/aws"] + type = aws_instance Dependencies: aws_instance.foo @@ -752,12 +771,14 @@ module.child: aws_instance.bar: ID = foo provider = provider["registry.terraform.io/hashicorp/aws"] + type = aws_instance ` const testTerraformApplyProvisionerFailStr = ` aws_instance.bar: (tainted) ID = foo provider = provider["registry.terraform.io/hashicorp/aws"] + type = aws_instance aws_instance.foo: ID = foo provider = provider["registry.terraform.io/hashicorp/aws"] @@ -769,6 +790,7 @@ const testTerraformApplyProvisionerFailCreateStr = ` aws_instance.bar: (tainted) ID = foo provider = provider["registry.terraform.io/hashicorp/aws"] + type = aws_instance ` const testTerraformApplyProvisionerFailCreateNoIdStr = ` @@ -850,14 +872,16 @@ const testTerraformApplyDestroyStr = ` const testTerraformApplyErrorStr = ` aws_instance.bar: (tainted) - ID = bar + ID = provider = provider["registry.terraform.io/hashicorp/aws"] + foo = 2 Dependencies: aws_instance.foo aws_instance.foo: ID = foo provider = provider["registry.terraform.io/hashicorp/aws"] + type = aws_instance value = 2 ` @@ -866,6 +890,7 @@ aws_instance.bar: ID = bar provider = provider["registry.terraform.io/hashicorp/aws"] require_new = abc + type = aws_instance ` const testTerraformApplyErrorDestroyCreateBeforeDestroyStr = ` @@ -881,12 +906,14 @@ const testTerraformApplyErrorPartialStr = ` aws_instance.bar: ID = bar provider = provider["registry.terraform.io/hashicorp/aws"] + type = aws_instance Dependencies: aws_instance.foo aws_instance.foo: ID = foo provider = provider["registry.terraform.io/hashicorp/aws"] + type = aws_instance value = 2 ` @@ -1107,7 +1134,6 @@ const testTerraformApplyUnknownAttrStr = ` aws_instance.foo: (tainted) ID = foo provider = provider["registry.terraform.io/hashicorp/aws"] - compute = unknown num = 2 type = aws_instance ` diff --git a/terraform/testdata/apply-multi-depose-create-before-destroy/main.tf b/terraform/testdata/apply-multi-depose-create-before-destroy/main.tf index ac7ba4b9b..e5a723b3a 100644 --- a/terraform/testdata/apply-multi-depose-create-before-destroy/main.tf +++ b/terraform/testdata/apply-multi-depose-create-before-destroy/main.tf @@ -1,7 +1,11 @@ +variable "require_new" { + type = string +} + resource "aws_instance" "web" { // require_new is a special attribute recognized by testDiffFn that forces // a new resource on every apply - require_new = "yes" + require_new = var.require_new lifecycle { create_before_destroy = true } diff --git a/terraform/testdata/apply-unknown/main.tf b/terraform/testdata/apply-unknown/main.tf index baf70ffe3..98f5ee87e 100644 --- a/terraform/testdata/apply-unknown/main.tf +++ b/terraform/testdata/apply-unknown/main.tf @@ -1,4 +1,3 @@ resource "aws_instance" "foo" { num = "2" - compute = "unknown" } From ea5ee39f38da630594397cf49883af67b8df21bb Mon Sep 17 00:00:00 2001 From: James Bardin Date: Thu, 8 Oct 2020 12:26:12 -0400 Subject: [PATCH 5/9] remove old mock provider ConfigureFn --- terraform/context_apply_test.go | 119 +++++++++--------- terraform/context_import_test.go | 30 ++--- terraform/context_input_test.go | 52 +++----- terraform/context_plan_test.go | 42 ++++--- terraform/context_validate_test.go | 7 +- terraform/provider_mock.go | 20 +-- .../testdata/apply-provider-computed/main.tf | 2 +- 7 files changed, 115 insertions(+), 157 deletions(-) diff --git a/terraform/context_apply_test.go b/terraform/context_apply_test.go index 4c585b73c..cec90d7ca 100644 --- a/terraform/context_apply_test.go +++ b/terraform/context_apply_test.go @@ -660,19 +660,15 @@ func TestContext2Apply_providerAliasConfigure(t *testing.T) { // Configure to record calls AFTER Plan above var configCount int32 - p2.ConfigureFn = func(c *ResourceConfig) error { + p2.ConfigureFn = func(req providers.ConfigureRequest) (resp providers.ConfigureResponse) { atomic.AddInt32(&configCount, 1) - foo, ok := c.Get("foo") - if !ok { - return fmt.Errorf("foo is not found") - } - + foo := req.Config.GetAttr("foo").AsString() if foo != "bar" { - return fmt.Errorf("foo: %#v", foo) + resp.Diagnostics = resp.Diagnostics.Append(fmt.Errorf("foo: %#v", foo)) } - return nil + return } state, diags := ctx.Apply() @@ -2477,16 +2473,18 @@ func TestContext2Apply_moduleInheritAlias(t *testing.T) { p.ApplyFn = testApplyFn p.DiffFn = testDiffFn - p.ConfigureFn = func(c *ResourceConfig) error { - if _, ok := c.Get("value"); !ok { - return nil + p.ConfigureFn = func(req providers.ConfigureRequest) (resp providers.ConfigureResponse) { + val := req.Config.GetAttr("value") + if val.IsNull() { + return } - if _, ok := c.Get("root"); ok { - return fmt.Errorf("child should not get root") + root := req.Config.GetAttr("root") + if !root.IsNull() { + resp.Diagnostics = resp.Diagnostics.Append(fmt.Errorf("child should not get root")) } - return nil + return } ctx := testContext2(t, &ContextOpts{ @@ -2601,19 +2599,18 @@ func TestContext2Apply_moduleOrphanInheritAlias(t *testing.T) { p.ApplyFn = testApplyFn p.DiffFn = testDiffFn - called := false - p.ConfigureFn = func(c *ResourceConfig) error { - called = true - - if _, ok := c.Get("child"); !ok { - return nil + p.ConfigureFn = func(req providers.ConfigureRequest) (resp providers.ConfigureResponse) { + val := req.Config.GetAttr("value") + if val.IsNull() { + return } - if _, ok := c.Get("root"); ok { - return fmt.Errorf("child should not get root") + root := req.Config.GetAttr("root") + if !root.IsNull() { + resp.Diagnostics = resp.Diagnostics.Append(fmt.Errorf("child should not get root")) } - return nil + return } // Create a state with an orphan module @@ -2645,7 +2642,7 @@ func TestContext2Apply_moduleOrphanInheritAlias(t *testing.T) { t.Fatalf("diags: %s", diags.Err()) } - if !called { + if !p.ConfigureCalled { t.Fatal("must call configure") } @@ -2658,12 +2655,13 @@ func TestContext2Apply_moduleOrphanProvider(t *testing.T) { p.ApplyFn = testApplyFn p.DiffFn = testDiffFn - p.ConfigureFn = func(c *ResourceConfig) error { - if _, ok := c.Get("value"); !ok { - return fmt.Errorf("value is not found") + p.ConfigureFn = func(req providers.ConfigureRequest) (resp providers.ConfigureResponse) { + val := req.Config.GetAttr("value") + if val.IsNull() { + resp.Diagnostics = resp.Diagnostics.Append(fmt.Errorf("value is not found")) } - return nil + return } // Create a state with an orphan module @@ -2701,12 +2699,13 @@ func TestContext2Apply_moduleOrphanGrandchildProvider(t *testing.T) { p.ApplyFn = testApplyFn p.DiffFn = testDiffFn - p.ConfigureFn = func(c *ResourceConfig) error { - if _, ok := c.Get("value"); !ok { - return fmt.Errorf("value is not found") + p.ConfigureFn = func(req providers.ConfigureRequest) (resp providers.ConfigureResponse) { + val := req.Config.GetAttr("value") + if val.IsNull() { + resp.Diagnostics = resp.Diagnostics.Append(fmt.Errorf("value is not found")) } - return nil + return } // Create a state with an orphan module that is nested (grandchild) @@ -2746,15 +2745,17 @@ func TestContext2Apply_moduleGrandchildProvider(t *testing.T) { var callLock sync.Mutex called := false - p.ConfigureFn = func(c *ResourceConfig) error { - if _, ok := c.Get("value"); !ok { - return fmt.Errorf("value is not found") + p.ConfigureFn = func(req providers.ConfigureRequest) (resp providers.ConfigureResponse) { + val := req.Config.GetAttr("value") + if val.IsNull() { + resp.Diagnostics = resp.Diagnostics.Append(fmt.Errorf("value is not found")) } + callLock.Lock() called = true callLock.Unlock() - return nil + return } ctx := testContext2(t, &ContextOpts{ @@ -3985,20 +3986,13 @@ func TestContext2Apply_providerComputedVar(t *testing.T) { }, }) - p.ConfigureFn = func(c *ResourceConfig) error { - if c.IsComputed("value") { - return fmt.Errorf("value is computed") + p.ConfigureFn = func(req providers.ConfigureRequest) (resp providers.ConfigureResponse) { + val := req.Config.GetAttr("value") + if val.IsNull() { + resp.Diagnostics = resp.Diagnostics.Append(fmt.Errorf("value is not found")) + return } - - v, ok := c.Get("value") - if !ok { - return fmt.Errorf("value is not found") - } - if v != "yes" { - return fmt.Errorf("value is not 'yes': %v", v) - } - - return nil + return } if _, diags := ctx.Plan(); diags.HasErrors() { @@ -4016,15 +4010,13 @@ func TestContext2Apply_providerConfigureDisabled(t *testing.T) { p.ApplyFn = testApplyFn p.DiffFn = testDiffFn - called := false - p.ConfigureFn = func(c *ResourceConfig) error { - called = true - - if _, ok := c.Get("value"); !ok { - return fmt.Errorf("value is not found") + p.ConfigureFn = func(req providers.ConfigureRequest) (resp providers.ConfigureResponse) { + val := req.Config.GetAttr("value") + if val.IsNull() { + resp.Diagnostics = resp.Diagnostics.Append(fmt.Errorf("value is not found")) } - return nil + return } ctx := testContext2(t, &ContextOpts{ @@ -4042,7 +4034,7 @@ func TestContext2Apply_providerConfigureDisabled(t *testing.T) { t.Fatalf("apply errors: %s", diags.Err()) } - if !called { + if !p.ConfigureCalled { t.Fatal("configure never called") } } @@ -8834,12 +8826,15 @@ func TestContext2Apply_providerWithLocals(t *testing.T) { providerRegion := "" // this should not be overridden during destroy - p.ConfigureFn = func(c *ResourceConfig) error { - if r, ok := c.Get("region"); ok { - providerRegion = r.(string) + p.ConfigureFn = func(req providers.ConfigureRequest) (resp providers.ConfigureResponse) { + val := req.Config.GetAttr("region") + if !val.IsNull() { + providerRegion = val.AsString() } - return nil + + return } + p.DiffFn = testDiffFn p.ApplyFn = testApplyFn ctx := testContext2(t, &ContextOpts{ @@ -11385,7 +11380,7 @@ output "output" { testP.GetSchemaReturn = schemaFn("test") providerConfig := "" - testP.ConfigureNewFn = func(req providers.ConfigureRequest) (resp providers.ConfigureResponse) { + testP.ConfigureFn = func(req providers.ConfigureRequest) (resp providers.ConfigureResponse) { value := req.Config.GetAttr("value") if value.IsKnown() && !value.IsNull() { providerConfig = value.AsString() diff --git a/terraform/context_import_test.go b/terraform/context_import_test.go index 31ab41ce4..01b9c2de2 100644 --- a/terraform/context_import_test.go +++ b/terraform/context_import_test.go @@ -1,7 +1,7 @@ package terraform import ( - "fmt" + "errors" "strings" "testing" @@ -196,15 +196,13 @@ func TestContextImport_moduleProvider(t *testing.T) { }, } - configured := false - p.ConfigureFn = func(c *ResourceConfig) error { - configured = true - - if v, ok := c.Get("foo"); !ok || v.(string) != "bar" { - return fmt.Errorf("bad") + p.ConfigureFn = func(req providers.ConfigureRequest) (resp providers.ConfigureResponse) { + foo := req.Config.GetAttr("foo").AsString() + if foo != "bar" { + resp.Diagnostics = resp.Diagnostics.Append(errors.New("not bar")) } - return nil + return } m := testModule(t, "import-provider") @@ -229,7 +227,7 @@ func TestContextImport_moduleProvider(t *testing.T) { t.Fatalf("unexpected errors: %s", diags.Err()) } - if !configured { + if !p.ConfigureCalled { t.Fatal("didn't configure provider") } @@ -258,15 +256,13 @@ func TestContextImport_providerModule(t *testing.T) { }, } - configured := false - p.ConfigureFn = func(c *ResourceConfig) error { - configured = true - - if v, ok := c.Get("foo"); !ok || v.(string) != "bar" { - return fmt.Errorf("bad") + p.ConfigureFn = func(req providers.ConfigureRequest) (resp providers.ConfigureResponse) { + foo := req.Config.GetAttr("foo").AsString() + if foo != "bar" { + resp.Diagnostics = resp.Diagnostics.Append(errors.New("not bar")) } - return nil + return } _, diags := ctx.Import(&ImportOpts{ @@ -283,7 +279,7 @@ func TestContextImport_providerModule(t *testing.T) { t.Fatalf("unexpected errors: %s", diags.Err()) } - if !configured { + if !p.ConfigureCalled { t.Fatal("didn't configure provider") } } diff --git a/terraform/context_input_test.go b/terraform/context_input_test.go index cb63b6906..2e1dd269f 100644 --- a/terraform/context_input_test.go +++ b/terraform/context_input_test.go @@ -56,9 +56,9 @@ func TestContext2Input_provider(t *testing.T) { }) var actual interface{} - p.ConfigureFn = func(c *ResourceConfig) error { - actual = c.Config["foo"] - return nil + p.ConfigureFn = func(req providers.ConfigureRequest) (resp providers.ConfigureResponse) { + actual = req.Config.GetAttr("foo").AsString() + return } p.ValidateFn = func(c *ResourceConfig) ([]string, []error) { return nil, c.CheckSet([]string{"foo"}) @@ -145,11 +145,11 @@ func TestContext2Input_providerMulti(t *testing.T) { t.Fatalf("plan errors: %s", diags.Err()) } - p.ConfigureFn = func(c *ResourceConfig) error { + p.ConfigureFn = func(req providers.ConfigureRequest) (resp providers.ConfigureResponse) { lock.Lock() defer lock.Unlock() - actual = append(actual, c.Config["foo"]) - return nil + actual = append(actual, req.Config.GetAttr("foo").AsString()) + return } if _, diags := ctx.Apply(); diags.HasErrors() { t.Fatalf("apply errors: %s", diags.Err()) @@ -217,9 +217,9 @@ func TestContext2Input_providerId(t *testing.T) { }) var actual interface{} - p.ConfigureFn = func(c *ResourceConfig) error { - actual = c.Config["foo"] - return nil + p.ConfigureFn = func(req providers.ConfigureRequest) (resp providers.ConfigureResponse) { + actual = req.Config.GetAttr("foo").AsString() + return } input.InputReturnMap = map[string]string{ @@ -290,9 +290,9 @@ func TestContext2Input_providerOnly(t *testing.T) { } var actual interface{} - p.ConfigureFn = func(c *ResourceConfig) error { - actual = c.Config["foo"] - return nil + p.ConfigureFn = func(req providers.ConfigureRequest) (resp providers.ConfigureResponse) { + actual = req.Config.GetAttr("foo").AsString() + return } if err := ctx.Input(InputModeProvider); err != nil { @@ -344,15 +344,10 @@ func TestContext2Input_providerVars(t *testing.T) { } var actual interface{} - /*p.InputFn = func(i UIInput, c *ResourceConfig) (*ResourceConfig, error) { - c.Config["bar"] = "baz" - return c, nil - }*/ - p.ConfigureFn = func(c *ResourceConfig) error { - actual, _ = c.Get("foo") - return nil + p.ConfigureFn = func(req providers.ConfigureRequest) (resp providers.ConfigureResponse) { + actual = req.Config.GetAttr("foo").AsString() + return } - if diags := ctx.Input(InputModeStd); diags.HasErrors() { t.Fatalf("input errors: %s", diags.Err()) } @@ -384,16 +379,6 @@ func TestContext2Input_providerVarsModuleInherit(t *testing.T) { UIInput: input, }) - /*p.InputFn = func(i UIInput, c *ResourceConfig) (*ResourceConfig, error) { - if errs := c.CheckSet([]string{"access_key"}); len(errs) > 0 { - return c, errs[0] - } - return c, nil - }*/ - p.ConfigureFn = func(c *ResourceConfig) error { - return nil - } - if diags := ctx.Input(InputModeStd); diags.HasErrors() { t.Fatalf("input errors: %s", diags.Err()) } @@ -414,13 +399,6 @@ func TestContext2Input_submoduleTriggersInvalidCount(t *testing.T) { UIInput: input, }) - /*p.InputFn = func(i UIInput, c *ResourceConfig) (*ResourceConfig, error) { - return c, nil - }*/ - p.ConfigureFn = func(c *ResourceConfig) error { - return nil - } - if diags := ctx.Input(InputModeStd); diags.HasErrors() { t.Fatalf("input errors: %s", diags.Err()) } diff --git a/terraform/context_plan_test.go b/terraform/context_plan_test.go index a1c6258df..75cdf5a8c 100644 --- a/terraform/context_plan_test.go +++ b/terraform/context_plan_test.go @@ -1016,12 +1016,13 @@ func TestContext2Plan_moduleProviderInherit(t *testing.T) { }, }, } - p.ConfigureFn = func(c *ResourceConfig) error { - if v, ok := c.Get("from"); !ok || v.(string) != "root" { - return fmt.Errorf("bad") + p.ConfigureFn = func(req providers.ConfigureRequest) (resp providers.ConfigureResponse) { + from := req.Config.GetAttr("from") + if from.IsNull() || from.AsString() != "root" { + resp.Diagnostics = resp.Diagnostics.Append(fmt.Errorf("not root")) } - return nil + return } p.DiffFn = func(req providers.PlanResourceChangeRequest) (resp providers.PlanResourceChangeResponse) { from := req.Config.GetAttr("from").AsString() @@ -1078,14 +1079,14 @@ func TestContext2Plan_moduleProviderInheritDeep(t *testing.T) { }, } - p.ConfigureFn = func(c *ResourceConfig) error { - v, ok := c.Get("from") - if !ok || v.(string) != "root" { - return fmt.Errorf("bad") + p.ConfigureFn = func(req providers.ConfigureRequest) (resp providers.ConfigureResponse) { + v := req.Config.GetAttr("from") + if v.IsNull() || v.AsString() != "root" { + resp.Diagnostics = resp.Diagnostics.Append(fmt.Errorf("not root")) } + from = v.AsString() - from = v.(string) - return nil + return } p.DiffFn = func(req providers.PlanResourceChangeRequest) (resp providers.PlanResourceChangeResponse) { @@ -1135,20 +1136,23 @@ func TestContext2Plan_moduleProviderDefaultsVar(t *testing.T) { }, }, } - p.ConfigureFn = func(c *ResourceConfig) error { + p.ConfigureFn = func(req providers.ConfigureRequest) (resp providers.ConfigureResponse) { var buf bytes.Buffer - if v, ok := c.Get("from"); ok { - buf.WriteString(v.(string) + "\n") + from := req.Config.GetAttr("from") + if !from.IsNull() { + buf.WriteString(from.AsString() + "\n") } - if v, ok := c.Get("to"); ok { - buf.WriteString(v.(string) + "\n") + to := req.Config.GetAttr("to") + if !to.IsNull() { + buf.WriteString(to.AsString() + "\n") } l.Lock() defer l.Unlock() calls = append(calls, buf.String()) - return nil + return } + p.DiffFn = testDiffFn return p, nil }, @@ -4434,9 +4438,9 @@ func TestContext2Plan_provider(t *testing.T) { p.DiffFn = testDiffFn var value interface{} - p.ConfigureFn = func(c *ResourceConfig) error { - value, _ = c.Get("foo") - return nil + p.ConfigureFn = func(req providers.ConfigureRequest) (resp providers.ConfigureResponse) { + value = req.Config.GetAttr("foo").AsString() + return } ctx := testContext2(t, &ContextOpts{ diff --git a/terraform/context_validate_test.go b/terraform/context_validate_test.go index 75415f58b..b88e10d11 100644 --- a/terraform/context_validate_test.go +++ b/terraform/context_validate_test.go @@ -173,14 +173,13 @@ func TestContext2Validate_computedVar(t *testing.T) { return nil, c.CheckSet([]string{"value"}) } - p.ConfigureFn = func(c *ResourceConfig) error { - return fmt.Errorf("Configure should not be called for provider") - } - diags := c.Validate() if diags.HasErrors() { t.Fatalf("unexpected error: %s", diags.Err()) } + if p.ConfigureCalled { + t.Fatal("Configure should not be called for provider") + } } func TestContext2Validate_computedInFunction(t *testing.T) { diff --git a/terraform/provider_mock.go b/terraform/provider_mock.go index f30a4adf8..c069ebbe9 100644 --- a/terraform/provider_mock.go +++ b/terraform/provider_mock.go @@ -51,7 +51,7 @@ type MockProvider struct { ConfigureCalled bool ConfigureResponse providers.ConfigureResponse ConfigureRequest providers.ConfigureRequest - ConfigureNewFn func(providers.ConfigureRequest) providers.ConfigureResponse // Named ConfigureNewFn so we can still have the legacy ConfigureFn declared below + ConfigureFn func(providers.ConfigureRequest) providers.ConfigureResponse StopCalled bool StopFn func() error @@ -88,10 +88,8 @@ type MockProvider struct { CloseCalled bool CloseError error - ValidateFn func(c *ResourceConfig) (ws []string, es []error) - ConfigureFn func(c *ResourceConfig) error + ValidateFn func(c *ResourceConfig) (ws []string, es []error) //ValidateFn func(providers.ValidateResourceTypeConfigRequest) providers.ValidateResourceTypeConfigResponse - //ConfigureFn func(providers.ConfigureRequest) providers.ConfigureResponse DiffFn func(providers.PlanResourceChangeRequest) providers.PlanResourceChangeResponse ApplyFn func(providers.ApplyResourceChangeRequest) providers.ApplyResourceChangeResponse } @@ -232,19 +230,7 @@ func (p *MockProvider) Configure(r providers.ConfigureRequest) providers.Configu p.ConfigureRequest = r if p.ConfigureFn != nil { - resp := p.getSchema() - schema := resp.Provider.Block - rc := NewResourceConfigShimmed(r.Config, schema) - ret := providers.ConfigureResponse{} - - err := p.ConfigureFn(rc) - if err != nil { - ret.Diagnostics = ret.Diagnostics.Append(err) - } - return ret - } - if p.ConfigureNewFn != nil { - return p.ConfigureNewFn(r) + return p.ConfigureFn(r) } return p.ConfigureResponse diff --git a/terraform/testdata/apply-provider-computed/main.tf b/terraform/testdata/apply-provider-computed/main.tf index 4a39bb546..81acf7cfa 100644 --- a/terraform/testdata/apply-provider-computed/main.tf +++ b/terraform/testdata/apply-provider-computed/main.tf @@ -1,5 +1,5 @@ provider "aws" { - value = "${test_instance.foo.value}" + value = test_instance.foo.id } resource "aws_instance" "bar" {} From 177797100d69ba1be13b036836653d4be6fa4e4e Mon Sep 17 00:00:00 2001 From: James Bardin Date: Thu, 8 Oct 2020 12:43:46 -0400 Subject: [PATCH 6/9] remove old mock validateFn --- terraform/context_apply_test.go | 4 ++-- terraform/context_input_test.go | 6 ----- terraform/context_validate_test.go | 24 ++++++++++++------- terraform/provider_mock.go | 16 ------------- .../testdata/validate-computed-var/main.tf | 2 +- .../validate-module-pc-vars/child/main.tf | 2 +- .../testdata/validate-module-pc-vars/main.tf | 2 +- 7 files changed, 21 insertions(+), 35 deletions(-) diff --git a/terraform/context_apply_test.go b/terraform/context_apply_test.go index cec90d7ca..a1f9fb03e 100644 --- a/terraform/context_apply_test.go +++ b/terraform/context_apply_test.go @@ -693,8 +693,8 @@ func TestContext2Apply_providerWarning(t *testing.T) { p := testProvider("aws") p.ApplyFn = testApplyFn p.DiffFn = testDiffFn - p.ValidateFn = func(c *ResourceConfig) (ws []string, es []error) { - ws = append(ws, "Just a warning") + p.ValidateResourceTypeConfigFn = func(req providers.ValidateResourceTypeConfigRequest) (resp providers.ValidateResourceTypeConfigResponse) { + resp.Diagnostics = resp.Diagnostics.Append(tfdiags.SimpleWarning("just a warning")) return } ctx := testContext2(t, &ContextOpts{ diff --git a/terraform/context_input_test.go b/terraform/context_input_test.go index 2e1dd269f..00208d571 100644 --- a/terraform/context_input_test.go +++ b/terraform/context_input_test.go @@ -60,9 +60,6 @@ func TestContext2Input_provider(t *testing.T) { actual = req.Config.GetAttr("foo").AsString() return } - p.ValidateFn = func(c *ResourceConfig) ([]string, []error) { - return nil, c.CheckSet([]string{"foo"}) - } if diags := ctx.Input(InputModeStd); diags.HasErrors() { t.Fatalf("input errors: %s", diags.Err()) @@ -133,9 +130,6 @@ func TestContext2Input_providerMulti(t *testing.T) { var actual []interface{} var lock sync.Mutex - p.ValidateFn = func(c *ResourceConfig) ([]string, []error) { - return nil, c.CheckSet([]string{"foo"}) - } if diags := ctx.Input(InputModeStd); diags.HasErrors() { t.Fatalf("input errors: %s", diags.Err()) diff --git a/terraform/context_validate_test.go b/terraform/context_validate_test.go index b88e10d11..28172182b 100644 --- a/terraform/context_validate_test.go +++ b/terraform/context_validate_test.go @@ -150,6 +150,7 @@ func TestContext2Validate_computedVar(t *testing.T) { ResourceTypes: map[string]*configschema.Block{ "test_instance": { Attributes: map[string]*configschema.Attribute{ + "id": {Type: cty.String, Computed: true}, "value": {Type: cty.String, Optional: true}, }, }, @@ -165,12 +166,13 @@ func TestContext2Validate_computedVar(t *testing.T) { }, }) - p.ValidateFn = func(c *ResourceConfig) ([]string, []error) { - if !c.IsComputed("value") { - return nil, []error{fmt.Errorf("value isn't computed")} + p.PrepareProviderConfigFn = func(req providers.PrepareProviderConfigRequest) (resp providers.PrepareProviderConfigResponse) { + val := req.Config.GetAttr("value") + if val.IsKnown() { + resp.Diagnostics = resp.Diagnostics.Append(fmt.Errorf("value isn't computed")) } - return nil, c.CheckSet([]string{"value"}) + return } diags := c.Validate() @@ -463,8 +465,11 @@ func TestContext2Validate_moduleProviderVar(t *testing.T) { }, }) - p.ValidateFn = func(c *ResourceConfig) ([]string, []error) { - return nil, c.CheckSet([]string{"foo"}) + p.PrepareProviderConfigFn = func(req providers.PrepareProviderConfigRequest) (resp providers.PrepareProviderConfigResponse) { + if req.Config.GetAttr("foo").IsNull() { + resp.Diagnostics = resp.Diagnostics.Append(errors.New("foo is null")) + } + return } diags := c.Validate() @@ -498,8 +503,11 @@ func TestContext2Validate_moduleProviderInheritUnused(t *testing.T) { }, }) - p.ValidateFn = func(c *ResourceConfig) ([]string, []error) { - return nil, c.CheckSet([]string{"foo"}) + p.PrepareProviderConfigFn = func(req providers.PrepareProviderConfigRequest) (resp providers.PrepareProviderConfigResponse) { + if req.Config.GetAttr("foo").IsNull() { + resp.Diagnostics = resp.Diagnostics.Append(errors.New("foo is null")) + } + return } diags := c.Validate() diff --git a/terraform/provider_mock.go b/terraform/provider_mock.go index c069ebbe9..b7c647c49 100644 --- a/terraform/provider_mock.go +++ b/terraform/provider_mock.go @@ -9,7 +9,6 @@ import ( "github.com/hashicorp/terraform/configs/hcl2shim" "github.com/hashicorp/terraform/providers" - "github.com/hashicorp/terraform/tfdiags" ) var _ providers.Interface = (*MockProvider)(nil) @@ -88,8 +87,6 @@ type MockProvider struct { CloseCalled bool CloseError error - ValidateFn func(c *ResourceConfig) (ws []string, es []error) - //ValidateFn func(providers.ValidateResourceTypeConfigRequest) providers.ValidateResourceTypeConfigResponse DiffFn func(providers.PlanResourceChangeRequest) providers.PlanResourceChangeResponse ApplyFn func(providers.ApplyResourceChangeRequest) providers.ApplyResourceChangeResponse } @@ -149,19 +146,6 @@ func (p *MockProvider) ValidateResourceTypeConfig(r providers.ValidateResourceTy p.ValidateResourceTypeConfigCalled = true p.ValidateResourceTypeConfigRequest = r - if p.ValidateFn != nil { - resp := p.getSchema() - schema := resp.Provider.Block - rc := NewResourceConfigShimmed(r.Config, schema) - warns, errs := p.ValidateFn(rc) - ret := providers.ValidateResourceTypeConfigResponse{} - for _, warn := range warns { - ret.Diagnostics = ret.Diagnostics.Append(tfdiags.SimpleWarning(warn)) - } - for _, err := range errs { - ret.Diagnostics = ret.Diagnostics.Append(err) - } - } if p.ValidateResourceTypeConfigFn != nil { return p.ValidateResourceTypeConfigFn(r) } diff --git a/terraform/testdata/validate-computed-var/main.tf b/terraform/testdata/validate-computed-var/main.tf index 4a39bb546..81acf7cfa 100644 --- a/terraform/testdata/validate-computed-var/main.tf +++ b/terraform/testdata/validate-computed-var/main.tf @@ -1,5 +1,5 @@ provider "aws" { - value = "${test_instance.foo.value}" + value = test_instance.foo.id } resource "aws_instance" "bar" {} diff --git a/terraform/testdata/validate-module-pc-vars/child/main.tf b/terraform/testdata/validate-module-pc-vars/child/main.tf index 3b4e15483..380cd465a 100644 --- a/terraform/testdata/validate-module-pc-vars/child/main.tf +++ b/terraform/testdata/validate-module-pc-vars/child/main.tf @@ -1,7 +1,7 @@ variable "value" {} provider "aws" { - foo = "${var.value}" + foo = var.value } resource "aws_instance" "foo" {} diff --git a/terraform/testdata/validate-module-pc-vars/main.tf b/terraform/testdata/validate-module-pc-vars/main.tf index 7d2d03e14..5e239b406 100644 --- a/terraform/testdata/validate-module-pc-vars/main.tf +++ b/terraform/testdata/validate-module-pc-vars/main.tf @@ -3,5 +3,5 @@ variable "provider_var" {} module "child" { source = "./child" - value = "${var.provider_var}" + value = var.provider_var } From a0caed541d37e8ee5b238a60809cee94c544f4f4 Mon Sep 17 00:00:00 2001 From: James Bardin Date: Thu, 8 Oct 2020 13:13:13 -0400 Subject: [PATCH 7/9] remove legacy ApplyFn from mock provisioner --- terraform/context_apply_test.go | 948 ++++++++++++++--------------- terraform/context_fixtures_test.go | 8 +- terraform/context_input_test.go | 32 +- terraform/context_plan_test.go | 220 +++---- terraform/context_refresh_test.go | 66 +- terraform/context_validate_test.go | 24 +- terraform/provider_mock.go | 9 - terraform/provisioner_mock.go | 49 -- 8 files changed, 646 insertions(+), 710 deletions(-) diff --git a/terraform/context_apply_test.go b/terraform/context_apply_test.go index a1f9fb03e..ce98a4631 100644 --- a/terraform/context_apply_test.go +++ b/terraform/context_apply_test.go @@ -34,8 +34,8 @@ import ( func TestContext2Apply_basic(t *testing.T) { m := testModule(t, "apply-good") p := testProvider("aws") - p.ApplyFn = testApplyFn - p.DiffFn = testDiffFn + p.ApplyResourceChangeFn = testApplyFn + p.PlanResourceChangeFn = testDiffFn ctx := testContext2(t, &ContextOpts{ Config: m, Providers: map[addrs.Provider]providers.Factory{ @@ -75,8 +75,8 @@ func TestContext2Apply_unstable(t *testing.T) { m := testModule(t, "apply-unstable") p := testProvider("test") - p.ApplyFn = testApplyFn - p.DiffFn = testDiffFn + p.ApplyResourceChangeFn = testApplyFn + p.PlanResourceChangeFn = testDiffFn ctx := testContext2(t, &ContextOpts{ Config: m, Providers: map[addrs.Provider]providers.Factory{ @@ -132,8 +132,8 @@ func TestContext2Apply_unstable(t *testing.T) { func TestContext2Apply_escape(t *testing.T) { m := testModule(t, "apply-escape") p := testProvider("aws") - p.ApplyFn = testApplyFn - p.DiffFn = testDiffFn + p.ApplyResourceChangeFn = testApplyFn + p.PlanResourceChangeFn = testDiffFn ctx := testContext2(t, &ContextOpts{ Config: m, Providers: map[addrs.Provider]providers.Factory{ @@ -162,8 +162,8 @@ aws_instance.bar: func TestContext2Apply_resourceCountOneList(t *testing.T) { m := testModule(t, "apply-resource-count-one-list") p := testProvider("null") - p.ApplyFn = testApplyFn - p.DiffFn = testDiffFn + p.ApplyResourceChangeFn = testApplyFn + p.PlanResourceChangeFn = testDiffFn ctx := testContext2(t, &ContextOpts{ Config: m, Providers: map[addrs.Provider]providers.Factory{ @@ -193,8 +193,8 @@ test = [foo]`) func TestContext2Apply_resourceCountZeroList(t *testing.T) { m := testModule(t, "apply-resource-count-zero-list") p := testProvider("null") - p.ApplyFn = testApplyFn - p.DiffFn = testDiffFn + p.ApplyResourceChangeFn = testApplyFn + p.PlanResourceChangeFn = testDiffFn ctx := testContext2(t, &ContextOpts{ Config: m, Providers: map[addrs.Provider]providers.Factory{ @@ -224,13 +224,13 @@ test = []`) func TestContext2Apply_resourceDependsOnModule(t *testing.T) { m := testModule(t, "apply-resource-depends-on-module") p := testProvider("aws") - p.DiffFn = testDiffFn + p.PlanResourceChangeFn = testDiffFn // verify the apply happens in the correct order var mu sync.Mutex var order []string - p.ApplyFn = func(req providers.ApplyResourceChangeRequest) (resp providers.ApplyResourceChangeResponse) { + p.ApplyResourceChangeFn = func(req providers.ApplyResourceChangeRequest) (resp providers.ApplyResourceChangeResponse) { ami := req.PlannedState.GetAttr("ami").AsString() switch ami { case "child": @@ -279,7 +279,7 @@ func TestContext2Apply_resourceDependsOnModule(t *testing.T) { func TestContext2Apply_resourceDependsOnModuleStateOnly(t *testing.T) { m := testModule(t, "apply-resource-depends-on-module-empty") p := testProvider("aws") - p.DiffFn = testDiffFn + p.PlanResourceChangeFn = testDiffFn state := states.NewState() root := state.EnsureModule(addrs.RootModuleInstance) @@ -307,7 +307,7 @@ func TestContext2Apply_resourceDependsOnModuleStateOnly(t *testing.T) { var mu sync.Mutex var order []string - p.ApplyFn = func(req providers.ApplyResourceChangeRequest) (resp providers.ApplyResourceChangeResponse) { + p.ApplyResourceChangeFn = func(req providers.ApplyResourceChangeRequest) (resp providers.ApplyResourceChangeResponse) { id := req.PriorState.GetAttr("id") if id.IsKnown() && id.AsString() == "parent" { // make the dep slower than the parent @@ -351,11 +351,11 @@ func TestContext2Apply_resourceDependsOnModuleStateOnly(t *testing.T) { func TestContext2Apply_resourceDependsOnModuleDestroy(t *testing.T) { m := testModule(t, "apply-resource-depends-on-module") p := testProvider("aws") - p.DiffFn = testDiffFn + p.PlanResourceChangeFn = testDiffFn var globalState *states.State { - p.ApplyFn = testApplyFn + p.ApplyResourceChangeFn = testApplyFn ctx := testContext2(t, &ContextOpts{ Config: m, Providers: map[addrs.Provider]providers.Factory{ @@ -380,7 +380,7 @@ func TestContext2Apply_resourceDependsOnModuleDestroy(t *testing.T) { // called a child. var called int32 var checked bool - p.ApplyFn = func(req providers.ApplyResourceChangeRequest) (resp providers.ApplyResourceChangeResponse) { + p.ApplyResourceChangeFn = func(req providers.ApplyResourceChangeRequest) (resp providers.ApplyResourceChangeResponse) { ami := req.PriorState.GetAttr("ami").AsString() if ami == "parent" { checked = true @@ -428,14 +428,14 @@ func TestContext2Apply_resourceDependsOnModuleDestroy(t *testing.T) { func TestContext2Apply_resourceDependsOnModuleGrandchild(t *testing.T) { m := testModule(t, "apply-resource-depends-on-module-deep") p := testProvider("aws") - p.DiffFn = testDiffFn + p.PlanResourceChangeFn = testDiffFn { // Wait for the dependency, sleep, and verify the graph never // called a child. var called int32 var checked bool - p.ApplyFn = func(req providers.ApplyResourceChangeRequest) (resp providers.ApplyResourceChangeResponse) { + p.ApplyResourceChangeFn = func(req providers.ApplyResourceChangeRequest) (resp providers.ApplyResourceChangeResponse) { planned := req.PlannedState.AsValueMap() if ami, ok := planned["ami"]; ok && ami.AsString() == "grandchild" { checked = true @@ -481,14 +481,14 @@ func TestContext2Apply_resourceDependsOnModuleGrandchild(t *testing.T) { func TestContext2Apply_resourceDependsOnModuleInModule(t *testing.T) { m := testModule(t, "apply-resource-depends-on-module-in-module") p := testProvider("aws") - p.DiffFn = testDiffFn + p.PlanResourceChangeFn = testDiffFn { // Wait for the dependency, sleep, and verify the graph never // called a child. var called int32 var checked bool - p.ApplyFn = func(req providers.ApplyResourceChangeRequest) (resp providers.ApplyResourceChangeResponse) { + p.ApplyResourceChangeFn = func(req providers.ApplyResourceChangeRequest) (resp providers.ApplyResourceChangeResponse) { planned := req.PlannedState.AsValueMap() if ami, ok := planned["ami"]; ok && ami.AsString() == "grandchild" { checked = true @@ -534,8 +534,8 @@ func TestContext2Apply_resourceDependsOnModuleInModule(t *testing.T) { func TestContext2Apply_mapVarBetweenModules(t *testing.T) { m := testModule(t, "apply-map-var-through-module") p := testProvider("null") - p.ApplyFn = testApplyFn - p.DiffFn = testDiffFn + p.ApplyResourceChangeFn = testApplyFn + p.PlanResourceChangeFn = testDiffFn ctx := testContext2(t, &ContextOpts{ Config: m, Providers: map[addrs.Provider]providers.Factory{ @@ -574,8 +574,8 @@ module.test: func TestContext2Apply_refCount(t *testing.T) { m := testModule(t, "apply-ref-count") p := testProvider("aws") - p.ApplyFn = testApplyFn - p.DiffFn = testDiffFn + p.ApplyResourceChangeFn = testApplyFn + p.PlanResourceChangeFn = testDiffFn ctx := testContext2(t, &ContextOpts{ Config: m, Providers: map[addrs.Provider]providers.Factory{ @@ -607,8 +607,8 @@ func TestContext2Apply_refCount(t *testing.T) { func TestContext2Apply_providerAlias(t *testing.T) { m := testModule(t, "apply-provider-alias") p := testProvider("aws") - p.ApplyFn = testApplyFn - p.DiffFn = testDiffFn + p.ApplyResourceChangeFn = testApplyFn + p.PlanResourceChangeFn = testDiffFn ctx := testContext2(t, &ContextOpts{ Config: m, Providers: map[addrs.Provider]providers.Factory{ @@ -642,8 +642,8 @@ func TestContext2Apply_providerAliasConfigure(t *testing.T) { m := testModule(t, "apply-provider-alias-configure") p2 := testProvider("another") - p2.ApplyFn = testApplyFn - p2.DiffFn = testDiffFn + p2.ApplyResourceChangeFn = testApplyFn + p2.PlanResourceChangeFn = testDiffFn ctx := testContext2(t, &ContextOpts{ Config: m, @@ -691,8 +691,8 @@ func TestContext2Apply_providerAliasConfigure(t *testing.T) { func TestContext2Apply_providerWarning(t *testing.T) { m := testModule(t, "apply-provider-warning") p := testProvider("aws") - p.ApplyFn = testApplyFn - p.DiffFn = testDiffFn + p.ApplyResourceChangeFn = testApplyFn + p.PlanResourceChangeFn = testDiffFn p.ValidateResourceTypeConfigFn = func(req providers.ValidateResourceTypeConfigRequest) (resp providers.ValidateResourceTypeConfigResponse) { resp.Diagnostics = resp.Diagnostics.Append(tfdiags.SimpleWarning("just a warning")) return @@ -733,8 +733,8 @@ func TestContext2Apply_emptyModule(t *testing.T) { // A module with only outputs (no resources) m := testModule(t, "apply-empty-module") p := testProvider("aws") - p.ApplyFn = testApplyFn - p.DiffFn = testDiffFn + p.ApplyResourceChangeFn = testApplyFn + p.PlanResourceChangeFn = testDiffFn ctx := testContext2(t, &ContextOpts{ Config: m, Providers: map[addrs.Provider]providers.Factory{ @@ -762,8 +762,8 @@ func TestContext2Apply_emptyModule(t *testing.T) { func TestContext2Apply_createBeforeDestroy(t *testing.T) { m := testModule(t, "apply-good-create-before") p := testProvider("aws") - p.ApplyFn = testApplyFn - p.DiffFn = testDiffFn + p.ApplyResourceChangeFn = testApplyFn + p.PlanResourceChangeFn = testDiffFn state := states.NewState() root := state.EnsureModule(addrs.RootModuleInstance) root.SetResourceInstanceCurrent( @@ -809,8 +809,8 @@ func TestContext2Apply_createBeforeDestroy(t *testing.T) { func TestContext2Apply_createBeforeDestroyUpdate(t *testing.T) { m := testModule(t, "apply-good-create-before-update") p := testProvider("aws") - p.ApplyFn = testApplyFn - p.DiffFn = testDiffFn + p.ApplyResourceChangeFn = testApplyFn + p.PlanResourceChangeFn = testDiffFn state := states.NewState() root := state.EnsureModule(addrs.RootModuleInstance) @@ -859,8 +859,8 @@ func TestContext2Apply_createBeforeDestroyUpdate(t *testing.T) { func TestContext2Apply_createBeforeDestroy_dependsNonCBD(t *testing.T) { m := testModule(t, "apply-cbd-depends-non-cbd") p := testProvider("aws") - p.ApplyFn = testApplyFn - p.DiffFn = testDiffFn + p.ApplyResourceChangeFn = testApplyFn + p.PlanResourceChangeFn = testDiffFn state := states.NewState() root := state.EnsureModule(addrs.RootModuleInstance) @@ -922,8 +922,8 @@ func TestContext2Apply_createBeforeDestroy_hook(t *testing.T) { h := new(MockHook) m := testModule(t, "apply-good-create-before") p := testProvider("aws") - p.ApplyFn = testApplyFn - p.DiffFn = testDiffFn + p.ApplyResourceChangeFn = testApplyFn + p.PlanResourceChangeFn = testDiffFn state := states.NewState() root := state.EnsureModule(addrs.RootModuleInstance) root.SetResourceInstanceCurrent( @@ -983,8 +983,8 @@ func TestContext2Apply_createBeforeDestroy_hook(t *testing.T) { func TestContext2Apply_createBeforeDestroy_deposedCount(t *testing.T) { m := testModule(t, "apply-cbd-count") p := testProvider("aws") - p.ApplyFn = testApplyFn - p.DiffFn = testDiffFn + p.ApplyResourceChangeFn = testApplyFn + p.PlanResourceChangeFn = testDiffFn state := states.NewState() root := state.EnsureModule(addrs.RootModuleInstance) @@ -1061,8 +1061,8 @@ aws_instance.bar.1: func TestContext2Apply_createBeforeDestroy_deposedOnly(t *testing.T) { m := testModule(t, "apply-cbd-deposed-only") p := testProvider("aws") - p.ApplyFn = testApplyFn - p.DiffFn = testDiffFn + p.ApplyResourceChangeFn = testApplyFn + p.PlanResourceChangeFn = testDiffFn state := states.NewState() root := state.EnsureModule(addrs.RootModuleInstance) @@ -1114,8 +1114,8 @@ aws_instance.bar: func TestContext2Apply_destroyComputed(t *testing.T) { m := testModule(t, "apply-destroy-computed") p := testProvider("aws") - p.ApplyFn = testApplyFn - p.DiffFn = testDiffFn + p.ApplyResourceChangeFn = testApplyFn + p.PlanResourceChangeFn = testDiffFn state := states.NewState() root := state.EnsureModule(addrs.RootModuleInstance) root.SetResourceInstanceCurrent( @@ -1160,8 +1160,8 @@ func TestContext2Apply_destroyDependsOn(t *testing.T) { func testContext2Apply_destroyDependsOn(t *testing.T) { m := testModule(t, "apply-destroy-depends-on") p := testProvider("aws") - p.ApplyFn = testApplyFn - p.DiffFn = testDiffFn + p.ApplyResourceChangeFn = testApplyFn + p.PlanResourceChangeFn = testDiffFn state := states.NewState() root := state.EnsureModule(addrs.RootModuleInstance) @@ -1186,7 +1186,7 @@ func testContext2Apply_destroyDependsOn(t *testing.T) { // Record the order we see Apply var actual []string var actualLock sync.Mutex - p.ApplyFn = func(req providers.ApplyResourceChangeRequest) providers.ApplyResourceChangeResponse { + p.ApplyResourceChangeFn = func(req providers.ApplyResourceChangeRequest) providers.ApplyResourceChangeResponse { actualLock.Lock() defer actualLock.Unlock() id := req.PriorState.GetAttr("id").AsString() @@ -1278,12 +1278,12 @@ func TestContext2Apply_destroyDependsOnStateOnly(t *testing.T) { func testContext2Apply_destroyDependsOnStateOnly(t *testing.T, state *states.State) { m := testModule(t, "empty") p := testProvider("aws") - p.ApplyFn = testApplyFn - p.DiffFn = testDiffFn + p.ApplyResourceChangeFn = testApplyFn + p.PlanResourceChangeFn = testDiffFn // Record the order we see Apply var actual []string var actualLock sync.Mutex - p.ApplyFn = func(req providers.ApplyResourceChangeRequest) providers.ApplyResourceChangeResponse { + p.ApplyResourceChangeFn = func(req providers.ApplyResourceChangeRequest) providers.ApplyResourceChangeResponse { actualLock.Lock() defer actualLock.Unlock() id := req.PriorState.GetAttr("id").AsString() @@ -1374,13 +1374,13 @@ func TestContext2Apply_destroyDependsOnStateOnlyModule(t *testing.T) { func testContext2Apply_destroyDependsOnStateOnlyModule(t *testing.T, state *states.State) { m := testModule(t, "empty") p := testProvider("aws") - p.ApplyFn = testApplyFn - p.DiffFn = testDiffFn + p.ApplyResourceChangeFn = testApplyFn + p.PlanResourceChangeFn = testDiffFn // Record the order we see Apply var actual []string var actualLock sync.Mutex - p.ApplyFn = func(req providers.ApplyResourceChangeRequest) providers.ApplyResourceChangeResponse { + p.ApplyResourceChangeFn = func(req providers.ApplyResourceChangeRequest) providers.ApplyResourceChangeResponse { actualLock.Lock() defer actualLock.Unlock() id := req.PriorState.GetAttr("id").AsString() @@ -1415,8 +1415,8 @@ func testContext2Apply_destroyDependsOnStateOnlyModule(t *testing.T, state *stat func TestContext2Apply_dataBasic(t *testing.T) { m := testModule(t, "apply-data-basic") p := testProvider("null") - p.ApplyFn = testApplyFn - p.DiffFn = testDiffFn + p.ApplyResourceChangeFn = testApplyFn + p.PlanResourceChangeFn = testDiffFn p.ReadDataSourceResponse = providers.ReadDataSourceResponse{ State: cty.ObjectVal(map[string]cty.Value{ "id": cty.StringVal("yo"), @@ -1450,8 +1450,8 @@ func TestContext2Apply_dataBasic(t *testing.T) { func TestContext2Apply_destroyData(t *testing.T) { m := testModule(t, "apply-destroy-data-resource") p := testProvider("null") - p.ApplyFn = testApplyFn - p.DiffFn = testDiffFn + p.ApplyResourceChangeFn = testApplyFn + p.PlanResourceChangeFn = testDiffFn state := states.NewState() root := state.EnsureModule(addrs.RootModuleInstance) root.SetResourceInstanceCurrent( @@ -1510,8 +1510,8 @@ func TestContext2Apply_destroySkipsCBD(t *testing.T) { // just doing a `terraform destroy`. m := testModule(t, "apply-destroy-cbd") p := testProvider("aws") - p.ApplyFn = testApplyFn - p.DiffFn = testDiffFn + p.ApplyResourceChangeFn = testApplyFn + p.PlanResourceChangeFn = testDiffFn state := states.NewState() root := state.EnsureModule(addrs.RootModuleInstance) root.SetResourceInstanceCurrent( @@ -1554,8 +1554,8 @@ func TestContext2Apply_destroySkipsCBD(t *testing.T) { func TestContext2Apply_destroyModuleVarProviderConfig(t *testing.T) { m := testModule(t, "apply-destroy-mod-var-provider-config") p := testProvider("aws") - p.ApplyFn = testApplyFn - p.DiffFn = testDiffFn + p.ApplyResourceChangeFn = testApplyFn + p.PlanResourceChangeFn = testDiffFn state := states.NewState() root := state.EnsureModule(addrs.RootModuleInstance) root.SetResourceInstanceCurrent( @@ -1589,8 +1589,8 @@ func TestContext2Apply_destroyCrossProviders(t *testing.T) { m := testModule(t, "apply-destroy-cross-providers") p_aws := testProvider("aws") - p_aws.ApplyFn = testApplyFn - p_aws.DiffFn = testDiffFn + p_aws.ApplyResourceChangeFn = testApplyFn + p_aws.PlanResourceChangeFn = testDiffFn p_aws.GetSchemaReturn = &ProviderSchema{ ResourceTypes: map[string]*configschema.Block{ "aws_instance": { @@ -1667,8 +1667,8 @@ func getContextForApply_destroyCrossProviders(t *testing.T, m *configs.Config, p func TestContext2Apply_minimal(t *testing.T) { m := testModule(t, "apply-minimal") p := testProvider("aws") - p.ApplyFn = testApplyFn - p.DiffFn = testDiffFn + p.ApplyResourceChangeFn = testApplyFn + p.PlanResourceChangeFn = testDiffFn ctx := testContext2(t, &ContextOpts{ Config: m, Providers: map[addrs.Provider]providers.Factory{ @@ -1704,7 +1704,7 @@ func TestContext2Apply_cancel(t *testing.T) { }, }) - p.ApplyFn = func(req providers.ApplyResourceChangeRequest) providers.ApplyResourceChangeResponse { + p.ApplyResourceChangeFn = func(req providers.ApplyResourceChangeRequest) providers.ApplyResourceChangeResponse { if !stopped { stopped = true go ctx.Stop() @@ -1718,7 +1718,7 @@ func TestContext2Apply_cancel(t *testing.T) { } return testApplyFn(req) } - p.DiffFn = testDiffFn + p.PlanResourceChangeFn = testDiffFn if _, diags := ctx.Plan(); diags.HasErrors() { t.Fatalf("plan errors: %s", diags.Err()) @@ -1761,8 +1761,8 @@ func TestContext2Apply_cancelBlock(t *testing.T) { }) applyCh := make(chan struct{}) - p.DiffFn = testDiffFn - p.ApplyFn = func(req providers.ApplyResourceChangeRequest) providers.ApplyResourceChangeResponse { + p.PlanResourceChangeFn = testDiffFn + p.ApplyResourceChangeFn = func(req providers.ApplyResourceChangeRequest) providers.ApplyResourceChangeResponse { close(applyCh) for !ctx.sh.Stopped() { @@ -1829,8 +1829,8 @@ aws_instance.foo: func TestContext2Apply_cancelProvisioner(t *testing.T) { m := testModule(t, "apply-cancel-provisioner") p := testProvider("aws") - p.ApplyFn = testApplyFn - p.DiffFn = testDiffFn + p.ApplyResourceChangeFn = testApplyFn + p.PlanResourceChangeFn = testDiffFn pr := testProvisioner() pr.GetSchemaResponse = provisioners.GetSchemaResponse{ @@ -1855,12 +1855,12 @@ func TestContext2Apply_cancelProvisioner(t *testing.T) { }) prStopped := make(chan struct{}) - pr.ApplyFn = func(rs *InstanceState, c *ResourceConfig) error { + pr.ProvisionResourceFn = func(req provisioners.ProvisionResourceRequest) (resp provisioners.ProvisionResourceResponse) { // Start the stop process go ctx.Stop() <-prStopped - return nil + return } pr.StopFn = func() error { close(prStopped) @@ -1901,8 +1901,8 @@ aws_instance.foo: (tainted) func TestContext2Apply_compute(t *testing.T) { m := testModule(t, "apply-compute") p := testProvider("aws") - p.ApplyFn = testApplyFn - p.DiffFn = testDiffFn + p.ApplyResourceChangeFn = testApplyFn + p.PlanResourceChangeFn = testDiffFn p.GetSchemaReturn = &ProviderSchema{ ResourceTypes: map[string]*configschema.Block{ "aws_instance": { @@ -1973,8 +1973,8 @@ func TestContext2Apply_compute(t *testing.T) { func TestContext2Apply_countDecrease(t *testing.T) { m := testModule(t, "apply-count-dec") p := testProvider("aws") - p.DiffFn = testDiffFn - p.ApplyFn = testApplyFn + p.PlanResourceChangeFn = testDiffFn + p.ApplyResourceChangeFn = testApplyFn state := states.NewState() root := state.EnsureModule(addrs.RootModuleInstance) root.SetResourceInstanceCurrent( @@ -2028,8 +2028,8 @@ func TestContext2Apply_countDecrease(t *testing.T) { func TestContext2Apply_countDecreaseToOneX(t *testing.T) { m := testModule(t, "apply-count-dec-one") p := testProvider("aws") - p.ApplyFn = testApplyFn - p.DiffFn = testDiffFn + p.ApplyResourceChangeFn = testApplyFn + p.PlanResourceChangeFn = testDiffFn state := states.NewState() root := state.EnsureModule(addrs.RootModuleInstance) root.SetResourceInstanceCurrent( @@ -2089,8 +2089,8 @@ func TestContext2Apply_countDecreaseToOneX(t *testing.T) { func TestContext2Apply_countDecreaseToOneCorrupted(t *testing.T) { m := testModule(t, "apply-count-dec-one") p := testProvider("aws") - p.ApplyFn = testApplyFn - p.DiffFn = testDiffFn + p.ApplyResourceChangeFn = testApplyFn + p.PlanResourceChangeFn = testDiffFn state := states.NewState() root := state.EnsureModule(addrs.RootModuleInstance) root.SetResourceInstanceCurrent( @@ -2143,8 +2143,8 @@ func TestContext2Apply_countDecreaseToOneCorrupted(t *testing.T) { func TestContext2Apply_countTainted(t *testing.T) { m := testModule(t, "apply-count-tainted") p := testProvider("aws") - p.DiffFn = testDiffFn - p.ApplyFn = testApplyFn + p.PlanResourceChangeFn = testDiffFn + p.ApplyResourceChangeFn = testApplyFn state := states.NewState() root := state.EnsureModule(addrs.RootModuleInstance) root.SetResourceInstanceCurrent( @@ -2206,8 +2206,8 @@ aws_instance.foo.1: func TestContext2Apply_countVariable(t *testing.T) { m := testModule(t, "apply-count-variable") p := testProvider("aws") - p.ApplyFn = testApplyFn - p.DiffFn = testDiffFn + p.ApplyResourceChangeFn = testApplyFn + p.PlanResourceChangeFn = testDiffFn ctx := testContext2(t, &ContextOpts{ Config: m, Providers: map[addrs.Provider]providers.Factory{ @@ -2234,8 +2234,8 @@ func TestContext2Apply_countVariable(t *testing.T) { func TestContext2Apply_countVariableRef(t *testing.T) { m := testModule(t, "apply-count-variable-ref") p := testProvider("aws") - p.ApplyFn = testApplyFn - p.DiffFn = testDiffFn + p.ApplyResourceChangeFn = testApplyFn + p.PlanResourceChangeFn = testDiffFn ctx := testContext2(t, &ContextOpts{ Config: m, Providers: map[addrs.Provider]providers.Factory{ @@ -2267,8 +2267,8 @@ func TestContext2Apply_provisionerInterpCount(t *testing.T) { m, snap := testModuleWithSnapshot(t, "apply-provisioner-interp-count") p := testProvider("aws") - p.ApplyFn = testApplyFn - p.DiffFn = testDiffFn + p.ApplyResourceChangeFn = testApplyFn + p.PlanResourceChangeFn = testDiffFn pr := testProvisioner() @@ -2319,8 +2319,8 @@ func TestContext2Apply_provisionerInterpCount(t *testing.T) { func TestContext2Apply_foreachVariable(t *testing.T) { m := testModule(t, "plan-for-each-unknown-value") p := testProvider("aws") - p.ApplyFn = testApplyFn - p.DiffFn = testDiffFn + p.ApplyResourceChangeFn = testApplyFn + p.PlanResourceChangeFn = testDiffFn ctx := testContext2(t, &ContextOpts{ Config: m, Providers: map[addrs.Provider]providers.Factory{ @@ -2352,8 +2352,8 @@ func TestContext2Apply_foreachVariable(t *testing.T) { func TestContext2Apply_moduleBasic(t *testing.T) { m := testModule(t, "apply-module") p := testProvider("aws") - p.ApplyFn = testApplyFn - p.DiffFn = testDiffFn + p.ApplyResourceChangeFn = testApplyFn + p.PlanResourceChangeFn = testDiffFn ctx := testContext2(t, &ContextOpts{ Config: m, Providers: map[addrs.Provider]providers.Factory{ @@ -2380,12 +2380,12 @@ func TestContext2Apply_moduleBasic(t *testing.T) { func TestContext2Apply_moduleDestroyOrder(t *testing.T) { m := testModule(t, "apply-module-destroy-order") p := testProvider("aws") - p.DiffFn = testDiffFn + p.PlanResourceChangeFn = testDiffFn // Create a custom apply function to track the order they were destroyed var order []string var orderLock sync.Mutex - p.ApplyFn = func(req providers.ApplyResourceChangeRequest) (resp providers.ApplyResourceChangeResponse) { + p.ApplyResourceChangeFn = func(req providers.ApplyResourceChangeRequest) (resp providers.ApplyResourceChangeResponse) { id := req.PriorState.GetAttr("id").AsString() if id == "b" { @@ -2470,8 +2470,8 @@ func TestContext2Apply_moduleDestroyOrder(t *testing.T) { func TestContext2Apply_moduleInheritAlias(t *testing.T) { m := testModule(t, "apply-module-provider-inherit-alias") p := testProvider("aws") - p.ApplyFn = testApplyFn - p.DiffFn = testDiffFn + p.ApplyResourceChangeFn = testApplyFn + p.PlanResourceChangeFn = testDiffFn p.ConfigureFn = func(req providers.ConfigureRequest) (resp providers.ConfigureResponse) { val := req.Config.GetAttr("value") @@ -2521,8 +2521,8 @@ func TestContext2Apply_orphanResource(t *testing.T) { // 2. Apply an empty configuration against the same state, which should // then clean up both the instances and the containing resource objects. p := testProvider("test") - p.ApplyFn = testApplyFn - p.DiffFn = testDiffFn + p.ApplyResourceChangeFn = testApplyFn + p.PlanResourceChangeFn = testDiffFn p.GetSchemaReturn = &ProviderSchema{ ResourceTypes: map[string]*configschema.Block{ "test_thing": { @@ -2596,8 +2596,8 @@ func TestContext2Apply_orphanResource(t *testing.T) { func TestContext2Apply_moduleOrphanInheritAlias(t *testing.T) { m := testModule(t, "apply-module-provider-inherit-alias-orphan") p := testProvider("aws") - p.ApplyFn = testApplyFn - p.DiffFn = testDiffFn + p.ApplyResourceChangeFn = testApplyFn + p.PlanResourceChangeFn = testDiffFn p.ConfigureFn = func(req providers.ConfigureRequest) (resp providers.ConfigureResponse) { val := req.Config.GetAttr("value") @@ -2652,8 +2652,8 @@ func TestContext2Apply_moduleOrphanInheritAlias(t *testing.T) { func TestContext2Apply_moduleOrphanProvider(t *testing.T) { m := testModule(t, "apply-module-orphan-provider-inherit") p := testProvider("aws") - p.ApplyFn = testApplyFn - p.DiffFn = testDiffFn + p.ApplyResourceChangeFn = testApplyFn + p.PlanResourceChangeFn = testDiffFn p.ConfigureFn = func(req providers.ConfigureRequest) (resp providers.ConfigureResponse) { val := req.Config.GetAttr("value") @@ -2696,8 +2696,8 @@ func TestContext2Apply_moduleOrphanProvider(t *testing.T) { func TestContext2Apply_moduleOrphanGrandchildProvider(t *testing.T) { m := testModule(t, "apply-module-orphan-provider-inherit") p := testProvider("aws") - p.ApplyFn = testApplyFn - p.DiffFn = testDiffFn + p.ApplyResourceChangeFn = testApplyFn + p.PlanResourceChangeFn = testDiffFn p.ConfigureFn = func(req providers.ConfigureRequest) (resp providers.ConfigureResponse) { val := req.Config.GetAttr("value") @@ -2740,8 +2740,8 @@ func TestContext2Apply_moduleOrphanGrandchildProvider(t *testing.T) { func TestContext2Apply_moduleGrandchildProvider(t *testing.T) { m := testModule(t, "apply-module-grandchild-provider-inherit") p := testProvider("aws") - p.ApplyFn = testApplyFn - p.DiffFn = testDiffFn + p.ApplyResourceChangeFn = testApplyFn + p.PlanResourceChangeFn = testDiffFn var callLock sync.Mutex called := false @@ -2787,11 +2787,11 @@ func TestContext2Apply_moduleGrandchildProvider(t *testing.T) { func TestContext2Apply_moduleOnlyProvider(t *testing.T) { m := testModule(t, "apply-module-only-provider") p := testProvider("aws") - p.ApplyFn = testApplyFn - p.DiffFn = testDiffFn + p.ApplyResourceChangeFn = testApplyFn + p.PlanResourceChangeFn = testDiffFn pTest := testProvider("test") - pTest.ApplyFn = testApplyFn - pTest.DiffFn = testDiffFn + pTest.ApplyResourceChangeFn = testApplyFn + pTest.PlanResourceChangeFn = testDiffFn ctx := testContext2(t, &ContextOpts{ Config: m, @@ -2820,8 +2820,8 @@ func TestContext2Apply_moduleOnlyProvider(t *testing.T) { func TestContext2Apply_moduleProviderAlias(t *testing.T) { m := testModule(t, "apply-module-provider-alias") p := testProvider("aws") - p.ApplyFn = testApplyFn - p.DiffFn = testDiffFn + p.ApplyResourceChangeFn = testApplyFn + p.PlanResourceChangeFn = testDiffFn ctx := testContext2(t, &ContextOpts{ Config: m, Providers: map[addrs.Provider]providers.Factory{ @@ -2848,8 +2848,8 @@ func TestContext2Apply_moduleProviderAlias(t *testing.T) { func TestContext2Apply_moduleProviderAliasTargets(t *testing.T) { m := testModule(t, "apply-module-provider-alias") p := testProvider("aws") - p.ApplyFn = testApplyFn - p.DiffFn = testDiffFn + p.ApplyResourceChangeFn = testApplyFn + p.PlanResourceChangeFn = testDiffFn ctx := testContext2(t, &ContextOpts{ Config: m, Providers: map[addrs.Provider]providers.Factory{ @@ -2888,8 +2888,8 @@ func TestContext2Apply_moduleProviderAliasTargets(t *testing.T) { func TestContext2Apply_moduleProviderCloseNested(t *testing.T) { m := testModule(t, "apply-module-provider-close-nested") p := testProvider("aws") - p.ApplyFn = testApplyFn - p.DiffFn = testDiffFn + p.ApplyResourceChangeFn = testApplyFn + p.PlanResourceChangeFn = testDiffFn state := states.NewState() root := state.EnsureModule(addrs.RootModuleInstance) root.SetResourceInstanceCurrent( @@ -2927,8 +2927,8 @@ func TestContext2Apply_moduleProviderCloseNested(t *testing.T) { func TestContext2Apply_moduleVarRefExisting(t *testing.T) { m := testModule(t, "apply-ref-existing") p := testProvider("aws") - p.ApplyFn = testApplyFn - p.DiffFn = testDiffFn + p.ApplyResourceChangeFn = testApplyFn + p.PlanResourceChangeFn = testDiffFn state := states.NewState() root := state.EnsureModule(addrs.RootModuleInstance) root.SetResourceInstanceCurrent( @@ -2967,8 +2967,8 @@ func TestContext2Apply_moduleVarRefExisting(t *testing.T) { func TestContext2Apply_moduleVarResourceCount(t *testing.T) { m := testModule(t, "apply-module-var-resource-count") p := testProvider("aws") - p.ApplyFn = testApplyFn - p.DiffFn = testDiffFn + p.ApplyResourceChangeFn = testApplyFn + p.PlanResourceChangeFn = testDiffFn ctx := testContext2(t, &ContextOpts{ Config: m, Providers: map[addrs.Provider]providers.Factory{ @@ -3017,8 +3017,8 @@ func TestContext2Apply_moduleVarResourceCount(t *testing.T) { func TestContext2Apply_moduleBool(t *testing.T) { m := testModule(t, "apply-module-bool") p := testProvider("aws") - p.ApplyFn = testApplyFn - p.DiffFn = testDiffFn + p.ApplyResourceChangeFn = testApplyFn + p.PlanResourceChangeFn = testDiffFn ctx := testContext2(t, &ContextOpts{ Config: m, Providers: map[addrs.Provider]providers.Factory{ @@ -3047,8 +3047,8 @@ func TestContext2Apply_moduleBool(t *testing.T) { func TestContext2Apply_moduleTarget(t *testing.T) { m := testModule(t, "plan-targeted-cross-module") p := testProvider("aws") - p.ApplyFn = testApplyFn - p.DiffFn = testDiffFn + p.ApplyResourceChangeFn = testApplyFn + p.PlanResourceChangeFn = testDiffFn ctx := testContext2(t, &ContextOpts{ Config: m, Providers: map[addrs.Provider]providers.Factory{ @@ -3095,12 +3095,12 @@ module.B: func TestContext2Apply_multiProvider(t *testing.T) { m := testModule(t, "apply-multi-provider") p := testProvider("aws") - p.ApplyFn = testApplyFn - p.DiffFn = testDiffFn + p.ApplyResourceChangeFn = testApplyFn + p.PlanResourceChangeFn = testDiffFn pDO := testProvider("do") - pDO.ApplyFn = testApplyFn - pDO.DiffFn = testDiffFn + pDO.ApplyResourceChangeFn = testApplyFn + pDO.PlanResourceChangeFn = testDiffFn ctx := testContext2(t, &ContextOpts{ Config: m, @@ -3134,8 +3134,8 @@ func TestContext2Apply_multiProvider(t *testing.T) { func TestContext2Apply_multiProviderDestroy(t *testing.T) { m := testModule(t, "apply-multi-provider-destroy") p := testProvider("aws") - p.ApplyFn = testApplyFn - p.DiffFn = testDiffFn + p.ApplyResourceChangeFn = testApplyFn + p.PlanResourceChangeFn = testDiffFn p.GetSchemaReturn = &ProviderSchema{ Provider: &configschema.Block{ Attributes: map[string]*configschema.Attribute{ @@ -3153,8 +3153,8 @@ func TestContext2Apply_multiProviderDestroy(t *testing.T) { } p2 := testProvider("vault") - p2.ApplyFn = testApplyFn - p2.DiffFn = testDiffFn + p2.ApplyResourceChangeFn = testApplyFn + p2.PlanResourceChangeFn = testDiffFn p2.GetSchemaReturn = &ProviderSchema{ ResourceTypes: map[string]*configschema.Block{ "vault_instance": { @@ -3217,8 +3217,8 @@ func TestContext2Apply_multiProviderDestroy(t *testing.T) { } // Set the apply functions - p.ApplyFn = applyFn - p2.ApplyFn = applyFn + p.ApplyResourceChangeFn = applyFn + p2.ApplyResourceChangeFn = applyFn ctx := testContext2(t, &ContextOpts{ Destroy: true, @@ -3255,8 +3255,8 @@ func TestContext2Apply_multiProviderDestroy(t *testing.T) { func TestContext2Apply_multiProviderDestroyChild(t *testing.T) { m := testModule(t, "apply-multi-provider-destroy-child") p := testProvider("aws") - p.ApplyFn = testApplyFn - p.DiffFn = testDiffFn + p.ApplyResourceChangeFn = testApplyFn + p.PlanResourceChangeFn = testDiffFn p.GetSchemaReturn = &ProviderSchema{ Provider: &configschema.Block{ Attributes: map[string]*configschema.Attribute{ @@ -3274,8 +3274,8 @@ func TestContext2Apply_multiProviderDestroyChild(t *testing.T) { } p2 := testProvider("vault") - p2.ApplyFn = testApplyFn - p2.DiffFn = testDiffFn + p2.ApplyResourceChangeFn = testApplyFn + p2.PlanResourceChangeFn = testDiffFn p2.GetSchemaReturn = &ProviderSchema{ Provider: &configschema.Block{}, ResourceTypes: map[string]*configschema.Block{ @@ -3339,8 +3339,8 @@ func TestContext2Apply_multiProviderDestroyChild(t *testing.T) { } // Set the apply functions - p.ApplyFn = applyFn - p2.ApplyFn = applyFn + p.ApplyResourceChangeFn = applyFn + p2.ApplyResourceChangeFn = applyFn ctx := testContext2(t, &ContextOpts{ Destroy: true, @@ -3376,8 +3376,8 @@ func TestContext2Apply_multiProviderDestroyChild(t *testing.T) { func TestContext2Apply_multiVar(t *testing.T) { m := testModule(t, "apply-multi-var") p := testProvider("aws") - p.ApplyFn = testApplyFn - p.DiffFn = testDiffFn + p.ApplyResourceChangeFn = testApplyFn + p.PlanResourceChangeFn = testDiffFn // First, apply with a count of 3 ctx := testContext2(t, &ContextOpts{ @@ -3461,14 +3461,14 @@ func TestContext2Apply_multiVarComprehensive(t *testing.T) { configs := map[string]*ResourceConfig{} var configsLock sync.Mutex - p.ApplyFn = testApplyFn + p.ApplyResourceChangeFn = testApplyFn p.PlanResourceChangeFn = func(req providers.PlanResourceChangeRequest) providers.PlanResourceChangeResponse { proposed := req.ProposedNewState configsLock.Lock() defer configsLock.Unlock() key := proposed.GetAttr("key").AsString() - // This test was originally written using the legacy p.DiffFn interface, + // This test was originally written using the legacy p.PlanResourceChangeFn interface, // and so the assertions below expect an old-style ResourceConfig, which // we'll construct via our shim for now to avoid rewriting all of the // assertions. @@ -3666,8 +3666,8 @@ func TestContext2Apply_multiVarComprehensive(t *testing.T) { func TestContext2Apply_multiVarOrder(t *testing.T) { m := testModule(t, "apply-multi-var-order") p := testProvider("aws") - p.ApplyFn = testApplyFn - p.DiffFn = testDiffFn + p.ApplyResourceChangeFn = testApplyFn + p.PlanResourceChangeFn = testDiffFn // First, apply with a count of 3 ctx := testContext2(t, &ContextOpts{ @@ -3700,8 +3700,8 @@ func TestContext2Apply_multiVarOrder(t *testing.T) { func TestContext2Apply_multiVarOrderInterp(t *testing.T) { m := testModule(t, "apply-multi-var-order-interp") p := testProvider("aws") - p.ApplyFn = testApplyFn - p.DiffFn = testDiffFn + p.ApplyResourceChangeFn = testApplyFn + p.PlanResourceChangeFn = testDiffFn // First, apply with a count of 3 ctx := testContext2(t, &ContextOpts{ @@ -3738,8 +3738,8 @@ func TestContext2Apply_multiVarCountDec(t *testing.T) { { m := testModule(t, "apply-multi-var-count-dec") p := testProvider("aws") - p.ApplyFn = testApplyFn - p.DiffFn = testDiffFn + p.ApplyResourceChangeFn = testApplyFn + p.PlanResourceChangeFn = testDiffFn ctx := testContext2(t, &ContextOpts{ Config: m, Providers: map[addrs.Provider]providers.Factory{ @@ -3773,7 +3773,7 @@ func TestContext2Apply_multiVarCountDec(t *testing.T) { // right order. m := testModule(t, "apply-multi-var-count-dec") p := testProvider("aws") - p.DiffFn = testDiffFn + p.PlanResourceChangeFn = testDiffFn // Verify that aws_instance.bar is modified first and nothing // else happens at the same time. @@ -3781,7 +3781,7 @@ func TestContext2Apply_multiVarCountDec(t *testing.T) { var checked bool var called int32 var lock sync.Mutex - p.ApplyFn = func(req providers.ApplyResourceChangeRequest) (resp providers.ApplyResourceChangeResponse) { + p.ApplyResourceChangeFn = func(req providers.ApplyResourceChangeRequest) (resp providers.ApplyResourceChangeResponse) { lock.Lock() defer lock.Unlock() @@ -3845,8 +3845,8 @@ func TestContext2Apply_multiVarCountDec(t *testing.T) { func TestContext2Apply_multiVarMissingState(t *testing.T) { m := testModule(t, "apply-multi-var-missing-state") p := testProvider("test") - p.ApplyFn = testApplyFn - p.DiffFn = testDiffFn + p.ApplyResourceChangeFn = testApplyFn + p.PlanResourceChangeFn = testDiffFn p.GetSchemaReturn = &ProviderSchema{ ResourceTypes: map[string]*configschema.Block{ "test_thing": { @@ -3881,8 +3881,8 @@ func TestContext2Apply_multiVarMissingState(t *testing.T) { func TestContext2Apply_outputOrphan(t *testing.T) { m := testModule(t, "apply-output-orphan") p := testProvider("aws") - p.ApplyFn = testApplyFn - p.DiffFn = testDiffFn + p.ApplyResourceChangeFn = testApplyFn + p.PlanResourceChangeFn = testDiffFn state := states.NewState() root := state.EnsureModule(addrs.RootModuleInstance) @@ -3916,8 +3916,8 @@ func TestContext2Apply_outputOrphan(t *testing.T) { func TestContext2Apply_outputOrphanModule(t *testing.T) { m := testModule(t, "apply-output-orphan-module") p := testProvider("aws") - p.ApplyFn = testApplyFn - p.DiffFn = testDiffFn + p.ApplyResourceChangeFn = testApplyFn + p.PlanResourceChangeFn = testDiffFn state := states.NewState() @@ -3971,12 +3971,12 @@ func TestContext2Apply_outputOrphanModule(t *testing.T) { func TestContext2Apply_providerComputedVar(t *testing.T) { m := testModule(t, "apply-provider-computed") p := testProvider("aws") - p.ApplyFn = testApplyFn - p.DiffFn = testDiffFn + p.ApplyResourceChangeFn = testApplyFn + p.PlanResourceChangeFn = testDiffFn pTest := testProvider("test") - pTest.ApplyFn = testApplyFn - pTest.DiffFn = testDiffFn + pTest.ApplyResourceChangeFn = testApplyFn + pTest.PlanResourceChangeFn = testDiffFn ctx := testContext2(t, &ContextOpts{ Config: m, @@ -4007,8 +4007,8 @@ func TestContext2Apply_providerComputedVar(t *testing.T) { func TestContext2Apply_providerConfigureDisabled(t *testing.T) { m := testModule(t, "apply-provider-configure-disabled") p := testProvider("aws") - p.ApplyFn = testApplyFn - p.DiffFn = testDiffFn + p.ApplyResourceChangeFn = testApplyFn + p.PlanResourceChangeFn = testDiffFn p.ConfigureFn = func(req providers.ConfigureRequest) (resp providers.ConfigureResponse) { val := req.Config.GetAttr("value") @@ -4043,8 +4043,8 @@ func TestContext2Apply_provisionerModule(t *testing.T) { m := testModule(t, "apply-provisioner-module") p := testProvider("aws") - p.ApplyFn = testApplyFn - p.DiffFn = testDiffFn + p.ApplyResourceChangeFn = testApplyFn + p.PlanResourceChangeFn = testDiffFn pr := testProvisioner() pr.GetSchemaResponse = provisioners.GetSchemaResponse{ @@ -4090,15 +4090,16 @@ func TestContext2Apply_Provisioner_compute(t *testing.T) { m := testModule(t, "apply-provisioner-compute") p := testProvider("aws") pr := testProvisioner() - p.ApplyFn = testApplyFn - p.DiffFn = testDiffFn - pr.ApplyFn = func(rs *InstanceState, c *ResourceConfig) error { - val, ok := c.Config["command"] - if !ok || val != "computed_value" { - t.Fatalf("bad value for foo: %v %#v", val, c) + p.ApplyResourceChangeFn = testApplyFn + p.PlanResourceChangeFn = testDiffFn + pr.ProvisionResourceFn = func(req provisioners.ProvisionResourceRequest) (resp provisioners.ProvisionResourceResponse) { + + val := req.Config.GetAttr("command").AsString() + if val != "computed_value" { + t.Fatalf("bad value for foo: %q", val) } - return nil + return } ctx := testContext2(t, &ContextOpts{ Config: m, @@ -4141,9 +4142,9 @@ func TestContext2Apply_provisionerCreateFail(t *testing.T) { m := testModule(t, "apply-provisioner-fail-create") p := testProvider("aws") pr := testProvisioner() - p.DiffFn = testDiffFn + p.PlanResourceChangeFn = testDiffFn - p.ApplyFn = func(req providers.ApplyResourceChangeRequest) providers.ApplyResourceChangeResponse { + p.ApplyResourceChangeFn = func(req providers.ApplyResourceChangeRequest) providers.ApplyResourceChangeResponse { resp := testApplyFn(req) resp.Diagnostics = resp.Diagnostics.Append(fmt.Errorf("error")) @@ -4180,9 +4181,9 @@ func TestContext2Apply_provisionerCreateFailNoId(t *testing.T) { m := testModule(t, "apply-provisioner-fail-create") p := testProvider("aws") pr := testProvisioner() - p.DiffFn = testDiffFn + p.PlanResourceChangeFn = testDiffFn - p.ApplyFn = func(req providers.ApplyResourceChangeRequest) (resp providers.ApplyResourceChangeResponse) { + p.ApplyResourceChangeFn = func(req providers.ApplyResourceChangeRequest) (resp providers.ApplyResourceChangeResponse) { resp.Diagnostics = resp.Diagnostics.Append(fmt.Errorf("error")) return } @@ -4217,10 +4218,11 @@ func TestContext2Apply_provisionerFail(t *testing.T) { m := testModule(t, "apply-provisioner-fail") p := testProvider("aws") pr := testProvisioner() - p.DiffFn = testDiffFn - p.ApplyFn = testApplyFn - pr.ApplyFn = func(*InstanceState, *ResourceConfig) error { - return fmt.Errorf("EXPLOSION") + p.PlanResourceChangeFn = testDiffFn + p.ApplyResourceChangeFn = testApplyFn + pr.ProvisionResourceFn = func(req provisioners.ProvisionResourceRequest) (resp provisioners.ProvisionResourceResponse) { + resp.Diagnostics = resp.Diagnostics.Append(fmt.Errorf("EXPLOSION")) + return } ctx := testContext2(t, &ContextOpts{ @@ -4253,10 +4255,11 @@ func TestContext2Apply_provisionerFail_createBeforeDestroy(t *testing.T) { m := testModule(t, "apply-provisioner-fail-create-before") p := testProvider("aws") pr := testProvisioner() - p.ApplyFn = testApplyFn - p.DiffFn = testDiffFn - pr.ApplyFn = func(*InstanceState, *ResourceConfig) error { - return fmt.Errorf("EXPLOSION") + p.ApplyResourceChangeFn = testApplyFn + p.PlanResourceChangeFn = testDiffFn + pr.ProvisionResourceFn = func(req provisioners.ProvisionResourceRequest) (resp provisioners.ProvisionResourceResponse) { + resp.Diagnostics = resp.Diagnostics.Append(fmt.Errorf("EXPLOSION")) + return } state := states.NewState() @@ -4319,11 +4322,11 @@ func TestContext2Apply_error_createBeforeDestroy(t *testing.T) { }, State: state, }) - p.ApplyFn = func(req providers.ApplyResourceChangeRequest) (resp providers.ApplyResourceChangeResponse) { + p.ApplyResourceChangeFn = func(req providers.ApplyResourceChangeRequest) (resp providers.ApplyResourceChangeResponse) { resp.Diagnostics = resp.Diagnostics.Append(fmt.Errorf("placeholder error from ApplyFn")) return } - p.DiffFn = testDiffFn + p.PlanResourceChangeFn = testDiffFn if _, diags := ctx.Plan(); diags.HasErrors() { t.Fatalf("plan errors: %s", diags.Err()) @@ -4368,7 +4371,7 @@ func TestContext2Apply_errorDestroy_createBeforeDestroy(t *testing.T) { }, State: state, }) - p.ApplyFn = func(req providers.ApplyResourceChangeRequest) (resp providers.ApplyResourceChangeResponse) { + p.ApplyResourceChangeFn = func(req providers.ApplyResourceChangeRequest) (resp providers.ApplyResourceChangeResponse) { // Fail the destroy! if req.PlannedState.IsNull() { resp.NewState = req.PriorState @@ -4378,7 +4381,7 @@ func TestContext2Apply_errorDestroy_createBeforeDestroy(t *testing.T) { return testApplyFn(req) } - p.DiffFn = testDiffFn + p.PlanResourceChangeFn = testDiffFn if _, diags := ctx.Plan(); diags.HasErrors() { t.Fatalf("plan errors: %s", diags.Err()) @@ -4422,7 +4425,7 @@ func TestContext2Apply_multiDepose_createBeforeDestroy(t *testing.T) { mustProviderConfig(`provider["registry.terraform.io/hashicorp/aws"]`), ) - p.DiffFn = testDiffFn + p.PlanResourceChangeFn = testDiffFn ctx := testContext2(t, &ContextOpts{ Config: m, @@ -4449,7 +4452,7 @@ func TestContext2Apply_multiDepose_createBeforeDestroy(t *testing.T) { resp.Diagnostics = resp.Diagnostics.Append(fmt.Errorf("destroy failed")) return } - p.ApplyFn = func(req providers.ApplyResourceChangeRequest) (resp providers.ApplyResourceChangeResponse) { + p.ApplyResourceChangeFn = func(req providers.ApplyResourceChangeRequest) (resp providers.ApplyResourceChangeResponse) { if req.PlannedState.IsNull() { return destroyFunc(req) } else { @@ -4613,11 +4616,12 @@ func TestContext2Apply_provisionerFailContinue(t *testing.T) { m := testModule(t, "apply-provisioner-fail-continue") p := testProvider("aws") pr := testProvisioner() - p.ApplyFn = testApplyFn - p.DiffFn = testDiffFn + p.ApplyResourceChangeFn = testApplyFn + p.PlanResourceChangeFn = testDiffFn - pr.ApplyFn = func(rs *InstanceState, c *ResourceConfig) error { - return fmt.Errorf("provisioner error") + pr.ProvisionResourceFn = func(req provisioners.ProvisionResourceRequest) (resp provisioners.ProvisionResourceResponse) { + resp.Diagnostics = resp.Diagnostics.Append(fmt.Errorf("provisioner error")) + return } ctx := testContext2(t, &ContextOpts{ @@ -4660,10 +4664,11 @@ func TestContext2Apply_provisionerFailContinueHook(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") + p.ApplyResourceChangeFn = testApplyFn + p.PlanResourceChangeFn = testDiffFn + pr.ProvisionResourceFn = func(req provisioners.ProvisionResourceRequest) (resp provisioners.ProvisionResourceResponse) { + resp.Diagnostics = resp.Diagnostics.Append(fmt.Errorf("provisioner error")) + return } ctx := testContext2(t, &ContextOpts{ @@ -4697,15 +4702,15 @@ func TestContext2Apply_provisionerDestroy(t *testing.T) { m := testModule(t, "apply-provisioner-destroy") p := testProvider("aws") pr := testProvisioner() - p.ApplyFn = testApplyFn - p.DiffFn = testDiffFn - pr.ApplyFn = func(rs *InstanceState, c *ResourceConfig) error { - val, ok := c.Config["command"] - if !ok || val != "destroy a bar" { - t.Fatalf("bad value for foo: %v %#v", val, c) + p.ApplyResourceChangeFn = testApplyFn + p.PlanResourceChangeFn = testDiffFn + pr.ProvisionResourceFn = func(req provisioners.ProvisionResourceRequest) (resp provisioners.ProvisionResourceResponse) { + val := req.Config.GetAttr("command").AsString() + if val != "destroy a bar" { + t.Fatalf("bad value for foo: %q", val) } - return nil + return } state := states.NewState() @@ -4753,10 +4758,11 @@ func TestContext2Apply_provisionerDestroyFail(t *testing.T) { m := testModule(t, "apply-provisioner-destroy") p := testProvider("aws") pr := testProvisioner() - p.ApplyFn = testApplyFn - p.DiffFn = testDiffFn - pr.ApplyFn = func(rs *InstanceState, c *ResourceConfig) error { - return fmt.Errorf("provisioner error") + p.ApplyResourceChangeFn = testApplyFn + p.PlanResourceChangeFn = testDiffFn + pr.ProvisionResourceFn = func(req provisioners.ProvisionResourceRequest) (resp provisioners.ProvisionResourceResponse) { + resp.Diagnostics = resp.Diagnostics.Append(fmt.Errorf("provisioner error")) + return } state := states.NewState() @@ -4810,21 +4816,22 @@ func TestContext2Apply_provisionerDestroyFailContinue(t *testing.T) { m := testModule(t, "apply-provisioner-destroy-continue") p := testProvider("aws") pr := testProvisioner() - p.ApplyFn = testApplyFn - p.DiffFn = testDiffFn + p.ApplyResourceChangeFn = testApplyFn + p.PlanResourceChangeFn = testDiffFn var l sync.Mutex var calls []string - pr.ApplyFn = func(rs *InstanceState, c *ResourceConfig) error { - val, ok := c.Config["command"] - if !ok { - t.Fatalf("bad value for foo: %v %#v", val, c) + pr.ProvisionResourceFn = func(req provisioners.ProvisionResourceRequest) (resp provisioners.ProvisionResourceResponse) { + val := req.Config.GetAttr("command") + if val.IsNull() { + t.Fatalf("bad value for foo: %#v", val) } l.Lock() defer l.Unlock() - calls = append(calls, val.(string)) - return fmt.Errorf("provisioner error") + calls = append(calls, val.AsString()) + resp.Diagnostics = resp.Diagnostics.Append(fmt.Errorf("provisioner error")) + return } state := states.NewState() @@ -4879,21 +4886,22 @@ func TestContext2Apply_provisionerDestroyFailContinueFail(t *testing.T) { m := testModule(t, "apply-provisioner-destroy-fail") p := testProvider("aws") pr := testProvisioner() - p.ApplyFn = testApplyFn - p.DiffFn = testDiffFn + p.ApplyResourceChangeFn = testApplyFn + p.PlanResourceChangeFn = testDiffFn var l sync.Mutex var calls []string - pr.ApplyFn = func(rs *InstanceState, c *ResourceConfig) error { - val, ok := c.Config["command"] - if !ok { - t.Fatalf("bad value for foo: %v %#v", val, c) + pr.ProvisionResourceFn = func(req provisioners.ProvisionResourceRequest) (resp provisioners.ProvisionResourceResponse) { + val := req.Config.GetAttr("command") + if val.IsNull() { + t.Fatalf("bad value for foo: %#v", val) } l.Lock() defer l.Unlock() - calls = append(calls, val.(string)) - return fmt.Errorf("provisioner error") + calls = append(calls, val.AsString()) + resp.Diagnostics = resp.Diagnostics.Append(fmt.Errorf("provisioner error")) + return } state := states.NewState() @@ -4950,23 +4958,18 @@ func TestContext2Apply_provisionerDestroyTainted(t *testing.T) { m := testModule(t, "apply-provisioner-destroy") p := testProvider("aws") pr := testProvisioner() - p.ApplyFn = testApplyFn - p.DiffFn = testDiffFn + p.ApplyResourceChangeFn = testApplyFn + p.PlanResourceChangeFn = testDiffFn destroyCalled := false - pr.ApplyFn = func(rs *InstanceState, c *ResourceConfig) error { + pr.ProvisionResourceFn = func(req provisioners.ProvisionResourceRequest) (resp provisioners.ProvisionResourceResponse) { expected := "create a b" - if rs.ID == "bar" { - destroyCalled = true - return nil + val := req.Config.GetAttr("command") + if val.AsString() != expected { + t.Fatalf("bad value for command: %#v", val) } - val, ok := c.Config["command"] - if !ok || val != expected { - t.Fatalf("bad value for command: %v %#v", val, c) - } - - return nil + return } state := states.NewState() @@ -5029,17 +5032,17 @@ aws_instance.foo["a"]: func TestContext2Apply_provisionerResourceRef(t *testing.T) { m := testModule(t, "apply-provisioner-resource-ref") p := testProvider("aws") - p.ApplyFn = testApplyFn - p.DiffFn = testDiffFn + p.ApplyResourceChangeFn = testApplyFn + p.PlanResourceChangeFn = testDiffFn pr := testProvisioner() - pr.ApplyFn = func(rs *InstanceState, c *ResourceConfig) error { - val, ok := c.Config["command"] - if !ok || val != "2" { - t.Fatalf("bad value for foo: %v %#v", val, c) + pr.ProvisionResourceFn = func(req provisioners.ProvisionResourceRequest) (resp provisioners.ProvisionResourceResponse) { + val := req.Config.GetAttr("command") + if val.AsString() != "2" { + t.Fatalf("bad value for command: %#v", val) } - return nil + return } ctx := testContext2(t, &ContextOpts{ @@ -5077,15 +5080,15 @@ func TestContext2Apply_provisionerSelfRef(t *testing.T) { m := testModule(t, "apply-provisioner-self-ref") p := testProvider("aws") pr := testProvisioner() - p.ApplyFn = testApplyFn - p.DiffFn = testDiffFn - pr.ApplyFn = func(rs *InstanceState, c *ResourceConfig) error { - val, ok := c.Config["command"] - if !ok || val != "bar" { - t.Fatalf("bad value for command: %v %#v", val, c) + p.ApplyResourceChangeFn = testApplyFn + p.PlanResourceChangeFn = testDiffFn + pr.ProvisionResourceFn = func(req provisioners.ProvisionResourceRequest) (resp provisioners.ProvisionResourceResponse) { + val := req.Config.GetAttr("command") + if val.AsString() != "bar" { + t.Fatalf("bad value for command: %#v", val) } - return nil + return } ctx := testContext2(t, &ContextOpts{ @@ -5126,19 +5129,19 @@ func TestContext2Apply_provisionerMultiSelfRef(t *testing.T) { m := testModule(t, "apply-provisioner-multi-self-ref") p := testProvider("aws") pr := testProvisioner() - p.ApplyFn = testApplyFn - p.DiffFn = testDiffFn - pr.ApplyFn = func(rs *InstanceState, c *ResourceConfig) error { + p.ApplyResourceChangeFn = testApplyFn + p.PlanResourceChangeFn = testDiffFn + pr.ProvisionResourceFn = func(req provisioners.ProvisionResourceRequest) (resp provisioners.ProvisionResourceResponse) { lock.Lock() defer lock.Unlock() - val, ok := c.Config["command"] - if !ok { - t.Fatalf("bad value for command: %v %#v", val, c) + val := req.Config.GetAttr("command") + if val.IsNull() { + t.Fatalf("bad value for command: %#v", val) } - commands = append(commands, val.(string)) - return nil + commands = append(commands, val.AsString()) + return } ctx := testContext2(t, &ContextOpts{ @@ -5186,19 +5189,19 @@ func TestContext2Apply_provisionerMultiSelfRefSingle(t *testing.T) { m := testModule(t, "apply-provisioner-multi-self-ref-single") p := testProvider("aws") pr := testProvisioner() - p.ApplyFn = testApplyFn - p.DiffFn = testDiffFn - pr.ApplyFn = func(rs *InstanceState, c *ResourceConfig) error { + p.ApplyResourceChangeFn = testApplyFn + p.PlanResourceChangeFn = testDiffFn + pr.ProvisionResourceFn = func(req provisioners.ProvisionResourceRequest) (resp provisioners.ProvisionResourceResponse) { lock.Lock() defer lock.Unlock() - val, ok := c.Config["order"] - if !ok { - t.Fatalf("bad value for order: %v %#v", val, c) + val := req.Config.GetAttr("order") + if val.IsNull() { + t.Fatalf("no val for order") } - order = append(order, val.(string)) - return nil + order = append(order, val.AsString()) + return } ctx := testContext2(t, &ContextOpts{ @@ -5243,15 +5246,15 @@ func TestContext2Apply_provisionerExplicitSelfRef(t *testing.T) { m := testModule(t, "apply-provisioner-explicit-self-ref") p := testProvider("aws") pr := testProvisioner() - p.ApplyFn = testApplyFn - p.DiffFn = testDiffFn - pr.ApplyFn = func(rs *InstanceState, c *ResourceConfig) error { - val, ok := c.Config["command"] - if !ok || val != "bar" { - t.Fatalf("bad value for command: %v %#v", val, c) + p.ApplyResourceChangeFn = testApplyFn + p.PlanResourceChangeFn = testDiffFn + pr.ProvisionResourceFn = func(req provisioners.ProvisionResourceRequest) (resp provisioners.ProvisionResourceResponse) { + val := req.Config.GetAttr("command") + if val.IsNull() || val.AsString() != "bar" { + t.Fatalf("bad value for command: %#v", val) } - return nil + return } var state *states.State @@ -5313,16 +5316,16 @@ func TestContext2Apply_provisionerForEachSelfRef(t *testing.T) { m := testModule(t, "apply-provisioner-for-each-self") p := testProvider("aws") pr := testProvisioner() - p.ApplyFn = testApplyFn - p.DiffFn = testDiffFn + p.ApplyResourceChangeFn = testApplyFn + p.PlanResourceChangeFn = testDiffFn - pr.ApplyFn = func(rs *InstanceState, c *ResourceConfig) error { - val, ok := c.Config["command"] - if !ok { - t.Fatalf("bad value for command: %v %#v", val, c) + pr.ProvisionResourceFn = func(req provisioners.ProvisionResourceRequest) (resp provisioners.ProvisionResourceResponse) { + val := req.Config.GetAttr("command") + if val.IsNull() { + t.Fatalf("bad value for command: %#v", val) } - return nil + return resp } ctx := testContext2(t, &ContextOpts{ @@ -5350,11 +5353,8 @@ func TestContext2Apply_Provisioner_Diff(t *testing.T) { m := testModule(t, "apply-provisioner-diff") p := testProvider("aws") pr := testProvisioner() - p.ApplyFn = testApplyFn - p.DiffFn = testDiffFn - pr.ApplyFn = func(rs *InstanceState, c *ResourceConfig) error { - return nil - } + p.ApplyResourceChangeFn = testApplyFn + p.PlanResourceChangeFn = testDiffFn ctx := testContext2(t, &ContextOpts{ Config: m, Providers: map[addrs.Provider]providers.Factory{ @@ -5459,8 +5459,8 @@ func TestContext2Apply_outputDiffVars(t *testing.T) { State: state, }) - p.ApplyFn = testApplyFn - p.DiffFn = testDiffFn + p.ApplyResourceChangeFn = testApplyFn + p.PlanResourceChangeFn = testDiffFn //func(info *InstanceInfo, s *InstanceState, rc *ResourceConfig) (*InstanceDiff, error) { // d := &InstanceDiff{ // Attributes: map[string]*ResourceAttrDiff{}, @@ -5502,8 +5502,8 @@ func TestContext2Apply_destroyX(t *testing.T) { m := testModule(t, "apply-destroy") h := new(HookRecordApplyOrder) p := testProvider("aws") - p.ApplyFn = testApplyFn - p.DiffFn = testDiffFn + p.ApplyResourceChangeFn = testApplyFn + p.PlanResourceChangeFn = testDiffFn ctx := testContext2(t, &ContextOpts{ Config: m, Hooks: []Hook{h}, @@ -5562,8 +5562,8 @@ func TestContext2Apply_destroyOrder(t *testing.T) { m := testModule(t, "apply-destroy") h := new(HookRecordApplyOrder) p := testProvider("aws") - p.ApplyFn = testApplyFn - p.DiffFn = testDiffFn + p.ApplyResourceChangeFn = testApplyFn + p.PlanResourceChangeFn = testDiffFn ctx := testContext2(t, &ContextOpts{ Config: m, Hooks: []Hook{h}, @@ -5625,8 +5625,8 @@ func TestContext2Apply_destroyModulePrefix(t *testing.T) { m := testModule(t, "apply-destroy-module-resource-prefix") h := new(MockHook) p := testProvider("aws") - p.ApplyFn = testApplyFn - p.DiffFn = testDiffFn + p.ApplyResourceChangeFn = testApplyFn + p.PlanResourceChangeFn = testDiffFn ctx := testContext2(t, &ContextOpts{ Config: m, Hooks: []Hook{h}, @@ -5680,8 +5680,8 @@ func TestContext2Apply_destroyModulePrefix(t *testing.T) { func TestContext2Apply_destroyNestedModule(t *testing.T) { m := testModule(t, "apply-destroy-nested-module") p := testProvider("aws") - p.ApplyFn = testApplyFn - p.DiffFn = testDiffFn + p.ApplyResourceChangeFn = testApplyFn + p.PlanResourceChangeFn = testDiffFn state := states.NewState() root := state.EnsureModule(addrs.RootModuleInstance) @@ -5722,8 +5722,8 @@ func TestContext2Apply_destroyNestedModule(t *testing.T) { func TestContext2Apply_destroyDeeplyNestedModule(t *testing.T) { m := testModule(t, "apply-destroy-deeply-nested-module") p := testProvider("aws") - p.ApplyFn = testApplyFn - p.DiffFn = testDiffFn + p.ApplyResourceChangeFn = testApplyFn + p.PlanResourceChangeFn = testDiffFn state := states.NewState() root := state.EnsureModule(addrs.RootModuleInstance) @@ -5764,8 +5764,8 @@ func TestContext2Apply_destroyDeeplyNestedModule(t *testing.T) { func TestContext2Apply_destroyModuleWithAttrsReferencingResource(t *testing.T) { m, snap := testModuleWithSnapshot(t, "apply-destroy-module-with-attrs") p := testProvider("aws") - p.ApplyFn = testApplyFn - p.DiffFn = testDiffFn + p.ApplyResourceChangeFn = testApplyFn + p.PlanResourceChangeFn = testDiffFn var state *states.State { @@ -5845,8 +5845,8 @@ func TestContext2Apply_destroyModuleWithAttrsReferencingResource(t *testing.T) { func TestContext2Apply_destroyWithModuleVariableAndCount(t *testing.T) { m, snap := testModuleWithSnapshot(t, "apply-destroy-mod-var-and-count") p := testProvider("aws") - p.ApplyFn = testApplyFn - p.DiffFn = testDiffFn + p.ApplyResourceChangeFn = testApplyFn + p.PlanResourceChangeFn = testDiffFn var state *states.State var diags tfdiags.Diagnostics @@ -5922,8 +5922,8 @@ func TestContext2Apply_destroyWithModuleVariableAndCount(t *testing.T) { func TestContext2Apply_destroyTargetWithModuleVariableAndCount(t *testing.T) { m := testModule(t, "apply-destroy-mod-var-and-count") p := testProvider("aws") - p.ApplyFn = testApplyFn - p.DiffFn = testDiffFn + p.ApplyResourceChangeFn = testApplyFn + p.PlanResourceChangeFn = testDiffFn var state *states.State var diags tfdiags.Diagnostics @@ -6001,8 +6001,8 @@ func TestContext2Apply_destroyTargetWithModuleVariableAndCount(t *testing.T) { func TestContext2Apply_destroyWithModuleVariableAndCountNested(t *testing.T) { m, snap := testModuleWithSnapshot(t, "apply-destroy-mod-var-and-count-nested") p := testProvider("aws") - p.ApplyFn = testApplyFn - p.DiffFn = testDiffFn + p.ApplyResourceChangeFn = testApplyFn + p.PlanResourceChangeFn = testDiffFn var state *states.State var diags tfdiags.Diagnostics @@ -6078,8 +6078,8 @@ func TestContext2Apply_destroyWithModuleVariableAndCountNested(t *testing.T) { func TestContext2Apply_destroyOutputs(t *testing.T) { m := testModule(t, "apply-destroy-outputs") p := testProvider("test") - p.ApplyFn = testApplyFn - p.DiffFn = testDiffFn + p.ApplyResourceChangeFn = testApplyFn + p.PlanResourceChangeFn = testDiffFn p.ReadDataSourceFn = func(req providers.ReadDataSourceRequest) providers.ReadDataSourceResponse { // add the required id @@ -6172,8 +6172,8 @@ func TestContext2Apply_destroyOrphan(t *testing.T) { State: state, }) - p.ApplyFn = testApplyFn - p.DiffFn = testDiffFn + p.ApplyResourceChangeFn = testApplyFn + p.PlanResourceChangeFn = testDiffFn if _, diags := ctx.Plan(); diags.HasErrors() { t.Fatalf("plan errors: %s", diags.Err()) @@ -6194,14 +6194,8 @@ func TestContext2Apply_destroyTaintedProvisioner(t *testing.T) { m := testModule(t, "apply-destroy-provisioner") p := testProvider("aws") pr := testProvisioner() - p.ApplyFn = testApplyFn - p.DiffFn = testDiffFn - - called := false - pr.ApplyFn = func(rs *InstanceState, c *ResourceConfig) error { - called = true - return nil - } + p.ApplyResourceChangeFn = testApplyFn + p.PlanResourceChangeFn = testDiffFn state := states.NewState() root := state.EnsureModule(addrs.RootModuleInstance) @@ -6235,7 +6229,7 @@ func TestContext2Apply_destroyTaintedProvisioner(t *testing.T) { t.Fatalf("diags: %s", diags.Err()) } - if called { + if pr.ProvisionResourceCalled { t.Fatal("provisioner should not be called") } @@ -6258,7 +6252,7 @@ func TestContext2Apply_error(t *testing.T) { }, }) - p.ApplyFn = func(req providers.ApplyResourceChangeRequest) (resp providers.ApplyResourceChangeResponse) { + p.ApplyResourceChangeFn = func(req providers.ApplyResourceChangeRequest) (resp providers.ApplyResourceChangeResponse) { if errored { resp.NewState = req.PlannedState resp.Diagnostics = resp.Diagnostics.Append(fmt.Errorf("error")) @@ -6268,7 +6262,7 @@ func TestContext2Apply_error(t *testing.T) { return testApplyFn(req) } - p.DiffFn = testDiffFn + p.PlanResourceChangeFn = testDiffFn if _, diags := ctx.Plan(); diags.HasErrors() { t.Fatalf("plan errors: %s", diags.Err()) @@ -6534,7 +6528,7 @@ func TestContext2Apply_errorPartial(t *testing.T) { State: state, }) - p.ApplyFn = func(req providers.ApplyResourceChangeRequest) (resp providers.ApplyResourceChangeResponse) { + p.ApplyResourceChangeFn = func(req providers.ApplyResourceChangeRequest) (resp providers.ApplyResourceChangeResponse) { if errored { resp.Diagnostics = resp.Diagnostics.Append(fmt.Errorf("error")) return @@ -6543,7 +6537,7 @@ func TestContext2Apply_errorPartial(t *testing.T) { return testApplyFn(req) } - p.DiffFn = testDiffFn + p.PlanResourceChangeFn = testDiffFn if _, diags := ctx.Plan(); diags.HasErrors() { t.Fatalf("plan errors: %s", diags.Err()) @@ -6570,8 +6564,8 @@ func TestContext2Apply_hook(t *testing.T) { m := testModule(t, "apply-good") h := new(MockHook) p := testProvider("aws") - p.ApplyFn = testApplyFn - p.DiffFn = testDiffFn + p.ApplyResourceChangeFn = testApplyFn + p.PlanResourceChangeFn = testDiffFn ctx := testContext2(t, &ContextOpts{ Config: m, Hooks: []Hook{h}, @@ -6603,8 +6597,8 @@ func TestContext2Apply_hookOrphan(t *testing.T) { m := testModule(t, "apply-blank") h := new(MockHook) p := testProvider("aws") - p.ApplyFn = testApplyFn - p.DiffFn = testDiffFn + p.ApplyResourceChangeFn = testApplyFn + p.PlanResourceChangeFn = testDiffFn state := states.NewState() root := state.EnsureModule(addrs.RootModuleInstance) @@ -6655,8 +6649,8 @@ func TestContext2Apply_idAttr(t *testing.T) { }, }) - p.ApplyFn = testApplyFn - p.DiffFn = testDiffFn + p.ApplyResourceChangeFn = testApplyFn + p.PlanResourceChangeFn = testDiffFn if _, diags := ctx.Plan(); diags.HasErrors() { t.Fatalf("plan errors: %s", diags.Err()) @@ -6685,8 +6679,8 @@ func TestContext2Apply_idAttr(t *testing.T) { func TestContext2Apply_outputBasic(t *testing.T) { m := testModule(t, "apply-output") p := testProvider("aws") - p.ApplyFn = testApplyFn - p.DiffFn = testDiffFn + p.ApplyResourceChangeFn = testApplyFn + p.PlanResourceChangeFn = testDiffFn ctx := testContext2(t, &ContextOpts{ Config: m, Providers: map[addrs.Provider]providers.Factory{ @@ -6713,8 +6707,8 @@ func TestContext2Apply_outputBasic(t *testing.T) { func TestContext2Apply_outputAdd(t *testing.T) { m1 := testModule(t, "apply-output-add-before") p1 := testProvider("aws") - p1.ApplyFn = testApplyFn - p1.DiffFn = testDiffFn + p1.ApplyResourceChangeFn = testApplyFn + p1.PlanResourceChangeFn = testDiffFn ctx1 := testContext2(t, &ContextOpts{ Config: m1, Providers: map[addrs.Provider]providers.Factory{ @@ -6733,8 +6727,8 @@ func TestContext2Apply_outputAdd(t *testing.T) { m2 := testModule(t, "apply-output-add-after") p2 := testProvider("aws") - p2.ApplyFn = testApplyFn - p2.DiffFn = testDiffFn + p2.ApplyResourceChangeFn = testApplyFn + p2.PlanResourceChangeFn = testDiffFn ctx2 := testContext2(t, &ContextOpts{ Config: m2, Providers: map[addrs.Provider]providers.Factory{ @@ -6763,8 +6757,8 @@ func TestContext2Apply_outputAdd(t *testing.T) { func TestContext2Apply_outputList(t *testing.T) { m := testModule(t, "apply-output-list") p := testProvider("aws") - p.ApplyFn = testApplyFn - p.DiffFn = testDiffFn + p.ApplyResourceChangeFn = testApplyFn + p.PlanResourceChangeFn = testDiffFn ctx := testContext2(t, &ContextOpts{ Config: m, Providers: map[addrs.Provider]providers.Factory{ @@ -6791,8 +6785,8 @@ func TestContext2Apply_outputList(t *testing.T) { func TestContext2Apply_outputMulti(t *testing.T) { m := testModule(t, "apply-output-multi") p := testProvider("aws") - p.ApplyFn = testApplyFn - p.DiffFn = testDiffFn + p.ApplyResourceChangeFn = testApplyFn + p.PlanResourceChangeFn = testDiffFn ctx := testContext2(t, &ContextOpts{ Config: m, Providers: map[addrs.Provider]providers.Factory{ @@ -6819,8 +6813,8 @@ func TestContext2Apply_outputMulti(t *testing.T) { func TestContext2Apply_outputMultiIndex(t *testing.T) { m := testModule(t, "apply-output-multi-index") p := testProvider("aws") - p.ApplyFn = testApplyFn - p.DiffFn = testDiffFn + p.ApplyResourceChangeFn = testApplyFn + p.PlanResourceChangeFn = testDiffFn ctx := testContext2(t, &ContextOpts{ Config: m, Providers: map[addrs.Provider]providers.Factory{ @@ -6855,14 +6849,14 @@ func TestContext2Apply_taintX(t *testing.T) { time.Sleep(10 * time.Millisecond) } - p.ApplyFn = func(req providers.ApplyResourceChangeRequest) providers.ApplyResourceChangeResponse { + p.ApplyResourceChangeFn = func(req providers.ApplyResourceChangeRequest) providers.ApplyResourceChangeResponse { once.Do(simulateProviderDelay) if req.PlannedState.IsNull() { atomic.AddInt32(&destroyCount, 1) } return testApplyFn(req) } - p.DiffFn = testDiffFn + p.PlanResourceChangeFn = testDiffFn state := states.NewState() root := state.EnsureModule(addrs.RootModuleInstance) @@ -6908,8 +6902,8 @@ func TestContext2Apply_taintX(t *testing.T) { func TestContext2Apply_taintDep(t *testing.T) { m := testModule(t, "apply-taint-dep") p := testProvider("aws") - p.ApplyFn = testApplyFn - p.DiffFn = testDiffFn + p.ApplyResourceChangeFn = testApplyFn + p.PlanResourceChangeFn = testDiffFn state := states.NewState() root := state.EnsureModule(addrs.RootModuleInstance) @@ -6960,8 +6954,8 @@ func TestContext2Apply_taintDep(t *testing.T) { func TestContext2Apply_taintDepRequiresNew(t *testing.T) { m := testModule(t, "apply-taint-dep-requires-new") p := testProvider("aws") - p.ApplyFn = testApplyFn - p.DiffFn = testDiffFn + p.ApplyResourceChangeFn = testApplyFn + p.PlanResourceChangeFn = testDiffFn state := states.NewState() root := state.EnsureModule(addrs.RootModuleInstance) @@ -7012,8 +7006,8 @@ func TestContext2Apply_taintDepRequiresNew(t *testing.T) { func TestContext2Apply_targeted(t *testing.T) { m := testModule(t, "apply-targeted") p := testProvider("aws") - p.ApplyFn = testApplyFn - p.DiffFn = testDiffFn + p.ApplyResourceChangeFn = testApplyFn + p.PlanResourceChangeFn = testDiffFn ctx := testContext2(t, &ContextOpts{ Config: m, Providers: map[addrs.Provider]providers.Factory{ @@ -7052,8 +7046,8 @@ aws_instance.foo: func TestContext2Apply_targetedCount(t *testing.T) { m := testModule(t, "apply-targeted-count") p := testProvider("aws") - p.ApplyFn = testApplyFn - p.DiffFn = testDiffFn + p.ApplyResourceChangeFn = testApplyFn + p.PlanResourceChangeFn = testDiffFn ctx := testContext2(t, &ContextOpts{ Config: m, Providers: map[addrs.Provider]providers.Factory{ @@ -7094,8 +7088,8 @@ aws_instance.foo.2: func TestContext2Apply_targetedCountIndex(t *testing.T) { m := testModule(t, "apply-targeted-count") p := testProvider("aws") - p.ApplyFn = testApplyFn - p.DiffFn = testDiffFn + p.ApplyResourceChangeFn = testApplyFn + p.PlanResourceChangeFn = testDiffFn ctx := testContext2(t, &ContextOpts{ Config: m, Providers: map[addrs.Provider]providers.Factory{ @@ -7128,8 +7122,8 @@ aws_instance.foo.1: func TestContext2Apply_targetedDestroy(t *testing.T) { m := testModule(t, "destroy-targeted") p := testProvider("aws") - p.ApplyFn = testApplyFn - p.DiffFn = testDiffFn + p.ApplyResourceChangeFn = testApplyFn + p.PlanResourceChangeFn = testDiffFn state := states.NewState() root := state.EnsureModule(addrs.RootModuleInstance) @@ -7210,8 +7204,8 @@ func TestContext2Apply_targetedDestroy(t *testing.T) { func TestContext2Apply_targetedDestroyCountDeps(t *testing.T) { m := testModule(t, "apply-destroy-targeted-count") p := testProvider("aws") - p.ApplyFn = testApplyFn - p.DiffFn = testDiffFn + p.ApplyResourceChangeFn = testApplyFn + p.PlanResourceChangeFn = testDiffFn state := states.NewState() root := state.EnsureModule(addrs.RootModuleInstance) @@ -7263,8 +7257,8 @@ func TestContext2Apply_targetedDestroyCountDeps(t *testing.T) { func TestContext2Apply_targetedDestroyModule(t *testing.T) { m := testModule(t, "apply-targeted-module") p := testProvider("aws") - p.ApplyFn = testApplyFn - p.DiffFn = testDiffFn + p.ApplyResourceChangeFn = testApplyFn + p.PlanResourceChangeFn = testDiffFn state := states.NewState() root := state.EnsureModule(addrs.RootModuleInstance) @@ -7343,8 +7337,8 @@ module.child: func TestContext2Apply_targetedDestroyCountIndex(t *testing.T) { m := testModule(t, "apply-targeted-count") p := testProvider("aws") - p.ApplyFn = testApplyFn - p.DiffFn = testDiffFn + p.ApplyResourceChangeFn = testApplyFn + p.PlanResourceChangeFn = testDiffFn foo := &states.ResourceInstanceObjectSrc{ Status: states.ObjectReady, @@ -7433,8 +7427,8 @@ aws_instance.foo.1: func TestContext2Apply_targetedModule(t *testing.T) { m := testModule(t, "apply-targeted-module") p := testProvider("aws") - p.ApplyFn = testApplyFn - p.DiffFn = testDiffFn + p.ApplyResourceChangeFn = testApplyFn + p.PlanResourceChangeFn = testDiffFn ctx := testContext2(t, &ContextOpts{ Config: m, Providers: map[addrs.Provider]providers.Factory{ @@ -7482,8 +7476,8 @@ module.child: func TestContext2Apply_targetedModuleDep(t *testing.T) { m := testModule(t, "apply-targeted-module-dep") p := testProvider("aws") - p.ApplyFn = testApplyFn - p.DiffFn = testDiffFn + p.ApplyResourceChangeFn = testApplyFn + p.PlanResourceChangeFn = testDiffFn ctx := testContext2(t, &ContextOpts{ Config: m, Providers: map[addrs.Provider]providers.Factory{ @@ -7534,8 +7528,8 @@ module.child: func TestContext2Apply_targetedModuleUnrelatedOutputs(t *testing.T) { m := testModule(t, "apply-targeted-module-unrelated-outputs") p := testProvider("aws") - p.ApplyFn = testApplyFn - p.DiffFn = testDiffFn + p.ApplyResourceChangeFn = testApplyFn + p.PlanResourceChangeFn = testDiffFn state := states.NewState() _ = state.EnsureModule(addrs.RootModuleInstance.Child("child2", addrs.NoKey)) @@ -7585,8 +7579,8 @@ module.child2: func TestContext2Apply_targetedModuleResource(t *testing.T) { m := testModule(t, "apply-targeted-module-resource") p := testProvider("aws") - p.ApplyFn = testApplyFn - p.DiffFn = testDiffFn + p.ApplyResourceChangeFn = testApplyFn + p.PlanResourceChangeFn = testDiffFn ctx := testContext2(t, &ContextOpts{ Config: m, Providers: map[addrs.Provider]providers.Factory{ @@ -7627,8 +7621,8 @@ module.child: func TestContext2Apply_targetedResourceOrphanModule(t *testing.T) { m := testModule(t, "apply-targeted-resource-orphan-module") p := testProvider("aws") - p.ApplyFn = testApplyFn - p.DiffFn = testDiffFn + p.ApplyResourceChangeFn = testApplyFn + p.PlanResourceChangeFn = testDiffFn state := states.NewState() child := state.EnsureModule(addrs.RootModuleInstance.Child("parent", addrs.NoKey)) @@ -7666,8 +7660,8 @@ func TestContext2Apply_targetedResourceOrphanModule(t *testing.T) { func TestContext2Apply_unknownAttribute(t *testing.T) { m := testModule(t, "apply-unknown") p := testProvider("aws") - p.ApplyFn = testApplyFn - p.DiffFn = func(req providers.PlanResourceChangeRequest) (resp providers.PlanResourceChangeResponse) { + p.ApplyResourceChangeFn = testApplyFn + p.PlanResourceChangeFn = func(req providers.PlanResourceChangeRequest) (resp providers.PlanResourceChangeResponse) { resp = testDiffFn(req) planned := resp.PlannedState.AsValueMap() planned["unknown"] = cty.UnknownVal(cty.String) @@ -7714,8 +7708,8 @@ func TestContext2Apply_unknownAttribute(t *testing.T) { func TestContext2Apply_unknownAttributeInterpolate(t *testing.T) { m := testModule(t, "apply-unknown-interpolate") p := testProvider("aws") - p.ApplyFn = testApplyFn - p.DiffFn = testDiffFn + p.ApplyResourceChangeFn = testApplyFn + p.PlanResourceChangeFn = testDiffFn ctx := testContext2(t, &ContextOpts{ Config: m, Providers: map[addrs.Provider]providers.Factory{ @@ -7832,8 +7826,8 @@ func TestContext2Apply_createBefore_depends(t *testing.T) { m := testModule(t, "apply-depends-create-before") h := new(HookRecordApplyOrder) p := testProvider("aws") - p.ApplyFn = testApplyFn - p.DiffFn = testDiffFn + p.ApplyResourceChangeFn = testApplyFn + p.PlanResourceChangeFn = testDiffFn state := states.NewState() root := state.EnsureModule(addrs.RootModuleInstance) root.SetResourceInstanceCurrent( @@ -7935,7 +7929,7 @@ func TestContext2Apply_singleDestroy(t *testing.T) { h := new(HookRecordApplyOrder) p := testProvider("aws") invokeCount := 0 - p.ApplyFn = func(req providers.ApplyResourceChangeRequest) providers.ApplyResourceChangeResponse { + p.ApplyResourceChangeFn = func(req providers.ApplyResourceChangeRequest) providers.ApplyResourceChangeResponse { invokeCount++ switch invokeCount { case 1: @@ -7962,7 +7956,7 @@ func TestContext2Apply_singleDestroy(t *testing.T) { return testApplyFn(req) } - p.DiffFn = testDiffFn + p.PlanResourceChangeFn = testDiffFn state := states.NewState() root := state.EnsureModule(addrs.RootModuleInstance) root.SetResourceInstanceCurrent( @@ -8034,8 +8028,8 @@ func TestContext2Apply_singleDestroy(t *testing.T) { // GH-7824 func TestContext2Apply_issue7824(t *testing.T) { p := testProvider("template") - p.ApplyFn = testApplyFn - p.DiffFn = testDiffFn + p.ApplyResourceChangeFn = testApplyFn + p.PlanResourceChangeFn = testDiffFn p.GetSchemaReturn = &ProviderSchema{ ResourceTypes: map[string]*configschema.Block{ "template_file": { @@ -8090,8 +8084,8 @@ func TestContext2Apply_issue5254(t *testing.T) { // Create a provider. We use "template" here just to match the repro // we got from the issue itself. p := testProvider("template") - p.ApplyFn = testApplyFn - p.DiffFn = testDiffFn + p.ApplyResourceChangeFn = testApplyFn + p.PlanResourceChangeFn = testDiffFn p.GetSchemaReturn = &ProviderSchema{ ResourceTypes: map[string]*configschema.Block{ "template_file": { @@ -8183,8 +8177,8 @@ template_file.parent.0: func TestContext2Apply_targetedWithTaintedInState(t *testing.T) { p := testProvider("aws") - p.DiffFn = testDiffFn - p.ApplyFn = testApplyFn + p.PlanResourceChangeFn = testDiffFn + p.ApplyResourceChangeFn = testApplyFn m, snap := testModuleWithSnapshot(t, "apply-tainted-targets") state := states.NewState() @@ -8256,8 +8250,8 @@ aws_instance.ifailedprovisioners: (tainted) func TestContext2Apply_ignoreChangesCreate(t *testing.T) { m := testModule(t, "apply-ignore-changes-create") p := testProvider("aws") - p.ApplyFn = testApplyFn - p.DiffFn = testDiffFn + p.ApplyResourceChangeFn = testApplyFn + p.PlanResourceChangeFn = testDiffFn instanceSchema := p.GetSchemaReturn.ResourceTypes["aws_instance"] instanceSchema.Attributes["required_field"] = &configschema.Attribute{ @@ -8305,9 +8299,9 @@ aws_instance.foo: func TestContext2Apply_ignoreChangesWithDep(t *testing.T) { m := testModule(t, "apply-ignore-changes-dep") p := testProvider("aws") - p.ApplyFn = testApplyFn + p.ApplyResourceChangeFn = testApplyFn - p.DiffFn = func(req providers.PlanResourceChangeRequest) (resp providers.PlanResourceChangeResponse) { + p.PlanResourceChangeFn = func(req providers.PlanResourceChangeRequest) (resp providers.PlanResourceChangeResponse) { resp.PlannedState = req.ProposedNewState switch req.TypeName { @@ -8400,8 +8394,8 @@ func TestContext2Apply_ignoreChangesWithDep(t *testing.T) { func TestContext2Apply_ignoreChangesWildcard(t *testing.T) { m := testModule(t, "apply-ignore-changes-wildcard") p := testProvider("aws") - p.ApplyFn = testApplyFn - p.DiffFn = testDiffFn + p.ApplyResourceChangeFn = testApplyFn + p.PlanResourceChangeFn = testDiffFn instanceSchema := p.GetSchemaReturn.ResourceTypes["aws_instance"] instanceSchema.Attributes["required_field"] = &configschema.Attribute{ @@ -8449,8 +8443,8 @@ aws_instance.foo: func TestContext2Apply_destroyNestedModuleWithAttrsReferencingResource(t *testing.T) { m, snap := testModuleWithSnapshot(t, "apply-destroy-nested-module-with-attrs") p := testProvider("null") - p.ApplyFn = testApplyFn - p.DiffFn = testDiffFn + p.ApplyResourceChangeFn = testApplyFn + p.PlanResourceChangeFn = testDiffFn var state *states.State var diags tfdiags.Diagnostics @@ -8545,13 +8539,13 @@ resource "null_instance" "depends" { // solely on the configuration providing "depends_on" provisionerOutput := "" - p.ApplyFn = func(req providers.ApplyResourceChangeRequest) providers.ApplyResourceChangeResponse { + p.ApplyResourceChangeFn = func(req providers.ApplyResourceChangeRequest) providers.ApplyResourceChangeResponse { // the side effect of the resource being applied provisionerOutput = "APPLIED" return testApplyFn(req) } - p.DiffFn = testDiffFn + p.PlanResourceChangeFn = testDiffFn p.ReadDataSourceFn = func(req providers.ReadDataSourceRequest) providers.ReadDataSourceResponse { return providers.ReadDataSourceResponse{ State: cty.ObjectVal(map[string]cty.Value{ @@ -8615,7 +8609,7 @@ resource "null_instance" "depends" { } `}) - p.ApplyFn = func(req providers.ApplyResourceChangeRequest) providers.ApplyResourceChangeResponse { + p.ApplyResourceChangeFn = func(req providers.ApplyResourceChangeRequest) providers.ApplyResourceChangeResponse { // the side effect of the resource being applied provisionerOutput = "APPLIED_AGAIN" return testApplyFn(req) @@ -8648,8 +8642,8 @@ resource "null_instance" "depends" { func TestContext2Apply_terraformWorkspace(t *testing.T) { m := testModule(t, "apply-terraform-workspace") p := testProvider("aws") - p.ApplyFn = testApplyFn - p.DiffFn = testDiffFn + p.ApplyResourceChangeFn = testApplyFn + p.PlanResourceChangeFn = testDiffFn ctx := testContext2(t, &ContextOpts{ Meta: &ContextMeta{Env: "foo"}, @@ -8679,8 +8673,8 @@ func TestContext2Apply_terraformWorkspace(t *testing.T) { func TestContext2Apply_multiRef(t *testing.T) { m := testModule(t, "apply-multi-ref") p := testProvider("aws") - p.ApplyFn = testApplyFn - p.DiffFn = testDiffFn + p.ApplyResourceChangeFn = testApplyFn + p.PlanResourceChangeFn = testDiffFn ctx := testContext2(t, &ContextOpts{ Config: m, Providers: map[addrs.Provider]providers.Factory{ @@ -8706,8 +8700,8 @@ func TestContext2Apply_multiRef(t *testing.T) { func TestContext2Apply_targetedModuleRecursive(t *testing.T) { m := testModule(t, "apply-targeted-module-recursive") p := testProvider("aws") - p.ApplyFn = testApplyFn - p.DiffFn = testDiffFn + p.ApplyResourceChangeFn = testApplyFn + p.PlanResourceChangeFn = testDiffFn ctx := testContext2(t, &ContextOpts{ Config: m, Providers: map[addrs.Provider]providers.Factory{ @@ -8780,8 +8774,8 @@ result_3 = hello world func TestContext2Apply_destroyWithLocals(t *testing.T) { m := testModule(t, "apply-destroy-with-locals") p := testProvider("aws") - p.ApplyFn = testApplyFn - p.DiffFn = testDiffFn + p.ApplyResourceChangeFn = testApplyFn + p.PlanResourceChangeFn = testDiffFn state := states.NewState() root := state.EnsureModule(addrs.RootModuleInstance) @@ -8835,8 +8829,8 @@ func TestContext2Apply_providerWithLocals(t *testing.T) { return } - p.DiffFn = testDiffFn - p.ApplyFn = testApplyFn + p.PlanResourceChangeFn = testDiffFn + p.ApplyResourceChangeFn = testApplyFn ctx := testContext2(t, &ContextOpts{ Config: m, Providers: map[addrs.Provider]providers.Factory{ @@ -8883,8 +8877,8 @@ func TestContext2Apply_providerWithLocals(t *testing.T) { func TestContext2Apply_destroyWithProviders(t *testing.T) { m := testModule(t, "destroy-module-with-provider") p := testProvider("aws") - p.ApplyFn = testApplyFn - p.DiffFn = testDiffFn + p.ApplyResourceChangeFn = testApplyFn + p.PlanResourceChangeFn = testDiffFn state := states.NewState() removed := state.EnsureModule(addrs.RootModuleInstance.Child("mod", addrs.NoKey).Child("removed", addrs.NoKey)) @@ -8942,7 +8936,7 @@ func TestContext2Apply_destroyWithProviders(t *testing.T) { func TestContext2Apply_providersFromState(t *testing.T) { m := configs.NewEmptyConfig() p := testProvider("aws") - p.DiffFn = testDiffFn + p.PlanResourceChangeFn = testDiffFn implicitProviderState := states.NewState() impRoot := implicitProviderState.EnsureModule(addrs.RootModuleInstance) @@ -9041,8 +9035,8 @@ func TestContext2Apply_plannedInterpolatedCount(t *testing.T) { m, snap := testModuleWithSnapshot(t, "apply-interpolated-count") p := testProvider("aws") - p.ApplyFn = testApplyFn - p.DiffFn = testDiffFn + p.ApplyResourceChangeFn = testApplyFn + p.PlanResourceChangeFn = testDiffFn Providers := map[addrs.Provider]providers.Factory{ addrs.NewDefaultProvider("aws"): testProviderFuncFixed(p), @@ -9095,8 +9089,8 @@ func TestContext2Apply_plannedDestroyInterpolatedCount(t *testing.T) { m, snap := testModuleWithSnapshot(t, "plan-destroy-interpolated-count") p := testProvider("aws") - p.ApplyFn = testApplyFn - p.DiffFn = testDiffFn + p.ApplyResourceChangeFn = testApplyFn + p.PlanResourceChangeFn = testDiffFn providers := map[addrs.Provider]providers.Factory{ addrs.NewDefaultProvider("aws"): testProviderFuncFixed(p), } @@ -9158,8 +9152,8 @@ func TestContext2Apply_scaleInMultivarRef(t *testing.T) { m := testModule(t, "apply-resource-scale-in") p := testProvider("aws") - p.ApplyFn = testApplyFn - p.DiffFn = testDiffFn + p.ApplyResourceChangeFn = testApplyFn + p.PlanResourceChangeFn = testDiffFn Providers := map[addrs.Provider]providers.Factory{ addrs.NewDefaultProvider("aws"): testProviderFuncFixed(p), @@ -9350,7 +9344,7 @@ func TestContext2Apply_invalidIndexRef(t *testing.T) { }, }, } - p.DiffFn = testDiffFn + p.PlanResourceChangeFn = testDiffFn m := testModule(t, "apply-invalid-index") c := testContext2(t, &ContextOpts{ @@ -9389,8 +9383,8 @@ func TestContext2Apply_moduleReplaceCycle(t *testing.T) { } p := testProvider("aws") - p.DiffFn = testDiffFn - p.ApplyFn = testApplyFn + p.PlanResourceChangeFn = testDiffFn + p.ApplyResourceChangeFn = testApplyFn instanceSchema := &configschema.Block{ Attributes: map[string]*configschema.Attribute{ @@ -9528,8 +9522,8 @@ func TestContext2Apply_moduleReplaceCycle(t *testing.T) { func TestContext2Apply_destroyDataCycle(t *testing.T) { m, snap := testModuleWithSnapshot(t, "apply-destroy-data-cycle") p := testProvider("null") - p.ApplyFn = testApplyFn - p.DiffFn = testDiffFn + p.ApplyResourceChangeFn = testApplyFn + p.PlanResourceChangeFn = testDiffFn state := states.NewState() root := state.EnsureModule(addrs.RootModuleInstance) @@ -9605,8 +9599,8 @@ func TestContext2Apply_destroyDataCycle(t *testing.T) { func TestContext2Apply_taintedDestroyFailure(t *testing.T) { m := testModule(t, "apply-destroy-tainted") p := testProvider("test") - p.DiffFn = testDiffFn - p.ApplyFn = func(req providers.ApplyResourceChangeRequest) (resp providers.ApplyResourceChangeResponse) { + p.PlanResourceChangeFn = testDiffFn + p.ApplyResourceChangeFn = func(req providers.ApplyResourceChangeRequest) (resp providers.ApplyResourceChangeResponse) { // All destroys fail. if req.PlannedState.IsNull() { resp.Diagnostics = resp.Diagnostics.Append(errors.New("failure")) @@ -9769,7 +9763,7 @@ func TestContext2Apply_taintedDestroyFailure(t *testing.T) { func TestContext2Apply_plannedConnectionRefs(t *testing.T) { m := testModule(t, "apply-plan-connection-refs") p := testProvider("test") - p.DiffFn = testDiffFn + p.PlanResourceChangeFn = testDiffFn p.ApplyResourceChangeFn = func(req providers.ApplyResourceChangeRequest) (resp providers.ApplyResourceChangeResponse) { s := req.PlannedState.AsValueMap() // delay "a" slightly, so if the reference edge is missing the "b" @@ -9827,8 +9821,8 @@ func TestContext2Apply_plannedConnectionRefs(t *testing.T) { func TestContext2Apply_cbdCycle(t *testing.T) { m, snap := testModuleWithSnapshot(t, "apply-cbd-cycle") p := testProvider("test") - p.ApplyFn = testApplyFn - p.DiffFn = testDiffFn + p.ApplyResourceChangeFn = testApplyFn + p.PlanResourceChangeFn = testDiffFn state := states.NewState() root := state.EnsureModule(addrs.RootModuleInstance) @@ -9946,7 +9940,7 @@ func TestContext2Apply_cbdCycle(t *testing.T) { func TestContext2Apply_ProviderMeta_apply_set(t *testing.T) { m := testModule(t, "provider-meta-set") p := testProvider("test") - p.DiffFn = testDiffFn + p.PlanResourceChangeFn = testDiffFn schema := p.GetSchemaReturn schema.ProviderMeta = &configschema.Block{ Attributes: map[string]*configschema.Attribute{ @@ -10029,7 +10023,7 @@ func TestContext2Apply_ProviderMeta_apply_set(t *testing.T) { func TestContext2Apply_ProviderMeta_apply_unset(t *testing.T) { m := testModule(t, "provider-meta-unset") p := testProvider("test") - p.DiffFn = testDiffFn + p.PlanResourceChangeFn = testDiffFn schema := p.GetSchemaReturn schema.ProviderMeta = &configschema.Block{ Attributes: map[string]*configschema.Attribute{ @@ -10089,7 +10083,7 @@ func TestContext2Apply_ProviderMeta_apply_unset(t *testing.T) { func TestContext2Apply_ProviderMeta_plan_set(t *testing.T) { m := testModule(t, "provider-meta-set") p := testProvider("test") - p.ApplyFn = testApplyFn + p.ApplyResourceChangeFn = testApplyFn schema := p.GetSchemaReturn schema.ProviderMeta = &configschema.Block{ Attributes: map[string]*configschema.Attribute{ @@ -10158,7 +10152,7 @@ func TestContext2Apply_ProviderMeta_plan_set(t *testing.T) { func TestContext2Apply_ProviderMeta_plan_unset(t *testing.T) { m := testModule(t, "provider-meta-unset") p := testProvider("test") - p.ApplyFn = testApplyFn + p.ApplyResourceChangeFn = testApplyFn schema := p.GetSchemaReturn schema.ProviderMeta = &configschema.Block{ Attributes: map[string]*configschema.Attribute{ @@ -10206,8 +10200,8 @@ func TestContext2Apply_ProviderMeta_plan_unset(t *testing.T) { func TestContext2Apply_ProviderMeta_plan_setNoSchema(t *testing.T) { m := testModule(t, "provider-meta-set") p := testProvider("test") - p.ApplyFn = testApplyFn - p.DiffFn = testDiffFn + p.ApplyResourceChangeFn = testApplyFn + p.PlanResourceChangeFn = testDiffFn ctx := testContext2(t, &ContextOpts{ Config: m, Providers: map[addrs.Provider]providers.Factory{ @@ -10246,8 +10240,8 @@ func TestContext2Apply_ProviderMeta_plan_setNoSchema(t *testing.T) { func TestContext2Apply_ProviderMeta_plan_setInvalid(t *testing.T) { m := testModule(t, "provider-meta-set") p := testProvider("test") - p.ApplyFn = testApplyFn - p.DiffFn = testDiffFn + p.ApplyResourceChangeFn = testApplyFn + p.PlanResourceChangeFn = testDiffFn schema := p.GetSchemaReturn schema.ProviderMeta = &configschema.Block{ Attributes: map[string]*configschema.Attribute{ @@ -10300,8 +10294,8 @@ func TestContext2Apply_ProviderMeta_plan_setInvalid(t *testing.T) { func TestContext2Apply_ProviderMeta_refresh_set(t *testing.T) { m := testModule(t, "provider-meta-set") p := testProvider("test") - p.ApplyFn = testApplyFn - p.DiffFn = testDiffFn + p.ApplyResourceChangeFn = testApplyFn + p.PlanResourceChangeFn = testDiffFn schema := p.GetSchemaReturn schema.ProviderMeta = &configschema.Block{ Attributes: map[string]*configschema.Attribute{ @@ -10380,8 +10374,8 @@ func TestContext2Apply_ProviderMeta_refresh_set(t *testing.T) { func TestContext2Apply_ProviderMeta_refresh_setNoSchema(t *testing.T) { m := testModule(t, "provider-meta-set") p := testProvider("test") - p.ApplyFn = testApplyFn - p.DiffFn = testDiffFn + p.ApplyResourceChangeFn = testApplyFn + p.PlanResourceChangeFn = testDiffFn // we need a schema for plan/apply so they don't error schema := p.GetSchemaReturn @@ -10449,8 +10443,8 @@ func TestContext2Apply_ProviderMeta_refresh_setNoSchema(t *testing.T) { func TestContext2Apply_ProviderMeta_refresh_setInvalid(t *testing.T) { m := testModule(t, "provider-meta-set") p := testProvider("test") - p.ApplyFn = testApplyFn - p.DiffFn = testDiffFn + p.ApplyResourceChangeFn = testApplyFn + p.PlanResourceChangeFn = testDiffFn // we need a matching schema for plan/apply so they don't error schema := p.GetSchemaReturn @@ -10529,8 +10523,8 @@ func TestContext2Apply_ProviderMeta_refresh_setInvalid(t *testing.T) { func TestContext2Apply_ProviderMeta_refreshdata_set(t *testing.T) { m := testModule(t, "provider-meta-data-set") p := testProvider("test") - p.ApplyFn = testApplyFn - p.DiffFn = testDiffFn + p.ApplyResourceChangeFn = testApplyFn + p.PlanResourceChangeFn = testDiffFn schema := p.GetSchemaReturn schema.ProviderMeta = &configschema.Block{ Attributes: map[string]*configschema.Attribute{ @@ -10625,8 +10619,8 @@ func TestContext2Apply_ProviderMeta_refreshdata_set(t *testing.T) { func TestContext2Apply_ProviderMeta_refreshdata_unset(t *testing.T) { m := testModule(t, "provider-meta-data-unset") p := testProvider("test") - p.ApplyFn = testApplyFn - p.DiffFn = testDiffFn + p.ApplyResourceChangeFn = testApplyFn + p.PlanResourceChangeFn = testDiffFn schema := p.GetSchemaReturn schema.ProviderMeta = &configschema.Block{ Attributes: map[string]*configschema.Attribute{ @@ -10694,8 +10688,8 @@ func TestContext2Apply_ProviderMeta_refreshdata_unset(t *testing.T) { func TestContext2Apply_ProviderMeta_refreshdata_setNoSchema(t *testing.T) { m := testModule(t, "provider-meta-data-set") p := testProvider("test") - p.ApplyFn = testApplyFn - p.DiffFn = testDiffFn + p.ApplyResourceChangeFn = testApplyFn + p.PlanResourceChangeFn = testDiffFn ctx := testContext2(t, &ContextOpts{ Config: m, Providers: map[addrs.Provider]providers.Factory{ @@ -10740,8 +10734,8 @@ func TestContext2Apply_ProviderMeta_refreshdata_setNoSchema(t *testing.T) { func TestContext2Apply_ProviderMeta_refreshdata_setInvalid(t *testing.T) { m := testModule(t, "provider-meta-data-set") p := testProvider("test") - p.ApplyFn = testApplyFn - p.DiffFn = testDiffFn + p.ApplyResourceChangeFn = testApplyFn + p.PlanResourceChangeFn = testDiffFn schema := p.GetSchemaReturn schema.ProviderMeta = &configschema.Block{ Attributes: map[string]*configschema.Attribute{ @@ -10827,8 +10821,8 @@ output "out" { }) p := testProvider("aws") - p.ApplyFn = testApplyFn - p.DiffFn = testDiffFn + p.ApplyResourceChangeFn = testApplyFn + p.PlanResourceChangeFn = testDiffFn ctx := testContext2(t, &ContextOpts{ Config: m, Providers: map[addrs.Provider]providers.Factory{ @@ -10888,8 +10882,8 @@ resource "aws_instance" "cbd" { }) p := testProvider("aws") - p.ApplyFn = testApplyFn - p.DiffFn = testDiffFn + p.ApplyResourceChangeFn = testApplyFn + p.PlanResourceChangeFn = testDiffFn ctx := testContext2(t, &ContextOpts{ Config: m, Providers: map[addrs.Provider]providers.Factory{ @@ -10945,7 +10939,7 @@ func TestContext2Apply_moduleDependsOn(t *testing.T) { } return resp } - p.DiffFn = testDiffFn + p.PlanResourceChangeFn = testDiffFn p.ApplyResourceChangeFn = func(req providers.ApplyResourceChangeRequest) (resp providers.ApplyResourceChangeResponse) { state := req.PlannedState.AsValueMap() @@ -11020,8 +11014,8 @@ output "c" { }`}) p := testProvider("test") - p.ApplyFn = testApplyFn - p.DiffFn = testDiffFn + p.ApplyResourceChangeFn = testApplyFn + p.PlanResourceChangeFn = testDiffFn ctx := testContext2(t, &ContextOpts{ Config: m, Providers: map[addrs.Provider]providers.Factory{ @@ -11089,8 +11083,8 @@ output "myoutput" { `}) p := testProvider("test") - p.ApplyFn = testApplyFn - p.DiffFn = testDiffFn + p.ApplyResourceChangeFn = testApplyFn + p.PlanResourceChangeFn = testDiffFn ctx := testContext2(t, &ContextOpts{ Config: m, Providers: map[addrs.Provider]providers.Factory{ @@ -11213,7 +11207,7 @@ locals { ) p := testProvider("test") - p.ApplyFn = testApplyFn + p.ApplyResourceChangeFn = testApplyFn p.PlanResourceChangeFn = func(r providers.PlanResourceChangeRequest) (resp providers.PlanResourceChangeResponse) { n := r.ProposedNewState.AsValueMap() @@ -11389,14 +11383,14 @@ output "output" { } return resp } - testP.ApplyFn = func(req providers.ApplyResourceChangeRequest) (resp providers.ApplyResourceChangeResponse) { + testP.ApplyResourceChangeFn = func(req providers.ApplyResourceChangeRequest) (resp providers.ApplyResourceChangeResponse) { if providerConfig != "valid" { resp.Diagnostics = resp.Diagnostics.Append(fmt.Errorf("provider config is %q", providerConfig)) return } return testApplyFn(req) } - testP.DiffFn = testDiffFn + testP.PlanResourceChangeFn = testDiffFn nullP := new(MockProvider) nullP.ReadResourceFn = func(req providers.ReadResourceRequest) providers.ReadResourceResponse { @@ -11404,8 +11398,8 @@ output "output" { } nullP.GetSchemaReturn = schemaFn("null") - nullP.ApplyFn = testApplyFn - nullP.DiffFn = testDiffFn + nullP.ApplyResourceChangeFn = testApplyFn + nullP.PlanResourceChangeFn = testDiffFn nullP.ReadDataSourceResponse = providers.ReadDataSourceResponse{ State: cty.ObjectVal(map[string]cty.Value{ @@ -11503,8 +11497,8 @@ output "outputs" { `}) p := testProvider("test") - p.ApplyFn = testApplyFn - p.DiffFn = testDiffFn + p.ApplyResourceChangeFn = testApplyFn + p.PlanResourceChangeFn = testDiffFn p.ReadDataSourceFn = func(req providers.ReadDataSourceRequest) providers.ReadDataSourceResponse { return providers.ReadDataSourceResponse{ State: cty.ObjectVal(map[string]cty.Value{ @@ -11583,7 +11577,7 @@ resource "test_resource" "a" { `}) p := testProvider("test") - p.ApplyFn = testApplyFn + p.ApplyResourceChangeFn = testApplyFn p.PlanResourceChangeFn = func(req providers.PlanResourceChangeRequest) providers.PlanResourceChangeResponse { proposed := req.ProposedNewState.AsValueMap() proposed["id"] = cty.UnknownVal(cty.String) @@ -11655,8 +11649,8 @@ resource "test_instance" "b" { `}) p := testProvider("test") - p.ApplyFn = testApplyFn - p.DiffFn = testDiffFn + p.ApplyResourceChangeFn = testApplyFn + p.PlanResourceChangeFn = testDiffFn ctx := testContext2(t, &ContextOpts{ Config: m, @@ -11718,8 +11712,8 @@ resource "test_resource" "c" { `}) p := testProvider("test") - p.ApplyFn = testApplyFn - p.DiffFn = testDiffFn + p.ApplyResourceChangeFn = testApplyFn + p.PlanResourceChangeFn = testDiffFn ctx := testContext2(t, &ContextOpts{ Config: m, @@ -11792,8 +11786,8 @@ resource "test_resource" "foo" { }) p := testProvider("test") - p.ApplyFn = testApplyFn - p.DiffFn = testDiffFn + p.ApplyResourceChangeFn = testApplyFn + p.PlanResourceChangeFn = testDiffFn ctx := testContext2(t, &ContextOpts{ Config: m, @@ -11874,8 +11868,8 @@ resource "test_resource" "foo" { }) p := testProvider("test") - p.ApplyFn = testApplyFn - p.DiffFn = testDiffFn + p.ApplyResourceChangeFn = testApplyFn + p.PlanResourceChangeFn = testDiffFn ctx := testContext2(t, &ContextOpts{ Config: m, diff --git a/terraform/context_fixtures_test.go b/terraform/context_fixtures_test.go index 5b2a6eed9..2ed264396 100644 --- a/terraform/context_fixtures_test.go +++ b/terraform/context_fixtures_test.go @@ -48,8 +48,8 @@ func contextFixtureApplyVars(t *testing.T) *contextTestFixture { "map": {Type: cty.Map(cty.String), Optional: true}, }, }) - p.ApplyFn = testApplyFn - p.DiffFn = testDiffFn + p.ApplyResourceChangeFn = testApplyFn + p.PlanResourceChangeFn = testDiffFn return &contextTestFixture{ Config: c, Providers: map[addrs.Provider]providers.Factory{ @@ -74,8 +74,8 @@ func contextFixtureApplyVarsEnv(t *testing.T) *contextTestFixture { "type": {Type: cty.String, Computed: true}, }, }) - p.ApplyFn = testApplyFn - p.DiffFn = testDiffFn + p.ApplyResourceChangeFn = testApplyFn + p.PlanResourceChangeFn = testDiffFn return &contextTestFixture{ Config: c, Providers: map[addrs.Provider]providers.Factory{ diff --git a/terraform/context_input_test.go b/terraform/context_input_test.go index 00208d571..1887ac97c 100644 --- a/terraform/context_input_test.go +++ b/terraform/context_input_test.go @@ -17,8 +17,8 @@ import ( func TestContext2Input_provider(t *testing.T) { m := testModule(t, "input-provider") p := testProvider("aws") - p.ApplyFn = testApplyFn - p.DiffFn = testDiffFn + p.ApplyResourceChangeFn = testApplyFn + p.PlanResourceChangeFn = testDiffFn p.GetSchemaReturn = &ProviderSchema{ Provider: &configschema.Block{ Attributes: map[string]*configschema.Attribute{ @@ -89,8 +89,8 @@ func TestContext2Input_providerMulti(t *testing.T) { m := testModule(t, "input-provider-multi") p := testProvider("aws") - p.ApplyFn = testApplyFn - p.DiffFn = testDiffFn + p.ApplyResourceChangeFn = testApplyFn + p.PlanResourceChangeFn = testDiffFn p.GetSchemaReturn = &ProviderSchema{ Provider: &configschema.Block{ Attributes: map[string]*configschema.Attribute{ @@ -158,8 +158,8 @@ func TestContext2Input_providerMulti(t *testing.T) { func TestContext2Input_providerOnce(t *testing.T) { m := testModule(t, "input-provider-once") p := testProvider("aws") - p.ApplyFn = testApplyFn - p.DiffFn = testDiffFn + p.ApplyResourceChangeFn = testApplyFn + p.PlanResourceChangeFn = testDiffFn ctx := testContext2(t, &ContextOpts{ Config: m, Providers: map[addrs.Provider]providers.Factory{ @@ -178,8 +178,8 @@ func TestContext2Input_providerId(t *testing.T) { m := testModule(t, "input-provider") p := testProvider("aws") - p.ApplyFn = testApplyFn - p.DiffFn = testDiffFn + p.ApplyResourceChangeFn = testApplyFn + p.PlanResourceChangeFn = testDiffFn p.GetSchemaReturn = &ProviderSchema{ Provider: &configschema.Block{ Attributes: map[string]*configschema.Attribute{ @@ -243,8 +243,8 @@ func TestContext2Input_providerOnly(t *testing.T) { m := testModule(t, "input-provider-vars") p := testProvider("aws") - p.ApplyFn = testApplyFn - p.DiffFn = testDiffFn + p.ApplyResourceChangeFn = testApplyFn + p.PlanResourceChangeFn = testDiffFn p.GetSchemaReturn = &ProviderSchema{ Provider: &configschema.Block{ Attributes: map[string]*configschema.Attribute{ @@ -317,8 +317,8 @@ func TestContext2Input_providerVars(t *testing.T) { input := new(MockUIInput) m := testModule(t, "input-provider-with-vars") p := testProvider("aws") - p.ApplyFn = testApplyFn - p.DiffFn = testDiffFn + p.ApplyResourceChangeFn = testApplyFn + p.PlanResourceChangeFn = testDiffFn ctx := testContext2(t, &ContextOpts{ Config: m, Providers: map[addrs.Provider]providers.Factory{ @@ -363,8 +363,8 @@ func TestContext2Input_providerVarsModuleInherit(t *testing.T) { input := new(MockUIInput) m := testModule(t, "input-provider-with-vars-and-module") p := testProvider("aws") - p.ApplyFn = testApplyFn - p.DiffFn = testDiffFn + p.ApplyResourceChangeFn = testApplyFn + p.PlanResourceChangeFn = testDiffFn ctx := testContext2(t, &ContextOpts{ Config: m, Providers: map[addrs.Provider]providers.Factory{ @@ -383,8 +383,8 @@ func TestContext2Input_submoduleTriggersInvalidCount(t *testing.T) { input := new(MockUIInput) m := testModule(t, "input-submodule-count") p := testProvider("aws") - p.ApplyFn = testApplyFn - p.DiffFn = testDiffFn + p.ApplyResourceChangeFn = testApplyFn + p.PlanResourceChangeFn = testDiffFn ctx := testContext2(t, &ContextOpts{ Config: m, Providers: map[addrs.Provider]providers.Factory{ diff --git a/terraform/context_plan_test.go b/terraform/context_plan_test.go index 75cdf5a8c..96882212e 100644 --- a/terraform/context_plan_test.go +++ b/terraform/context_plan_test.go @@ -27,7 +27,7 @@ import ( func TestContext2Plan_basic(t *testing.T) { m := testModule(t, "plan-good") p := testProvider("aws") - p.DiffFn = testDiffFn + p.PlanResourceChangeFn = testDiffFn ctx := testContext2(t, &ContextOpts{ Config: m, Providers: map[addrs.Provider]providers.Factory{ @@ -83,7 +83,7 @@ func TestContext2Plan_basic(t *testing.T) { func TestContext2Plan_createBefore_deposed(t *testing.T) { m := testModule(t, "plan-cbd") p := testProvider("aws") - p.DiffFn = testDiffFn + p.PlanResourceChangeFn = testDiffFn state := states.NewState() root := state.EnsureModule(addrs.RootModuleInstance) @@ -198,7 +198,7 @@ func TestContext2Plan_createBefore_deposed(t *testing.T) { func TestContext2Plan_createBefore_maintainRoot(t *testing.T) { m := testModule(t, "plan-cbd-maintain-root") p := testProvider("aws") - p.DiffFn = testDiffFn + p.PlanResourceChangeFn = testDiffFn ctx := testContext2(t, &ContextOpts{ Config: m, Providers: map[addrs.Provider]providers.Factory{ @@ -230,7 +230,7 @@ func TestContext2Plan_createBefore_maintainRoot(t *testing.T) { func TestContext2Plan_emptyDiff(t *testing.T) { m := testModule(t, "plan-empty") p := testProvider("aws") - p.DiffFn = func(req providers.PlanResourceChangeRequest) (resp providers.PlanResourceChangeResponse) { + p.PlanResourceChangeFn = func(req providers.PlanResourceChangeRequest) (resp providers.PlanResourceChangeResponse) { resp.PlannedState = req.ProposedNewState return resp } @@ -273,7 +273,7 @@ func TestContext2Plan_emptyDiff(t *testing.T) { func TestContext2Plan_escapedVar(t *testing.T) { m := testModule(t, "plan-escaped-var") p := testProvider("aws") - p.DiffFn = testDiffFn + p.PlanResourceChangeFn = testDiffFn ctx := testContext2(t, &ContextOpts{ Config: m, Providers: map[addrs.Provider]providers.Factory{ @@ -315,7 +315,7 @@ func TestContext2Plan_escapedVar(t *testing.T) { func TestContext2Plan_minimal(t *testing.T) { m := testModule(t, "plan-empty") p := testProvider("aws") - p.DiffFn = testDiffFn + p.PlanResourceChangeFn = testDiffFn ctx := testContext2(t, &ContextOpts{ Config: m, Providers: map[addrs.Provider]providers.Factory{ @@ -354,7 +354,7 @@ func TestContext2Plan_minimal(t *testing.T) { func TestContext2Plan_modules(t *testing.T) { m := testModule(t, "plan-modules") p := testProvider("aws") - p.DiffFn = testDiffFn + p.PlanResourceChangeFn = testDiffFn ctx := testContext2(t, &ContextOpts{ Config: m, Providers: map[addrs.Provider]providers.Factory{ @@ -414,7 +414,7 @@ func TestContext2Plan_moduleExpand(t *testing.T) { // Test a smattering of plan expansion behavior m := testModule(t, "plan-modules-expand") p := testProvider("aws") - p.DiffFn = testDiffFn + p.PlanResourceChangeFn = testDiffFn ctx := testContext2(t, &ContextOpts{ Config: m, Providers: map[addrs.Provider]providers.Factory{ @@ -475,7 +475,7 @@ func TestContext2Plan_moduleCycle(t *testing.T) { }, }, } - p.DiffFn = testDiffFn + p.PlanResourceChangeFn = testDiffFn ctx := testContext2(t, &ContextOpts{ Config: m, @@ -530,7 +530,7 @@ func TestContext2Plan_moduleDeadlock(t *testing.T) { testCheckDeadlock(t, func() { m := testModule(t, "plan-module-deadlock") p := testProvider("aws") - p.DiffFn = testDiffFn + p.PlanResourceChangeFn = testDiffFn ctx := testContext2(t, &ContextOpts{ Config: m, @@ -576,7 +576,7 @@ func TestContext2Plan_moduleDeadlock(t *testing.T) { func TestContext2Plan_moduleInput(t *testing.T) { m := testModule(t, "plan-module-input") p := testProvider("aws") - p.DiffFn = testDiffFn + p.PlanResourceChangeFn = testDiffFn ctx := testContext2(t, &ContextOpts{ Config: m, Providers: map[addrs.Provider]providers.Factory{ @@ -631,7 +631,7 @@ func TestContext2Plan_moduleInput(t *testing.T) { func TestContext2Plan_moduleInputComputed(t *testing.T) { m := testModule(t, "plan-module-input-computed") p := testProvider("aws") - p.DiffFn = testDiffFn + p.PlanResourceChangeFn = testDiffFn ctx := testContext2(t, &ContextOpts{ Config: m, Providers: map[addrs.Provider]providers.Factory{ @@ -683,7 +683,7 @@ func TestContext2Plan_moduleInputComputed(t *testing.T) { func TestContext2Plan_moduleInputFromVar(t *testing.T) { m := testModule(t, "plan-module-input-var") p := testProvider("aws") - p.DiffFn = testDiffFn + p.PlanResourceChangeFn = testDiffFn ctx := testContext2(t, &ContextOpts{ Config: m, Providers: map[addrs.Provider]providers.Factory{ @@ -751,7 +751,7 @@ func TestContext2Plan_moduleMultiVar(t *testing.T) { }, }, } - p.DiffFn = testDiffFn + p.PlanResourceChangeFn = testDiffFn ctx := testContext2(t, &ContextOpts{ Config: m, @@ -815,7 +815,7 @@ func TestContext2Plan_moduleMultiVar(t *testing.T) { func TestContext2Plan_moduleOrphans(t *testing.T) { m := testModule(t, "plan-modules-remove") p := testProvider("aws") - p.DiffFn = testDiffFn + p.PlanResourceChangeFn = testDiffFn state := states.NewState() child := state.EnsureModule(addrs.RootModuleInstance.Child("child", addrs.NoKey)) @@ -889,7 +889,7 @@ func TestContext2Plan_moduleOrphansWithProvisioner(t *testing.T) { m := testModule(t, "plan-modules-remove-provisioners") p := testProvider("aws") pr := testProvisioner() - p.DiffFn = testDiffFn + p.PlanResourceChangeFn = testDiffFn state := states.NewState() root := state.EnsureModule(addrs.RootModuleInstance) @@ -1024,7 +1024,7 @@ func TestContext2Plan_moduleProviderInherit(t *testing.T) { return } - p.DiffFn = func(req providers.PlanResourceChangeRequest) (resp providers.PlanResourceChangeResponse) { + p.PlanResourceChangeFn = func(req providers.PlanResourceChangeRequest) (resp providers.PlanResourceChangeResponse) { from := req.Config.GetAttr("from").AsString() l.Lock() @@ -1089,7 +1089,7 @@ func TestContext2Plan_moduleProviderInheritDeep(t *testing.T) { return } - p.DiffFn = func(req providers.PlanResourceChangeRequest) (resp providers.PlanResourceChangeResponse) { + p.PlanResourceChangeFn = func(req providers.PlanResourceChangeRequest) (resp providers.PlanResourceChangeResponse) { if from != "root" { resp.Diagnostics = resp.Diagnostics.Append(fmt.Errorf("bad resource")) return @@ -1153,7 +1153,7 @@ func TestContext2Plan_moduleProviderDefaultsVar(t *testing.T) { return } - p.DiffFn = testDiffFn + p.PlanResourceChangeFn = testDiffFn return p, nil }, }, @@ -1197,7 +1197,7 @@ func TestContext2Plan_moduleProviderVar(t *testing.T) { }, }, } - p.DiffFn = testDiffFn + p.PlanResourceChangeFn = testDiffFn ctx := testContext2(t, &ContextOpts{ Config: m, @@ -1241,7 +1241,7 @@ func TestContext2Plan_moduleProviderVar(t *testing.T) { func TestContext2Plan_moduleVar(t *testing.T) { m := testModule(t, "plan-module-var") p := testProvider("aws") - p.DiffFn = testDiffFn + p.PlanResourceChangeFn = testDiffFn ctx := testContext2(t, &ContextOpts{ Config: m, Providers: map[addrs.Provider]providers.Factory{ @@ -1296,7 +1296,7 @@ func TestContext2Plan_moduleVar(t *testing.T) { func TestContext2Plan_moduleVarWrongTypeBasic(t *testing.T) { m := testModule(t, "plan-module-wrong-var-type") p := testProvider("aws") - p.DiffFn = testDiffFn + p.PlanResourceChangeFn = testDiffFn ctx := testContext2(t, &ContextOpts{ Config: m, Providers: map[addrs.Provider]providers.Factory{ @@ -1313,7 +1313,7 @@ func TestContext2Plan_moduleVarWrongTypeBasic(t *testing.T) { func TestContext2Plan_moduleVarWrongTypeNested(t *testing.T) { m := testModule(t, "plan-module-wrong-var-type-nested") p := testProvider("null") - p.DiffFn = testDiffFn + p.PlanResourceChangeFn = testDiffFn ctx := testContext2(t, &ContextOpts{ Config: m, Providers: map[addrs.Provider]providers.Factory{ @@ -1330,7 +1330,7 @@ func TestContext2Plan_moduleVarWrongTypeNested(t *testing.T) { func TestContext2Plan_moduleVarWithDefaultValue(t *testing.T) { m := testModule(t, "plan-module-var-with-default-value") p := testProvider("null") - p.DiffFn = testDiffFn + p.PlanResourceChangeFn = testDiffFn ctx := testContext2(t, &ContextOpts{ Config: m, Providers: map[addrs.Provider]providers.Factory{ @@ -1347,7 +1347,7 @@ func TestContext2Plan_moduleVarWithDefaultValue(t *testing.T) { func TestContext2Plan_moduleVarComputed(t *testing.T) { m := testModule(t, "plan-module-var-computed") p := testProvider("aws") - p.DiffFn = testDiffFn + p.PlanResourceChangeFn = testDiffFn ctx := testContext2(t, &ContextOpts{ Config: m, Providers: map[addrs.Provider]providers.Factory{ @@ -1398,7 +1398,7 @@ func TestContext2Plan_moduleVarComputed(t *testing.T) { func TestContext2Plan_preventDestroy_bad(t *testing.T) { m := testModule(t, "plan-prevent-destroy-bad") p := testProvider("aws") - p.DiffFn = testDiffFn + p.PlanResourceChangeFn = testDiffFn state := states.NewState() root := state.EnsureModule(addrs.RootModuleInstance) root.SetResourceInstanceCurrent( @@ -1432,7 +1432,7 @@ func TestContext2Plan_preventDestroy_bad(t *testing.T) { func TestContext2Plan_preventDestroy_good(t *testing.T) { m := testModule(t, "plan-prevent-destroy-good") p := testProvider("aws") - p.DiffFn = testDiffFn + p.PlanResourceChangeFn = testDiffFn state := states.NewState() root := state.EnsureModule(addrs.RootModuleInstance) @@ -1466,7 +1466,7 @@ func TestContext2Plan_preventDestroy_good(t *testing.T) { func TestContext2Plan_preventDestroy_countBad(t *testing.T) { m := testModule(t, "plan-prevent-destroy-count-bad") p := testProvider("aws") - p.DiffFn = testDiffFn + p.PlanResourceChangeFn = testDiffFn state := states.NewState() root := state.EnsureModule(addrs.RootModuleInstance) @@ -1519,7 +1519,7 @@ func TestContext2Plan_preventDestroy_countGood(t *testing.T) { }, }, } - p.DiffFn = testDiffFn + p.PlanResourceChangeFn = testDiffFn state := states.NewState() root := state.EnsureModule(addrs.RootModuleInstance) @@ -1572,7 +1572,7 @@ func TestContext2Plan_preventDestroy_countGoodNoChange(t *testing.T) { }, }, } - p.DiffFn = testDiffFn + p.PlanResourceChangeFn = testDiffFn state := states.NewState() root := state.EnsureModule(addrs.RootModuleInstance) @@ -1606,7 +1606,7 @@ func TestContext2Plan_preventDestroy_countGoodNoChange(t *testing.T) { func TestContext2Plan_preventDestroy_destroyPlan(t *testing.T) { m := testModule(t, "plan-prevent-destroy-good") p := testProvider("aws") - p.DiffFn = testDiffFn + p.PlanResourceChangeFn = testDiffFn state := states.NewState() root := state.EnsureModule(addrs.RootModuleInstance) @@ -1642,7 +1642,7 @@ func TestContext2Plan_preventDestroy_destroyPlan(t *testing.T) { func TestContext2Plan_provisionerCycle(t *testing.T) { m := testModule(t, "plan-provisioner-cycle") p := testProvider("aws") - p.DiffFn = testDiffFn + p.PlanResourceChangeFn = testDiffFn pr := testProvisioner() ctx := testContext2(t, &ContextOpts{ Config: m, @@ -1663,7 +1663,7 @@ func TestContext2Plan_provisionerCycle(t *testing.T) { func TestContext2Plan_computed(t *testing.T) { m := testModule(t, "plan-computed") p := testProvider("aws") - p.DiffFn = testDiffFn + p.PlanResourceChangeFn = testDiffFn ctx := testContext2(t, &ContextOpts{ Config: m, Providers: map[addrs.Provider]providers.Factory{ @@ -1806,7 +1806,7 @@ func TestContext2Plan_computedDataResource(t *testing.T) { }, }, } - p.DiffFn = testDiffFn + p.PlanResourceChangeFn = testDiffFn ctx := testContext2(t, &ContextOpts{ Config: m, @@ -1866,7 +1866,7 @@ func TestContext2Plan_computedInFunction(t *testing.T) { }, }, } - p.DiffFn = testDiffFn + p.PlanResourceChangeFn = testDiffFn p.ReadDataSourceResponse = providers.ReadDataSourceResponse{ State: cty.ObjectVal(map[string]cty.Value{ "computed": cty.ListVal([]cty.Value{ @@ -1914,7 +1914,7 @@ func TestContext2Plan_computedDataCountResource(t *testing.T) { }, }, } - p.DiffFn = testDiffFn + p.PlanResourceChangeFn = testDiffFn ctx := testContext2(t, &ContextOpts{ Config: m, @@ -1945,7 +1945,7 @@ func TestContext2Plan_computedDataCountResource(t *testing.T) { func TestContext2Plan_localValueCount(t *testing.T) { m := testModule(t, "plan-local-value-count") p := testProvider("test") - p.DiffFn = testDiffFn + p.PlanResourceChangeFn = testDiffFn ctx := testContext2(t, &ContextOpts{ Config: m, Providers: map[addrs.Provider]providers.Factory{ @@ -2081,7 +2081,7 @@ func TestContext2Plan_computedList(t *testing.T) { }, }, } - p.DiffFn = testDiffFn + p.PlanResourceChangeFn = testDiffFn ctx := testContext2(t, &ContextOpts{ Config: m, @@ -2133,7 +2133,7 @@ func TestContext2Plan_computedList(t *testing.T) { func TestContext2Plan_computedMultiIndex(t *testing.T) { m := testModule(t, "plan-computed-multi-index") p := testProvider("aws") - p.DiffFn = testDiffFn + p.PlanResourceChangeFn = testDiffFn p.GetSchemaReturn = &ProviderSchema{ ResourceTypes: map[string]*configschema.Block{ @@ -2147,7 +2147,7 @@ func TestContext2Plan_computedMultiIndex(t *testing.T) { }, } - p.DiffFn = testDiffFn + p.PlanResourceChangeFn = testDiffFn ctx := testContext2(t, &ContextOpts{ Config: m, @@ -2203,7 +2203,7 @@ func TestContext2Plan_computedMultiIndex(t *testing.T) { func TestContext2Plan_count(t *testing.T) { m := testModule(t, "plan-count") p := testProvider("aws") - p.DiffFn = testDiffFn + p.PlanResourceChangeFn = testDiffFn ctx := testContext2(t, &ContextOpts{ Config: m, Providers: map[addrs.Provider]providers.Factory{ @@ -2278,7 +2278,7 @@ func TestContext2Plan_count(t *testing.T) { func TestContext2Plan_countComputed(t *testing.T) { m := testModule(t, "plan-count-computed") p := testProvider("aws") - p.DiffFn = testDiffFn + p.PlanResourceChangeFn = testDiffFn ctx := testContext2(t, &ContextOpts{ Config: m, Providers: map[addrs.Provider]providers.Factory{ @@ -2295,7 +2295,7 @@ func TestContext2Plan_countComputed(t *testing.T) { func TestContext2Plan_countComputedModule(t *testing.T) { m := testModule(t, "plan-count-computed-module") p := testProvider("aws") - p.DiffFn = testDiffFn + p.PlanResourceChangeFn = testDiffFn ctx := testContext2(t, &ContextOpts{ Config: m, Providers: map[addrs.Provider]providers.Factory{ @@ -2315,7 +2315,7 @@ func TestContext2Plan_countComputedModule(t *testing.T) { func TestContext2Plan_countModuleStatic(t *testing.T) { m := testModule(t, "plan-count-module-static") p := testProvider("aws") - p.DiffFn = testDiffFn + p.PlanResourceChangeFn = testDiffFn ctx := testContext2(t, &ContextOpts{ Config: m, Providers: map[addrs.Provider]providers.Factory{ @@ -2369,7 +2369,7 @@ func TestContext2Plan_countModuleStatic(t *testing.T) { func TestContext2Plan_countModuleStaticGrandchild(t *testing.T) { m := testModule(t, "plan-count-module-static-grandchild") p := testProvider("aws") - p.DiffFn = testDiffFn + p.PlanResourceChangeFn = testDiffFn ctx := testContext2(t, &ContextOpts{ Config: m, Providers: map[addrs.Provider]providers.Factory{ @@ -2423,7 +2423,7 @@ func TestContext2Plan_countModuleStaticGrandchild(t *testing.T) { func TestContext2Plan_countIndex(t *testing.T) { m := testModule(t, "plan-count-index") p := testProvider("aws") - p.DiffFn = testDiffFn + p.PlanResourceChangeFn = testDiffFn ctx := testContext2(t, &ContextOpts{ Config: m, Providers: map[addrs.Provider]providers.Factory{ @@ -2474,7 +2474,7 @@ func TestContext2Plan_countIndex(t *testing.T) { func TestContext2Plan_countVar(t *testing.T) { m := testModule(t, "plan-count-var") p := testProvider("aws") - p.DiffFn = testDiffFn + p.PlanResourceChangeFn = testDiffFn ctx := testContext2(t, &ContextOpts{ Config: m, Providers: map[addrs.Provider]providers.Factory{ @@ -2599,7 +2599,7 @@ func TestContext2Plan_countZero(t *testing.T) { func TestContext2Plan_countOneIndex(t *testing.T) { m := testModule(t, "plan-count-one-index") p := testProvider("aws") - p.DiffFn = testDiffFn + p.PlanResourceChangeFn = testDiffFn ctx := testContext2(t, &ContextOpts{ Config: m, Providers: map[addrs.Provider]providers.Factory{ @@ -2650,7 +2650,7 @@ func TestContext2Plan_countOneIndex(t *testing.T) { func TestContext2Plan_countDecreaseToOne(t *testing.T) { m := testModule(t, "plan-count-dec") p := testProvider("aws") - p.DiffFn = testDiffFn + p.PlanResourceChangeFn = testDiffFn state := states.NewState() root := state.EnsureModule(addrs.RootModuleInstance) @@ -2752,7 +2752,7 @@ aws_instance.foo.2: func TestContext2Plan_countIncreaseFromNotSet(t *testing.T) { m := testModule(t, "plan-count-inc") p := testProvider("aws") - p.DiffFn = testDiffFn + p.PlanResourceChangeFn = testDiffFn state := states.NewState() root := state.EnsureModule(addrs.RootModuleInstance) @@ -2832,7 +2832,7 @@ func TestContext2Plan_countIncreaseFromNotSet(t *testing.T) { func TestContext2Plan_countIncreaseFromOne(t *testing.T) { m := testModule(t, "plan-count-inc") p := testProvider("aws") - p.DiffFn = testDiffFn + p.PlanResourceChangeFn = testDiffFn state := states.NewState() root := state.EnsureModule(addrs.RootModuleInstance) root.SetResourceInstanceCurrent( @@ -2916,7 +2916,7 @@ func TestContext2Plan_countIncreaseFromOne(t *testing.T) { func TestContext2Plan_countIncreaseFromOneCorrupted(t *testing.T) { m := testModule(t, "plan-count-inc") p := testProvider("aws") - p.DiffFn = testDiffFn + p.PlanResourceChangeFn = testDiffFn state := states.NewState() root := state.EnsureModule(addrs.RootModuleInstance) @@ -3027,7 +3027,7 @@ func TestContext2Plan_countIncreaseWithSplatReference(t *testing.T) { }, }, } - p.DiffFn = testDiffFn + p.PlanResourceChangeFn = testDiffFn state := states.NewState() root := state.EnsureModule(addrs.RootModuleInstance) @@ -3120,7 +3120,7 @@ func TestContext2Plan_countIncreaseWithSplatReference(t *testing.T) { func TestContext2Plan_forEach(t *testing.T) { m := testModule(t, "plan-for-each") p := testProvider("aws") - p.DiffFn = testDiffFn + p.PlanResourceChangeFn = testDiffFn ctx := testContext2(t, &ContextOpts{ Config: m, Providers: map[addrs.Provider]providers.Factory{ @@ -3156,7 +3156,7 @@ func TestContext2Plan_forEachUnknownValue(t *testing.T) { // expect this to produce an error, but not to panic. m := testModule(t, "plan-for-each-unknown-value") p := testProvider("aws") - p.DiffFn = testDiffFn + p.PlanResourceChangeFn = testDiffFn ctx := testContext2(t, &ContextOpts{ Config: m, Providers: map[addrs.Provider]providers.Factory{ @@ -3187,7 +3187,7 @@ func TestContext2Plan_forEachUnknownValue(t *testing.T) { func TestContext2Plan_destroy(t *testing.T) { m := testModule(t, "plan-destroy") p := testProvider("aws") - p.DiffFn = testDiffFn + p.PlanResourceChangeFn = testDiffFn state := states.NewState() root := state.EnsureModule(addrs.RootModuleInstance) @@ -3250,7 +3250,7 @@ func TestContext2Plan_destroy(t *testing.T) { func TestContext2Plan_moduleDestroy(t *testing.T) { m := testModule(t, "plan-module-destroy") p := testProvider("aws") - p.DiffFn = testDiffFn + p.PlanResourceChangeFn = testDiffFn state := states.NewState() root := state.EnsureModule(addrs.RootModuleInstance) @@ -3314,7 +3314,7 @@ func TestContext2Plan_moduleDestroy(t *testing.T) { func TestContext2Plan_moduleDestroyCycle(t *testing.T) { m := testModule(t, "plan-module-destroy-gh-1835") p := testProvider("aws") - p.DiffFn = testDiffFn + p.PlanResourceChangeFn = testDiffFn state := states.NewState() aModule := state.EnsureModule(addrs.RootModuleInstance.Child("a_module", addrs.NoKey)) @@ -3378,7 +3378,7 @@ func TestContext2Plan_moduleDestroyCycle(t *testing.T) { func TestContext2Plan_moduleDestroyMultivar(t *testing.T) { m := testModule(t, "plan-module-destroy-multivar") p := testProvider("aws") - p.DiffFn = testDiffFn + p.PlanResourceChangeFn = testDiffFn state := states.NewState() child := state.EnsureModule(addrs.RootModuleInstance.Child("child", addrs.NoKey)) @@ -3457,7 +3457,7 @@ func TestContext2Plan_pathVar(t *testing.T) { }, }, } - p.DiffFn = testDiffFn + p.PlanResourceChangeFn = testDiffFn ctx := testContext2(t, &ContextOpts{ Config: m, @@ -3522,7 +3522,7 @@ func TestContext2Plan_diffVar(t *testing.T) { State: state, }) - p.DiffFn = testDiffFn + p.PlanResourceChangeFn = testDiffFn plan, diags := ctx.Plan() if diags.HasErrors() { @@ -3576,7 +3576,7 @@ func TestContext2Plan_hook(t *testing.T) { m := testModule(t, "plan-good") h := new(MockHook) p := testProvider("aws") - p.DiffFn = testDiffFn + p.PlanResourceChangeFn = testDiffFn ctx := testContext2(t, &ContextOpts{ Config: m, Hooks: []Hook{h}, @@ -3604,7 +3604,7 @@ func TestContext2Plan_closeProvider(t *testing.T) { // "provider.aws". m := testModule(t, "plan-close-module-provider") p := testProvider("aws") - p.DiffFn = testDiffFn + p.PlanResourceChangeFn = testDiffFn ctx := testContext2(t, &ContextOpts{ Config: m, Providers: map[addrs.Provider]providers.Factory{ @@ -3625,7 +3625,7 @@ func TestContext2Plan_closeProvider(t *testing.T) { func TestContext2Plan_orphan(t *testing.T) { m := testModule(t, "plan-orphan") p := testProvider("aws") - p.DiffFn = testDiffFn + p.PlanResourceChangeFn = testDiffFn state := states.NewState() root := state.EnsureModule(addrs.RootModuleInstance) root.SetResourceInstanceCurrent( @@ -3688,7 +3688,7 @@ func TestContext2Plan_orphan(t *testing.T) { func TestContext2Plan_shadowUuid(t *testing.T) { m := testModule(t, "plan-shadow-uuid") p := testProvider("aws") - p.DiffFn = testDiffFn + p.PlanResourceChangeFn = testDiffFn ctx := testContext2(t, &ContextOpts{ Config: m, Providers: map[addrs.Provider]providers.Factory{ @@ -3705,7 +3705,7 @@ func TestContext2Plan_shadowUuid(t *testing.T) { func TestContext2Plan_state(t *testing.T) { m := testModule(t, "plan-good") p := testProvider("aws") - p.DiffFn = testDiffFn + p.PlanResourceChangeFn = testDiffFn state := states.NewState() root := state.EnsureModule(addrs.RootModuleInstance) root.SetResourceInstanceCurrent( @@ -3778,7 +3778,7 @@ func TestContext2Plan_state(t *testing.T) { func TestContext2Plan_taint(t *testing.T) { m := testModule(t, "plan-taint") p := testProvider("aws") - p.DiffFn = testDiffFn + p.PlanResourceChangeFn = testDiffFn state := states.NewState() root := state.EnsureModule(addrs.RootModuleInstance) root.SetResourceInstanceCurrent( @@ -3858,8 +3858,8 @@ func TestContext2Plan_taintIgnoreChanges(t *testing.T) { }, }, } - p.ApplyFn = testApplyFn - p.DiffFn = testDiffFn + p.ApplyResourceChangeFn = testApplyFn + p.PlanResourceChangeFn = testDiffFn state := states.NewState() root := state.EnsureModule(addrs.RootModuleInstance) @@ -3923,7 +3923,7 @@ func TestContext2Plan_taintIgnoreChanges(t *testing.T) { func TestContext2Plan_taintDestroyInterpolatedCountRace(t *testing.T) { m := testModule(t, "plan-taint-interpolated-count") p := testProvider("aws") - p.DiffFn = testDiffFn + p.PlanResourceChangeFn = testDiffFn state := states.NewState() root := state.EnsureModule(addrs.RootModuleInstance) root.SetResourceInstanceCurrent( @@ -4005,7 +4005,7 @@ func TestContext2Plan_taintDestroyInterpolatedCountRace(t *testing.T) { func TestContext2Plan_targeted(t *testing.T) { m := testModule(t, "plan-targeted") p := testProvider("aws") - p.DiffFn = testDiffFn + p.PlanResourceChangeFn = testDiffFn ctx := testContext2(t, &ContextOpts{ Config: m, Providers: map[addrs.Provider]providers.Factory{ @@ -4056,7 +4056,7 @@ func TestContext2Plan_targeted(t *testing.T) { func TestContext2Plan_targetedCrossModule(t *testing.T) { m := testModule(t, "plan-targeted-cross-module") p := testProvider("aws") - p.DiffFn = testDiffFn + p.PlanResourceChangeFn = testDiffFn ctx := testContext2(t, &ContextOpts{ Config: m, Providers: map[addrs.Provider]providers.Factory{ @@ -4120,7 +4120,7 @@ func TestContext2Plan_targetedModuleWithProvider(t *testing.T) { }, }, } - p.DiffFn = testDiffFn + p.PlanResourceChangeFn = testDiffFn ctx := testContext2(t, &ContextOpts{ Config: m, @@ -4158,7 +4158,7 @@ func TestContext2Plan_targetedModuleWithProvider(t *testing.T) { func TestContext2Plan_targetedOrphan(t *testing.T) { m := testModule(t, "plan-targeted-orphan") p := testProvider("aws") - p.DiffFn = testDiffFn + p.PlanResourceChangeFn = testDiffFn state := states.NewState() root := state.EnsureModule(addrs.RootModuleInstance) @@ -4226,7 +4226,7 @@ func TestContext2Plan_targetedOrphan(t *testing.T) { func TestContext2Plan_targetedModuleOrphan(t *testing.T) { m := testModule(t, "plan-targeted-module-orphan") p := testProvider("aws") - p.DiffFn = testDiffFn + p.PlanResourceChangeFn = testDiffFn state := states.NewState() child := state.EnsureModule(addrs.RootModuleInstance.Child("child", addrs.NoKey)) @@ -4290,7 +4290,7 @@ func TestContext2Plan_targetedModuleOrphan(t *testing.T) { func TestContext2Plan_targetedModuleUntargetedVariable(t *testing.T) { m := testModule(t, "plan-targeted-module-untargeted-variable") p := testProvider("aws") - p.DiffFn = testDiffFn + p.PlanResourceChangeFn = testDiffFn ctx := testContext2(t, &ContextOpts{ Config: m, Providers: map[addrs.Provider]providers.Factory{ @@ -4347,7 +4347,7 @@ func TestContext2Plan_targetedModuleUntargetedVariable(t *testing.T) { func TestContext2Plan_outputContainsTargetedResource(t *testing.T) { m := testModule(t, "plan-untargeted-resource-output") p := testProvider("aws") - p.DiffFn = testDiffFn + p.PlanResourceChangeFn = testDiffFn ctx := testContext2(t, &ContextOpts{ Config: m, Providers: map[addrs.Provider]providers.Factory{ @@ -4379,7 +4379,7 @@ func TestContext2Plan_outputContainsTargetedResource(t *testing.T) { func TestContext2Plan_targetedOverTen(t *testing.T) { m := testModule(t, "plan-targeted-over-ten") p := testProvider("aws") - p.DiffFn = testDiffFn + p.PlanResourceChangeFn = testDiffFn state := states.NewState() root := state.EnsureModule(addrs.RootModuleInstance) @@ -4435,7 +4435,7 @@ func TestContext2Plan_targetedOverTen(t *testing.T) { func TestContext2Plan_provider(t *testing.T) { m := testModule(t, "plan-provider") p := testProvider("aws") - p.DiffFn = testDiffFn + p.PlanResourceChangeFn = testDiffFn var value interface{} p.ConfigureFn = func(req providers.ConfigureRequest) (resp providers.ConfigureResponse) { @@ -4485,7 +4485,7 @@ func TestContext2Plan_varListErr(t *testing.T) { func TestContext2Plan_ignoreChanges(t *testing.T) { m := testModule(t, "plan-ignore-changes") p := testProvider("aws") - p.DiffFn = testDiffFn + p.PlanResourceChangeFn = testDiffFn state := states.NewState() root := state.EnsureModule(addrs.RootModuleInstance) @@ -4544,7 +4544,7 @@ func TestContext2Plan_ignoreChanges(t *testing.T) { func TestContext2Plan_ignoreChangesWildcard(t *testing.T) { m := testModule(t, "plan-ignore-changes-wildcard") p := testProvider("aws") - p.DiffFn = testDiffFn + p.PlanResourceChangeFn = testDiffFn state := states.NewState() root := state.EnsureModule(addrs.RootModuleInstance) @@ -4605,7 +4605,7 @@ func TestContext2Plan_ignoreChangesInMap(t *testing.T) { } } - p.DiffFn = testDiffFn + p.PlanResourceChangeFn = testDiffFn s := states.BuildState(func(ss *states.SyncState) { ss.SetResourceInstanceCurrent( @@ -4680,8 +4680,8 @@ func TestContext2Plan_moduleMapLiteral(t *testing.T) { }, }, } - p.ApplyFn = testApplyFn - p.DiffFn = func(req providers.PlanResourceChangeRequest) (resp providers.PlanResourceChangeResponse) { + p.ApplyResourceChangeFn = testApplyFn + p.PlanResourceChangeFn = func(req providers.PlanResourceChangeRequest) (resp providers.PlanResourceChangeResponse) { s := req.ProposedNewState.AsValueMap() m := s["tags"].AsValueMap() @@ -4725,8 +4725,8 @@ func TestContext2Plan_computedValueInMap(t *testing.T) { }, }, } - p.DiffFn = testDiffFn - p.DiffFn = func(req providers.PlanResourceChangeRequest) (resp providers.PlanResourceChangeResponse) { + p.PlanResourceChangeFn = testDiffFn + p.PlanResourceChangeFn = func(req providers.PlanResourceChangeRequest) (resp providers.PlanResourceChangeResponse) { resp = testDiffFn(req) if req.TypeName != "aws_computed_source" { @@ -4785,7 +4785,7 @@ func TestContext2Plan_computedValueInMap(t *testing.T) { func TestContext2Plan_moduleVariableFromSplat(t *testing.T) { m := testModule(t, "plan-module-variable-from-splat") p := testProvider("aws") - p.DiffFn = testDiffFn + p.PlanResourceChangeFn = testDiffFn p.GetSchemaReturn = &ProviderSchema{ ResourceTypes: map[string]*configschema.Block{ "aws_instance": { @@ -4945,8 +4945,8 @@ func TestContext2Plan_createBeforeDestroy_depends_datasource(t *testing.T) { func TestContext2Plan_listOrder(t *testing.T) { m := testModule(t, "plan-list-order") p := testProvider("aws") - p.ApplyFn = testApplyFn - p.DiffFn = testDiffFn + p.ApplyResourceChangeFn = testApplyFn + p.PlanResourceChangeFn = testDiffFn p.GetSchemaReturn = &ProviderSchema{ ResourceTypes: map[string]*configschema.Block{ "aws_instance": { @@ -4992,7 +4992,7 @@ func TestContext2Plan_listOrder(t *testing.T) { func TestContext2Plan_ignoreChangesWithFlatmaps(t *testing.T) { m := testModule(t, "plan-ignore-changes-with-flatmaps") p := testProvider("aws") - p.DiffFn = testDiffFn + p.PlanResourceChangeFn = testDiffFn p.GetSchemaReturn = &ProviderSchema{ ResourceTypes: map[string]*configschema.Block{ "aws_instance": { @@ -5081,7 +5081,7 @@ func TestContext2Plan_ignoreChangesWithFlatmaps(t *testing.T) { func TestContext2Plan_resourceNestedCount(t *testing.T) { m := testModule(t, "nested-resource-count-plan") p := testProvider("aws") - p.DiffFn = testDiffFn + p.PlanResourceChangeFn = testDiffFn p.ReadResourceFn = func(req providers.ReadResourceRequest) providers.ReadResourceResponse { return providers.ReadResourceResponse{ NewState: req.PriorState, @@ -5176,7 +5176,7 @@ func TestContext2Plan_resourceNestedCount(t *testing.T) { func TestContext2Plan_computedAttrRefTypeMismatch(t *testing.T) { m := testModule(t, "plan-computed-attr-ref-type-mismatch") p := testProvider("aws") - p.DiffFn = testDiffFn + p.PlanResourceChangeFn = testDiffFn p.ValidateResourceTypeConfigFn = func(req providers.ValidateResourceTypeConfigRequest) providers.ValidateResourceTypeConfigResponse { var diags tfdiags.Diagnostics if req.TypeName == "aws_instance" { @@ -5189,8 +5189,8 @@ func TestContext2Plan_computedAttrRefTypeMismatch(t *testing.T) { Diagnostics: diags, } } - p.DiffFn = testDiffFn - p.ApplyFn = func(req providers.ApplyResourceChangeRequest) (resp providers.ApplyResourceChangeResponse) { + p.PlanResourceChangeFn = testDiffFn + p.ApplyResourceChangeFn = func(req providers.ApplyResourceChangeRequest) (resp providers.ApplyResourceChangeResponse) { if req.TypeName != "aws_ami_list" { t.Fatalf("Reached apply for unexpected resource type! %s", req.TypeName) } @@ -5618,7 +5618,7 @@ func TestContext2Plan_requiredModuleOutput(t *testing.T) { }, }, } - p.DiffFn = testDiffFn + p.PlanResourceChangeFn = testDiffFn ctx := testContext2(t, &ContextOpts{ Config: m, @@ -5683,7 +5683,7 @@ func TestContext2Plan_requiredModuleObject(t *testing.T) { }, }, } - p.DiffFn = testDiffFn + p.PlanResourceChangeFn = testDiffFn ctx := testContext2(t, &ContextOpts{ Config: m, @@ -5768,7 +5768,7 @@ resource "aws_instance" "foo" { ) p := testProvider("aws") - p.DiffFn = testDiffFn + p.PlanResourceChangeFn = testDiffFn ctx := testContext2(t, &ContextOpts{ Config: m, Providers: map[addrs.Provider]providers.Factory{ @@ -5830,7 +5830,7 @@ output"out" { }) p := testProvider("aws") - p.DiffFn = testDiffFn + p.PlanResourceChangeFn = testDiffFn ctx := testContext2(t, &ContextOpts{ Config: m, Providers: map[addrs.Provider]providers.Factory{ @@ -5860,7 +5860,7 @@ resource "aws_instance" "foo" { }) p := testProvider("aws") - p.DiffFn = testDiffFn + p.PlanResourceChangeFn = testDiffFn targets := []addrs.Targetable{} target, diags := addrs.ParseTargetStr("module.mod[1].aws_instance.foo[0]") @@ -5924,7 +5924,7 @@ resource "aws_instance" "foo" { }) p := testProvider("aws") - p.DiffFn = testDiffFn + p.PlanResourceChangeFn = testDiffFn target, diags := addrs.ParseTargetStr("module.mod[1].aws_instance.foo") if diags.HasErrors() { @@ -5994,7 +5994,7 @@ resource "aws_instance" "foo" { }) p := testProvider("aws") - p.DiffFn = testDiffFn + p.PlanResourceChangeFn = testDiffFn ctx := testContext2(t, &ContextOpts{ Config: m, @@ -6075,8 +6075,8 @@ data "test_data_source" "foo" {} // for_each can reference a resource with 0 instances func TestContext2Plan_scaleInForEach(t *testing.T) { p := testProvider("test") - p.ApplyFn = testApplyFn - p.DiffFn = testDiffFn + p.ApplyResourceChangeFn = testApplyFn + p.PlanResourceChangeFn = testDiffFn m := testModuleInline(t, map[string]string{ "main.tf": ` @@ -6129,7 +6129,7 @@ resource "test_instance" "b" { func TestContext2Plan_targetedModuleInstance(t *testing.T) { m := testModule(t, "plan-targeted") p := testProvider("aws") - p.DiffFn = testDiffFn + p.PlanResourceChangeFn = testDiffFn ctx := testContext2(t, &ContextOpts{ Config: m, Providers: map[addrs.Provider]providers.Factory{ @@ -6212,8 +6212,8 @@ data "test_data_source" "d" { func TestContext2Plan_dataReferencesResource(t *testing.T) { p := testProvider("test") - p.ApplyFn = testApplyFn - p.DiffFn = testDiffFn + p.ApplyResourceChangeFn = testApplyFn + p.PlanResourceChangeFn = testDiffFn p.ReadDataSourceFn = func(req providers.ReadDataSourceRequest) (resp providers.ReadDataSourceResponse) { resp.Diagnostics = resp.Diagnostics.Append(fmt.Errorf("data source should not be read")) @@ -6261,8 +6261,8 @@ data "test_data_source" "e" { func TestContext2Plan_skipRefresh(t *testing.T) { p := testProvider("test") - p.ApplyFn = testApplyFn - p.DiffFn = testDiffFn + p.ApplyResourceChangeFn = testApplyFn + p.PlanResourceChangeFn = testDiffFn m := testModuleInline(t, map[string]string{ "main.tf": ` @@ -6307,8 +6307,8 @@ resource "test_instance" "a" { func TestContext2Plan_dataInModuleDependsOn(t *testing.T) { p := testProvider("test") - p.ApplyFn = testApplyFn - p.DiffFn = testDiffFn + p.ApplyResourceChangeFn = testApplyFn + p.PlanResourceChangeFn = testDiffFn readDataSourceB := false p.ReadDataSourceFn = func(req providers.ReadDataSourceRequest) (resp providers.ReadDataSourceResponse) { diff --git a/terraform/context_refresh_test.go b/terraform/context_refresh_test.go index f91627437..77535d735 100644 --- a/terraform/context_refresh_test.go +++ b/terraform/context_refresh_test.go @@ -52,7 +52,7 @@ func TestContext2Refresh(t *testing.T) { p.ReadResourceResponse = providers.ReadResourceResponse{ NewState: readState, } - p.DiffFn = testDiffFn + p.PlanResourceChangeFn = testDiffFn s, diags := ctx.Refresh() if diags.HasErrors() { @@ -282,7 +282,7 @@ func TestContext2Refresh_targeted(t *testing.T) { NewState: req.PriorState, } } - p.DiffFn = testDiffFn + p.PlanResourceChangeFn = testDiffFn _, diags := ctx.Refresh() if diags.HasErrors() { @@ -361,7 +361,7 @@ func TestContext2Refresh_targetedCount(t *testing.T) { NewState: req.PriorState, } } - p.DiffFn = testDiffFn + p.PlanResourceChangeFn = testDiffFn _, diags := ctx.Refresh() if diags.HasErrors() { @@ -448,7 +448,7 @@ func TestContext2Refresh_targetedCountIndex(t *testing.T) { NewState: req.PriorState, } } - p.DiffFn = testDiffFn + p.PlanResourceChangeFn = testDiffFn _, diags := ctx.Refresh() if diags.HasErrors() { @@ -480,7 +480,7 @@ func TestContext2Refresh_moduleComputedVar(t *testing.T) { }, }, } - p.DiffFn = testDiffFn + p.PlanResourceChangeFn = testDiffFn m := testModule(t, "refresh-module-computed-var") ctx := testContext2(t, &ContextOpts{ @@ -517,7 +517,7 @@ func TestContext2Refresh_delete(t *testing.T) { p.ReadResourceResponse = providers.ReadResourceResponse{ NewState: cty.NullVal(p.GetSchemaReturn.ResourceTypes["aws_instance"].ImpliedType()), } - p.DiffFn = testDiffFn + p.PlanResourceChangeFn = testDiffFn s, diags := ctx.Refresh() if diags.HasErrors() { @@ -547,7 +547,7 @@ func TestContext2Refresh_ignoreUncreated(t *testing.T) { "id": cty.StringVal("foo"), }), } - p.DiffFn = testDiffFn + p.PlanResourceChangeFn = testDiffFn _, diags := ctx.Refresh() if diags.HasErrors() { @@ -561,7 +561,7 @@ func TestContext2Refresh_ignoreUncreated(t *testing.T) { func TestContext2Refresh_hook(t *testing.T) { h := new(MockHook) p := testProvider("aws") - p.DiffFn = testDiffFn + p.PlanResourceChangeFn = testDiffFn m := testModule(t, "refresh-basic") state := states.NewState() @@ -623,7 +623,7 @@ func TestContext2Refresh_modules(t *testing.T) { NewState: new, } } - p.DiffFn = testDiffFn + p.PlanResourceChangeFn = testDiffFn s, diags := ctx.Refresh() if diags.HasErrors() { @@ -640,7 +640,7 @@ func TestContext2Refresh_modules(t *testing.T) { func TestContext2Refresh_moduleInputComputedOutput(t *testing.T) { m := testModule(t, "refresh-module-input-computed-output") p := testProvider("aws") - p.DiffFn = testDiffFn + p.PlanResourceChangeFn = testDiffFn p.GetSchemaReturn = &ProviderSchema{ Provider: &configschema.Block{}, ResourceTypes: map[string]*configschema.Block{ @@ -675,7 +675,7 @@ func TestContext2Refresh_moduleInputComputedOutput(t *testing.T) { func TestContext2Refresh_moduleVarModule(t *testing.T) { m := testModule(t, "refresh-module-var-module") p := testProvider("aws") - p.DiffFn = testDiffFn + p.PlanResourceChangeFn = testDiffFn ctx := testContext2(t, &ContextOpts{ Config: m, Providers: map[addrs.Provider]providers.Factory{ @@ -705,7 +705,7 @@ func TestContext2Refresh_noState(t *testing.T) { "id": cty.StringVal("foo"), }), } - p.DiffFn = testDiffFn + p.PlanResourceChangeFn = testDiffFn if _, diags := ctx.Refresh(); diags.HasErrors() { t.Fatalf("refresh errs: %s", diags.Err()) @@ -732,7 +732,7 @@ func TestContext2Refresh_output(t *testing.T) { }, }, } - p.DiffFn = testDiffFn + p.PlanResourceChangeFn = testDiffFn m := testModule(t, "refresh-output") @@ -768,7 +768,7 @@ func TestContext2Refresh_outputPartial(t *testing.T) { // Refresh creates a partial plan for any instances that don't have // remote objects yet, to get stub values for interpolation. Therefore // we need to make DiffFn available to let that complete. - p.DiffFn = testDiffFn + p.PlanResourceChangeFn = testDiffFn p.GetSchemaReturn = &ProviderSchema{ Provider: &configschema.Block{}, @@ -840,7 +840,7 @@ func TestContext2Refresh_stateBasic(t *testing.T) { } p.ReadResourceFn = nil - p.DiffFn = testDiffFn + p.PlanResourceChangeFn = testDiffFn p.ReadResourceResponse = providers.ReadResourceResponse{ NewState: readStateVal, } @@ -949,7 +949,7 @@ func TestContext2Refresh_dataState(t *testing.T) { State: readStateVal, } } - p.DiffFn = testDiffFn + p.PlanResourceChangeFn = testDiffFn s, diags := ctx.Refresh() if diags.HasErrors() { @@ -1015,7 +1015,7 @@ func TestContext2Refresh_dataStateRefData(t *testing.T) { State: cty.ObjectVal(m), } } - p.DiffFn = testDiffFn + p.PlanResourceChangeFn = testDiffFn s, diags := ctx.Refresh() if diags.HasErrors() { @@ -1053,7 +1053,7 @@ func TestContext2Refresh_tainted(t *testing.T) { NewState: cty.ObjectVal(m), } } - p.DiffFn = testDiffFn + p.PlanResourceChangeFn = testDiffFn s, diags := ctx.Refresh() if diags.HasErrors() { @@ -1077,8 +1077,8 @@ func TestContext2Refresh_tainted(t *testing.T) { func TestContext2Refresh_unknownProvider(t *testing.T) { m := testModule(t, "refresh-unknown-provider") p := testProvider("aws") - p.ApplyFn = testApplyFn - p.DiffFn = testDiffFn + p.ApplyResourceChangeFn = testApplyFn + p.PlanResourceChangeFn = testDiffFn state := states.NewState() root := state.EnsureModule(addrs.RootModuleInstance) @@ -1141,7 +1141,7 @@ func TestContext2Refresh_vars(t *testing.T) { } p.ReadResourceFn = nil - p.DiffFn = testDiffFn + p.PlanResourceChangeFn = testDiffFn p.ReadResourceResponse = providers.ReadResourceResponse{ NewState: readStateVal, } @@ -1195,7 +1195,7 @@ func TestContext2Refresh_orphanModule(t *testing.T) { NewState: req.PriorState, } } - p.DiffFn = testDiffFn + p.PlanResourceChangeFn = testDiffFn state := states.NewState() root := state.EnsureModule(addrs.RootModuleInstance) @@ -1265,7 +1265,7 @@ func TestContext2Validate(t *testing.T) { }, }, } - p.DiffFn = testDiffFn + p.PlanResourceChangeFn = testDiffFn m := testModule(t, "validate-good") c := testContext2(t, &ContextOpts{ @@ -1284,8 +1284,8 @@ func TestContext2Validate(t *testing.T) { func TestContext2Refresh_updateProviderInState(t *testing.T) { m := testModule(t, "update-resource-provider") p := testProvider("aws") - p.DiffFn = testDiffFn - p.ApplyFn = testApplyFn + p.PlanResourceChangeFn = testDiffFn + p.ApplyResourceChangeFn = testApplyFn state := states.NewState() root := state.EnsureModule(addrs.RootModuleInstance) @@ -1338,7 +1338,7 @@ func TestContext2Refresh_schemaUpgradeFlatmap(t *testing.T) { "name": cty.StringVal("foo"), }), } - p.DiffFn = testDiffFn + p.PlanResourceChangeFn = testDiffFn s := states.BuildState(func(s *states.SyncState) { s.SetResourceInstanceCurrent( @@ -1425,7 +1425,7 @@ func TestContext2Refresh_schemaUpgradeJSON(t *testing.T) { "name": cty.StringVal("foo"), }), } - p.DiffFn = testDiffFn + p.PlanResourceChangeFn = testDiffFn s := states.BuildState(func(s *states.SyncState) { s.SetResourceInstanceCurrent( @@ -1503,7 +1503,7 @@ data "aws_data_source" "foo" { resp.State = req.Config return } - p.DiffFn = testDiffFn + p.PlanResourceChangeFn = testDiffFn ctx := testContext2(t, &ContextOpts{ Config: m, @@ -1544,7 +1544,7 @@ func TestContext2Refresh_dataResourceDependsOn(t *testing.T) { }, }, } - p.DiffFn = testDiffFn + p.PlanResourceChangeFn = testDiffFn p.ReadDataSourceResponse = providers.ReadDataSourceResponse{ State: cty.ObjectVal(map[string]cty.Value{ "compute": cty.StringVal("value"), @@ -1653,8 +1653,8 @@ resource "aws_instance" "foo" { }) p := testProvider("aws") - p.ApplyFn = testApplyFn - p.DiffFn = testDiffFn + p.ApplyResourceChangeFn = testApplyFn + p.PlanResourceChangeFn = testDiffFn ctx := testContext2(t, &ContextOpts{ Config: m, @@ -1722,8 +1722,8 @@ resource "aws_instance" "bar" { }) p := testProvider("aws") - p.ApplyFn = testApplyFn - p.DiffFn = testDiffFn + p.ApplyResourceChangeFn = testApplyFn + p.PlanResourceChangeFn = testDiffFn ctx := testContext2(t, &ContextOpts{ Config: m, diff --git a/terraform/context_validate_test.go b/terraform/context_validate_test.go index 28172182b..c1848a12f 100644 --- a/terraform/context_validate_test.go +++ b/terraform/context_validate_test.go @@ -928,8 +928,8 @@ func TestContext2Validate_targetedDestroy(t *testing.T) { m := testModule(t, "validate-targeted") p := testProvider("aws") pr := simpleMockProvisioner() - p.ApplyFn = testApplyFn - p.DiffFn = testDiffFn + p.ApplyResourceChangeFn = testApplyFn + p.PlanResourceChangeFn = testDiffFn p.GetSchemaReturn = &ProviderSchema{ ResourceTypes: map[string]*configschema.Block{ "aws_instance": { @@ -1017,8 +1017,8 @@ func TestContext2Validate_interpolateVar(t *testing.T) { m := testModule(t, "input-interpolate-var") p := testProvider("null") - p.ApplyFn = testApplyFn - p.DiffFn = testDiffFn + p.ApplyResourceChangeFn = testApplyFn + p.PlanResourceChangeFn = testDiffFn p.GetSchemaReturn = &ProviderSchema{ ResourceTypes: map[string]*configschema.Block{ "template_file": { @@ -1050,8 +1050,8 @@ func TestContext2Validate_interpolateComputedModuleVarDef(t *testing.T) { m := testModule(t, "validate-computed-module-var-ref") p := testProvider("aws") - p.ApplyFn = testApplyFn - p.DiffFn = testDiffFn + p.ApplyResourceChangeFn = testApplyFn + p.PlanResourceChangeFn = testDiffFn p.GetSchemaReturn = &ProviderSchema{ ResourceTypes: map[string]*configschema.Block{ "aws_instance": { @@ -1082,8 +1082,8 @@ func TestContext2Validate_interpolateMap(t *testing.T) { m := testModule(t, "issue-9549") p := testProvider("template") - p.ApplyFn = testApplyFn - p.DiffFn = testDiffFn + p.ApplyResourceChangeFn = testApplyFn + p.PlanResourceChangeFn = testDiffFn ctx := testContext2(t, &ContextOpts{ Config: m, @@ -1482,7 +1482,7 @@ resource "aws_instance" "foo" { }) p := testProvider("aws") - p.DiffFn = testDiffFn + p.PlanResourceChangeFn = testDiffFn ctx := testContext2(t, &ContextOpts{ Config: m, Providers: map[addrs.Provider]providers.Factory{ @@ -1511,7 +1511,7 @@ resource "aws_instance" "foo" { }) p := testProvider("aws") - p.DiffFn = testDiffFn + p.PlanResourceChangeFn = testDiffFn ctx := testContext2(t, &ContextOpts{ Config: m, Providers: map[addrs.Provider]providers.Factory{ @@ -1543,7 +1543,7 @@ resource "aws_instance" "foo" { }) p := testProvider("aws") - p.DiffFn = testDiffFn + p.PlanResourceChangeFn = testDiffFn ctx := testContext2(t, &ContextOpts{ Config: m, Providers: map[addrs.Provider]providers.Factory{ @@ -1626,7 +1626,7 @@ output "out" { }) p := testProvider("aws") - p.DiffFn = testDiffFn + p.PlanResourceChangeFn = testDiffFn ctx := testContext2(t, &ContextOpts{ Config: m, Providers: map[addrs.Provider]providers.Factory{ diff --git a/terraform/provider_mock.go b/terraform/provider_mock.go index b7c647c49..45397fe22 100644 --- a/terraform/provider_mock.go +++ b/terraform/provider_mock.go @@ -86,9 +86,6 @@ type MockProvider struct { CloseCalled bool CloseError error - - DiffFn func(providers.PlanResourceChangeRequest) providers.PlanResourceChangeResponse - ApplyFn func(providers.ApplyResourceChangeRequest) providers.ApplyResourceChangeResponse } func (p *MockProvider) GetSchema() providers.GetSchemaResponse { @@ -263,9 +260,6 @@ func (p *MockProvider) PlanResourceChange(r providers.PlanResourceChangeRequest) p.PlanResourceChangeCalled = true p.PlanResourceChangeRequest = r - if p.DiffFn != nil { - return p.DiffFn(r) - } if p.PlanResourceChangeFn != nil { return p.PlanResourceChangeFn(r) } @@ -279,9 +273,6 @@ func (p *MockProvider) ApplyResourceChange(r providers.ApplyResourceChangeReques p.ApplyResourceChangeRequest = r p.Unlock() - if p.ApplyFn != nil { - return p.ApplyFn(r) - } if p.ApplyResourceChangeFn != nil { return p.ApplyResourceChangeFn(r) } diff --git a/terraform/provisioner_mock.go b/terraform/provisioner_mock.go index d476e4ea7..2a3323541 100644 --- a/terraform/provisioner_mock.go +++ b/terraform/provisioner_mock.go @@ -1,12 +1,8 @@ package terraform import ( - "fmt" "sync" - "github.com/zclconf/go-cty/cty" - "github.com/zclconf/go-cty/cty/convert" - "github.com/hashicorp/terraform/provisioners" ) @@ -39,12 +35,6 @@ type MockProvisioner struct { CloseCalled bool CloseResponse error CloseFn func() error - - // Legacy callbacks: if these are set, we will shim incoming calls for - // new-style methods to these old-fashioned terraform.ResourceProvider - // mock callbacks, for the benefit of older tests that were written against - // the old mock API. - ApplyFn func(rs *InstanceState, c *ResourceConfig) error } func (p *MockProvisioner) GetSchema() provisioners.GetSchemaResponse { @@ -79,45 +69,6 @@ func (p *MockProvisioner) ProvisionResource(r provisioners.ProvisionResourceRequ p.ProvisionResourceCalled = true p.ProvisionResourceRequest = r - if p.ApplyFn != nil { - if !r.Config.IsKnown() { - panic(fmt.Sprintf("cannot provision with unknown value: %#v", r.Config)) - } - - schema := p.getSchema() - rc := NewResourceConfigShimmed(r.Config, schema.Provisioner) - connVal := r.Connection - connMap := map[string]string{} - - if !connVal.IsNull() && connVal.IsKnown() { - for it := connVal.ElementIterator(); it.Next(); { - ak, av := it.Element() - name := ak.AsString() - - if !av.IsKnown() || av.IsNull() { - continue - } - - av, _ = convert.Convert(av, cty.String) - connMap[name] = av.AsString() - } - } - - // We no longer pass the full instance state to a provisioner, so we'll - // construct a partial one that should be good enough for what existing - // test mocks need. - is := &InstanceState{ - Ephemeral: EphemeralState{ - ConnInfo: connMap, - }, - } - var resp provisioners.ProvisionResourceResponse - err := p.ApplyFn(is, rc) - if err != nil { - resp.Diagnostics = resp.Diagnostics.Append(err) - } - return resp - } if p.ProvisionResourceFn != nil { fn := p.ProvisionResourceFn return fn(r) From 027a6c2cf67a20d6a9663496d021fc15b3d05c73 Mon Sep 17 00:00:00 2001 From: James Bardin Date: Thu, 8 Oct 2020 13:42:06 -0400 Subject: [PATCH 8/9] update command tests to use new mock provider --- command/apply_test.go | 69 +++++++++++------------------------------- command/import_test.go | 10 +++--- command/plan_test.go | 57 +++++++++++----------------------- 3 files changed, 41 insertions(+), 95 deletions(-) diff --git a/command/apply_test.go b/command/apply_test.go index 74719c32a..280568b4f 100644 --- a/command/apply_test.go +++ b/command/apply_test.go @@ -341,43 +341,26 @@ func TestApply_error(t *testing.T) { var lock sync.Mutex errored := false - p.ApplyFn = func(info *terraform.InstanceInfo, s *terraform.InstanceState, d *terraform.InstanceDiff) (*terraform.InstanceState, error) { + p.ApplyResourceChangeFn = func(req providers.ApplyResourceChangeRequest) (resp providers.ApplyResourceChangeResponse) { lock.Lock() defer lock.Unlock() if !errored { errored = true - return nil, fmt.Errorf("error") + resp.Diagnostics = resp.Diagnostics.Append(fmt.Errorf("error")) } - newState := &terraform.InstanceState{ - ID: "foo", - Attributes: map[string]string{}, - } - newState.Attributes["id"] = newState.ID - if ad, ok := d.Attributes["ami"]; ok { - newState.Attributes["ami"] = ad.New - } - if ad, ok := d.Attributes["error"]; ok { - newState.Attributes["error"] = ad.New - } - return newState, nil + s := req.PlannedState.AsValueMap() + s["id"] = cty.StringVal("foo") + + resp.NewState = cty.ObjectVal(s) + return } - p.DiffFn = func(info *terraform.InstanceInfo, s *terraform.InstanceState, rc *terraform.ResourceConfig) (*terraform.InstanceDiff, error) { - ret := &terraform.InstanceDiff{ - Attributes: map[string]*terraform.ResourceAttrDiff{}, - } - if new, ok := rc.Get("ami"); ok { - ret.Attributes["ami"] = &terraform.ResourceAttrDiff{ - New: new.(string), - } - } - if new, ok := rc.Get("error"); ok { - ret.Attributes["error"] = &terraform.ResourceAttrDiff{ - New: fmt.Sprintf("%t", new.(bool)), - } - } - return ret, nil + p.PlanResourceChangeFn = func(req providers.PlanResourceChangeRequest) (resp providers.PlanResourceChangeResponse) { + s := req.ProposedNewState.AsValueMap() + s["id"] = cty.UnknownVal(cty.String) + resp.PlannedState = cty.ObjectVal(s) + return } p.GetSchemaReturn = &terraform.ProviderSchema{ ResourceTypes: map[string]*configschema.Block{ @@ -902,25 +885,13 @@ func TestApply_shutdown(t *testing.T) { return nil } - p.DiffFn = func( - *terraform.InstanceInfo, - *terraform.InstanceState, - *terraform.ResourceConfig) (*terraform.InstanceDiff, error) { - return &terraform.InstanceDiff{ - Attributes: map[string]*terraform.ResourceAttrDiff{ - "ami": &terraform.ResourceAttrDiff{ - New: "bar", - }, - }, - }, nil + p.PlanResourceChangeFn = func(req providers.PlanResourceChangeRequest) (resp providers.PlanResourceChangeResponse) { + resp.PlannedState = req.ProposedNewState + return } var once sync.Once - p.ApplyFn = func( - *terraform.InstanceInfo, - *terraform.InstanceState, - *terraform.InstanceDiff) (*terraform.InstanceState, error) { - + p.ApplyResourceChangeFn = func(req providers.ApplyResourceChangeRequest) (resp providers.ApplyResourceChangeResponse) { // only cancel once once.Do(func() { shutdownCh <- struct{}{} @@ -934,12 +905,8 @@ func TestApply_shutdown(t *testing.T) { // canceled. time.Sleep(200 * time.Millisecond) - return &terraform.InstanceState{ - ID: "foo", - Attributes: map[string]string{ - "ami": "2", - }, - }, nil + resp.NewState = req.PlannedState + return } p.GetSchemaReturn = &terraform.ProviderSchema{ diff --git a/command/import_test.go b/command/import_test.go index 21174727c..bde634c21 100644 --- a/command/import_test.go +++ b/command/import_test.go @@ -110,7 +110,7 @@ func TestImport_providerConfig(t *testing.T) { } configured := false - p.ConfigureNewFn = func(req providers.ConfigureRequest) providers.ConfigureResponse { + p.ConfigureFn = func(req providers.ConfigureRequest) providers.ConfigureResponse { configured = true cfg := req.Config @@ -217,7 +217,7 @@ func TestImport_remoteState(t *testing.T) { } configured := false - p.ConfigureNewFn = func(req providers.ConfigureRequest) providers.ConfigureResponse { + p.ConfigureFn = func(req providers.ConfigureRequest) providers.ConfigureResponse { var diags tfdiags.Diagnostics configured = true if got, want := req.Config.GetAttr("foo"), cty.StringVal("bar"); !want.RawEquals(got) { @@ -364,7 +364,7 @@ func TestImport_providerConfigWithVar(t *testing.T) { } configured := false - p.ConfigureNewFn = func(req providers.ConfigureRequest) providers.ConfigureResponse { + p.ConfigureFn = func(req providers.ConfigureRequest) providers.ConfigureResponse { var diags tfdiags.Diagnostics configured = true if got, want := req.Config.GetAttr("foo"), cty.StringVal("bar"); !want.RawEquals(got) { @@ -495,7 +495,7 @@ func TestImport_providerConfigWithVarDefault(t *testing.T) { } configured := false - p.ConfigureNewFn = func(req providers.ConfigureRequest) providers.ConfigureResponse { + p.ConfigureFn = func(req providers.ConfigureRequest) providers.ConfigureResponse { var diags tfdiags.Diagnostics configured = true if got, want := req.Config.GetAttr("foo"), cty.StringVal("bar"); !want.RawEquals(got) { @@ -568,7 +568,7 @@ func TestImport_providerConfigWithVarFile(t *testing.T) { } configured := false - p.ConfigureNewFn = func(req providers.ConfigureRequest) providers.ConfigureResponse { + p.ConfigureFn = func(req providers.ConfigureRequest) providers.ConfigureResponse { var diags tfdiags.Diagnostics configured = true if got, want := req.Config.GetAttr("foo"), cty.StringVal("bar"); !want.RawEquals(got) { diff --git a/command/plan_test.go b/command/plan_test.go index 46b631a6f..831f45dfc 100644 --- a/command/plan_test.go +++ b/command/plan_test.go @@ -524,15 +524,10 @@ func TestPlan_vars(t *testing.T) { } actual := "" - p.DiffFn = func( - info *terraform.InstanceInfo, - s *terraform.InstanceState, - c *terraform.ResourceConfig) (*terraform.InstanceDiff, error) { - if v, ok := c.Config["value"]; ok { - actual = v.(string) - } - - return nil, nil + p.PlanResourceChangeFn = func(req providers.PlanResourceChangeRequest) (resp providers.PlanResourceChangeResponse) { + actual = req.ProposedNewState.GetAttr("value").AsString() + resp.PlannedState = req.ProposedNewState + return } args := []string{ @@ -656,15 +651,10 @@ func TestPlan_varFile(t *testing.T) { } actual := "" - p.DiffFn = func( - info *terraform.InstanceInfo, - s *terraform.InstanceState, - c *terraform.ResourceConfig) (*terraform.InstanceDiff, error) { - if v, ok := c.Config["value"]; ok { - actual = v.(string) - } - - return nil, nil + p.PlanResourceChangeFn = func(req providers.PlanResourceChangeRequest) (resp providers.PlanResourceChangeResponse) { + actual = req.ProposedNewState.GetAttr("value").AsString() + resp.PlannedState = req.ProposedNewState + return } args := []string{ @@ -706,15 +696,10 @@ func TestPlan_varFileDefault(t *testing.T) { } actual := "" - p.DiffFn = func( - info *terraform.InstanceInfo, - s *terraform.InstanceState, - c *terraform.ResourceConfig) (*terraform.InstanceDiff, error) { - if v, ok := c.Config["value"]; ok { - actual = v.(string) - } - - return nil, nil + p.PlanResourceChangeFn = func(req providers.PlanResourceChangeRequest) (resp providers.PlanResourceChangeResponse) { + actual = req.ProposedNewState.GetAttr("value").AsString() + resp.PlannedState = req.ProposedNewState + return } args := []string{ @@ -824,11 +809,7 @@ func TestPlan_shutdown(t *testing.T) { var once sync.Once - p.DiffFn = func( - *terraform.InstanceInfo, - *terraform.InstanceState, - *terraform.ResourceConfig) (*terraform.InstanceDiff, error) { - + p.PlanResourceChangeFn = func(req providers.PlanResourceChangeRequest) (resp providers.PlanResourceChangeResponse) { once.Do(func() { shutdownCh <- struct{}{} }) @@ -841,14 +822,12 @@ func TestPlan_shutdown(t *testing.T) { // canceled. time.Sleep(200 * time.Millisecond) - return &terraform.InstanceDiff{ - Attributes: map[string]*terraform.ResourceAttrDiff{ - "ami": &terraform.ResourceAttrDiff{ - New: "bar", - }, - }, - }, nil + s := req.ProposedNewState.AsValueMap() + s["ami"] = cty.StringVal("bar") + resp.PlannedState = cty.ObjectVal(s) + return } + p.GetSchemaReturn = &terraform.ProviderSchema{ ResourceTypes: map[string]*configschema.Block{ "test_instance": { From 103a6cf2dbf9b1adb756a20e07097a9ea809c7bb Mon Sep 17 00:00:00 2001 From: James Bardin Date: Thu, 8 Oct 2020 13:52:04 -0400 Subject: [PATCH 9/9] update mock provider call --- backend/local/backend_refresh_test.go | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) diff --git a/backend/local/backend_refresh_test.go b/backend/local/backend_refresh_test.go index 7d96b971b..cb6cb9b4f 100644 --- a/backend/local/backend_refresh_test.go +++ b/backend/local/backend_refresh_test.go @@ -79,12 +79,13 @@ func TestLocal_refreshInput(t *testing.T) { p.ReadResourceResponse = providers.ReadResourceResponse{NewState: cty.ObjectVal(map[string]cty.Value{ "id": cty.StringVal("yes"), })} - p.ConfigureFn = func(c *terraform.ResourceConfig) error { - if v, ok := c.Get("value"); !ok || v != "bar" { - return fmt.Errorf("no value set") + p.ConfigureFn = func(req providers.ConfigureRequest) (resp providers.ConfigureResponse) { + val := req.Config.GetAttr("value") + if val.IsNull() || val.AsString() != "bar" { + resp.Diagnostics = resp.Diagnostics.Append(fmt.Errorf("incorrect value %#v", val)) } - return nil + return } // Enable input asking since it is normally disabled by default