diff --git a/backend/local/testing.go b/backend/local/testing.go index 91ba0f900..1d3c582cc 100644 --- a/backend/local/testing.go +++ b/backend/local/testing.go @@ -47,14 +47,13 @@ func TestLocalProvider(t *testing.T, b *Local, name string) *terraform.MockResou if b.ContextOpts == nil { b.ContextOpts = &terraform.ContextOpts{} } - if b.ContextOpts.Providers == nil { - b.ContextOpts.Providers = make(map[string]terraform.ResourceProviderFactory) - } // Setup our provider - b.ContextOpts.Providers[name] = func() (terraform.ResourceProvider, error) { - return p, nil - } + b.ContextOpts.ProviderResolver = terraform.ResourceProviderResolverFixed( + map[string]terraform.ResourceProviderFactory{ + name: terraform.ResourceProviderFactoryFixed(p), + }, + ) return p } diff --git a/command/command_test.go b/command/command_test.go index 77cb3e741..a416256f8 100644 --- a/command/command_test.go +++ b/command/command_test.go @@ -71,21 +71,25 @@ func testFixturePath(name string) string { func metaOverridesForProvider(p terraform.ResourceProvider) *testingOverrides { return &testingOverrides{ - Providers: map[string]terraform.ResourceProviderFactory{ - "test": func() (terraform.ResourceProvider, error) { - return p, nil + ProviderResolver: terraform.ResourceProviderResolverFixed( + map[string]terraform.ResourceProviderFactory{ + "test": func() (terraform.ResourceProvider, error) { + return p, nil + }, }, - }, + ), } } func metaOverridesForProviderAndProvisioner(p terraform.ResourceProvider, pr terraform.ResourceProvisioner) *testingOverrides { return &testingOverrides{ - Providers: map[string]terraform.ResourceProviderFactory{ - "test": func() (terraform.ResourceProvider, error) { - return p, nil + ProviderResolver: terraform.ResourceProviderResolverFixed( + map[string]terraform.ResourceProviderFactory{ + "test": func() (terraform.ResourceProvider, error) { + return p, nil + }, }, - }, + ), Provisioners: map[string]terraform.ResourceProvisionerFactory{ "shell": func() (terraform.ResourceProvisioner, error) { return pr, nil diff --git a/helper/resource/testing.go b/helper/resource/testing.go index a700a8c79..11b1a5cd6 100644 --- a/helper/resource/testing.go +++ b/helper/resource/testing.go @@ -383,11 +383,11 @@ func Test(t TestT, c TestCase) { c.PreCheck() } - ctxProviders, err := testProviderFactories(c) + providerResolver, err := testProviderResolver(c) if err != nil { t.Fatal(err) } - opts := terraform.ContextOpts{Providers: ctxProviders} + opts := terraform.ContextOpts{ProviderResolver: providerResolver} // A single state variable to track the lifecycle, starting with no state var state *terraform.State @@ -499,16 +499,17 @@ func Test(t TestT, c TestCase) { } } -// testProviderFactories is a helper to build the ResourceProviderFactory map +// testProviderResolver is a helper to build a ResourceProviderResolver // with pre instantiated ResourceProviders, so that we can reset them for the // test, while only calling the factory function once. // Any errors are stored so that they can be returned by the factory in // terraform to match non-test behavior. -func testProviderFactories(c TestCase) (map[string]terraform.ResourceProviderFactory, error) { - ctxProviders := c.ProviderFactories // make(map[string]terraform.ResourceProviderFactory) +func testProviderResolver(c TestCase) (terraform.ResourceProviderResolver, error) { + ctxProviders := c.ProviderFactories if ctxProviders == nil { ctxProviders = make(map[string]terraform.ResourceProviderFactory) } + // add any fixed providers for k, p := range c.Providers { ctxProviders[k] = terraform.ResourceProviderFactoryFixed(p) @@ -530,7 +531,7 @@ func testProviderFactories(c TestCase) (map[string]terraform.ResourceProviderFac } } - return ctxProviders, nil + return terraform.ResourceProviderResolverFixed(ctxProviders), nil } // UnitTest is a helper to force the acceptance testing harness to run in the diff --git a/terraform/context_apply_test.go b/terraform/context_apply_test.go index 0a59ab5f4..044e6666d 100644 --- a/terraform/context_apply_test.go +++ b/terraform/context_apply_test.go @@ -23,9 +23,11 @@ func TestContext2Apply_basic(t *testing.T) { p.DiffFn = testDiffFn ctx := testContext2(t, &ContextOpts{ Module: m, - Providers: map[string]ResourceProviderFactory{ - "aws": testProviderFuncFixed(p), - }, + ProviderResolver: ResourceProviderResolverFixed( + map[string]ResourceProviderFactory{ + "aws": testProviderFuncFixed(p), + }, + ), }) if _, err := ctx.Plan(); err != nil { @@ -56,9 +58,11 @@ func TestContext2Apply_escape(t *testing.T) { p.DiffFn = testDiffFn ctx := testContext2(t, &ContextOpts{ Module: m, - Providers: map[string]ResourceProviderFactory{ - "aws": testProviderFuncFixed(p), - }, + ProviderResolver: ResourceProviderResolverFixed( + map[string]ResourceProviderFactory{ + "aws": testProviderFuncFixed(p), + }, + ), }) if _, err := ctx.Plan(); err != nil { @@ -85,9 +89,11 @@ func TestContext2Apply_resourceCountOneList(t *testing.T) { p.DiffFn = testDiffFn ctx := testContext2(t, &ContextOpts{ Module: m, - Providers: map[string]ResourceProviderFactory{ - "null": testProviderFuncFixed(p), - }, + ProviderResolver: ResourceProviderResolverFixed( + map[string]ResourceProviderFactory{ + "null": testProviderFuncFixed(p), + }, + ), }) if _, err := ctx.Plan(); err != nil { @@ -117,9 +123,11 @@ func TestContext2Apply_resourceCountZeroList(t *testing.T) { p.DiffFn = testDiffFn ctx := testContext2(t, &ContextOpts{ Module: m, - Providers: map[string]ResourceProviderFactory{ - "null": testProviderFuncFixed(p), - }, + ProviderResolver: ResourceProviderResolverFixed( + map[string]ResourceProviderFactory{ + "null": testProviderFuncFixed(p), + }, + ), }) if _, err := ctx.Plan(); err != nil { @@ -173,9 +181,11 @@ func TestContext2Apply_resourceDependsOnModule(t *testing.T) { ctx := testContext2(t, &ContextOpts{ Module: m, - Providers: map[string]ResourceProviderFactory{ - "aws": testProviderFuncFixed(p), - }, + ProviderResolver: ResourceProviderResolverFixed( + map[string]ResourceProviderFactory{ + "aws": testProviderFuncFixed(p), + }, + ), }) if _, err := ctx.Plan(); err != nil { @@ -257,9 +267,11 @@ func TestContext2Apply_resourceDependsOnModuleStateOnly(t *testing.T) { ctx := testContext2(t, &ContextOpts{ Module: m, - Providers: map[string]ResourceProviderFactory{ - "aws": testProviderFuncFixed(p), - }, + ProviderResolver: ResourceProviderResolverFixed( + map[string]ResourceProviderFactory{ + "aws": testProviderFuncFixed(p), + }, + ), State: state, }) @@ -294,9 +306,11 @@ func TestContext2Apply_resourceDependsOnModuleDestroy(t *testing.T) { p.ApplyFn = testApplyFn ctx := testContext2(t, &ContextOpts{ Module: m, - Providers: map[string]ResourceProviderFactory{ - "aws": testProviderFuncFixed(p), - }, + ProviderResolver: ResourceProviderResolverFixed( + map[string]ResourceProviderFactory{ + "aws": testProviderFuncFixed(p), + }, + ), }) if _, err := ctx.Plan(); err != nil { @@ -338,9 +352,11 @@ func TestContext2Apply_resourceDependsOnModuleDestroy(t *testing.T) { ctx := testContext2(t, &ContextOpts{ Module: m, - Providers: map[string]ResourceProviderFactory{ - "aws": testProviderFuncFixed(p), - }, + ProviderResolver: ResourceProviderResolverFixed( + map[string]ResourceProviderFactory{ + "aws": testProviderFuncFixed(p), + }, + ), State: globalState, Destroy: true, }) @@ -398,9 +414,11 @@ func TestContext2Apply_resourceDependsOnModuleGrandchild(t *testing.T) { ctx := testContext2(t, &ContextOpts{ Module: m, - Providers: map[string]ResourceProviderFactory{ - "aws": testProviderFuncFixed(p), - }, + ProviderResolver: ResourceProviderResolverFixed( + map[string]ResourceProviderFactory{ + "aws": testProviderFuncFixed(p), + }, + ), }) if _, err := ctx.Plan(); err != nil { @@ -452,9 +470,11 @@ func TestContext2Apply_resourceDependsOnModuleInModule(t *testing.T) { ctx := testContext2(t, &ContextOpts{ Module: m, - Providers: map[string]ResourceProviderFactory{ - "aws": testProviderFuncFixed(p), - }, + ProviderResolver: ResourceProviderResolverFixed( + map[string]ResourceProviderFactory{ + "aws": testProviderFuncFixed(p), + }, + ), }) if _, err := ctx.Plan(); err != nil { @@ -481,9 +501,11 @@ func TestContext2Apply_mapVarBetweenModules(t *testing.T) { p.DiffFn = testDiffFn ctx := testContext2(t, &ContextOpts{ Module: m, - Providers: map[string]ResourceProviderFactory{ - "null": testProviderFuncFixed(p), - }, + ProviderResolver: ResourceProviderResolverFixed( + map[string]ResourceProviderFactory{ + "null": testProviderFuncFixed(p), + }, + ), }) if _, err := ctx.Plan(); err != nil { @@ -520,9 +542,11 @@ func TestContext2Apply_refCount(t *testing.T) { p.DiffFn = testDiffFn ctx := testContext2(t, &ContextOpts{ Module: m, - Providers: map[string]ResourceProviderFactory{ - "aws": testProviderFuncFixed(p), - }, + ProviderResolver: ResourceProviderResolverFixed( + map[string]ResourceProviderFactory{ + "aws": testProviderFuncFixed(p), + }, + ), }) if _, err := ctx.Plan(); err != nil { @@ -553,9 +577,11 @@ func TestContext2Apply_providerAlias(t *testing.T) { p.DiffFn = testDiffFn ctx := testContext2(t, &ContextOpts{ Module: m, - Providers: map[string]ResourceProviderFactory{ - "aws": testProviderFuncFixed(p), - }, + ProviderResolver: ResourceProviderResolverFixed( + map[string]ResourceProviderFactory{ + "aws": testProviderFuncFixed(p), + }, + ), }) if _, err := ctx.Plan(); err != nil { @@ -589,9 +615,11 @@ func TestContext2Apply_providerAliasConfigure(t *testing.T) { ctx := testContext2(t, &ContextOpts{ Module: m, - Providers: map[string]ResourceProviderFactory{ - "another": testProviderFuncFixed(p2), - }, + ProviderResolver: ResourceProviderResolverFixed( + map[string]ResourceProviderFactory{ + "another": testProviderFuncFixed(p2), + }, + ), }) if p, err := ctx.Plan(); err != nil { @@ -645,9 +673,11 @@ func TestContext2Apply_providerWarning(t *testing.T) { } ctx := testContext2(t, &ContextOpts{ Module: m, - Providers: map[string]ResourceProviderFactory{ - "aws": testProviderFuncFixed(p), - }, + ProviderResolver: ResourceProviderResolverFixed( + map[string]ResourceProviderFactory{ + "aws": testProviderFuncFixed(p), + }, + ), }) if _, err := ctx.Plan(); err != nil { @@ -726,9 +756,11 @@ func TestContext2Apply_computedAttrRefTypeMismatch(t *testing.T) { } ctx := testContext2(t, &ContextOpts{ Module: m, - Providers: map[string]ResourceProviderFactory{ - "aws": testProviderFuncFixed(p), - }, + ProviderResolver: ResourceProviderResolverFixed( + map[string]ResourceProviderFactory{ + "aws": testProviderFuncFixed(p), + }, + ), }) if _, err := ctx.Plan(); err != nil { @@ -753,9 +785,11 @@ func TestContext2Apply_emptyModule(t *testing.T) { p.DiffFn = testDiffFn ctx := testContext2(t, &ContextOpts{ Module: m, - Providers: map[string]ResourceProviderFactory{ - "aws": testProviderFuncFixed(p), - }, + ProviderResolver: ResourceProviderResolverFixed( + map[string]ResourceProviderFactory{ + "aws": testProviderFuncFixed(p), + }, + ), }) if _, err := ctx.Plan(); err != nil { @@ -800,9 +834,11 @@ func TestContext2Apply_createBeforeDestroy(t *testing.T) { } ctx := testContext2(t, &ContextOpts{ Module: m, - Providers: map[string]ResourceProviderFactory{ - "aws": testProviderFuncFixed(p), - }, + ProviderResolver: ResourceProviderResolverFixed( + map[string]ResourceProviderFactory{ + "aws": testProviderFuncFixed(p), + }, + ), State: state, }) @@ -854,9 +890,11 @@ func TestContext2Apply_createBeforeDestroyUpdate(t *testing.T) { } ctx := testContext2(t, &ContextOpts{ Module: m, - Providers: map[string]ResourceProviderFactory{ - "aws": testProviderFuncFixed(p), - }, + ProviderResolver: ResourceProviderResolverFixed( + map[string]ResourceProviderFactory{ + "aws": testProviderFuncFixed(p), + }, + ), State: state, }) @@ -920,9 +958,11 @@ func TestContext2Apply_createBeforeDestroy_dependsNonCBD(t *testing.T) { } ctx := testContext2(t, &ContextOpts{ Module: m, - Providers: map[string]ResourceProviderFactory{ - "aws": testProviderFuncFixed(p), - }, + ProviderResolver: ResourceProviderResolverFixed( + map[string]ResourceProviderFactory{ + "aws": testProviderFuncFixed(p), + }, + ), State: state, }) @@ -987,9 +1027,11 @@ func TestContext2Apply_createBeforeDestroy_hook(t *testing.T) { ctx := testContext2(t, &ContextOpts{ Module: m, Hooks: []Hook{h}, - Providers: map[string]ResourceProviderFactory{ - "aws": testProviderFuncFixed(p), - }, + ProviderResolver: ResourceProviderResolverFixed( + map[string]ResourceProviderFactory{ + "aws": testProviderFuncFixed(p), + }, + ), State: state, }) @@ -1054,9 +1096,11 @@ func TestContext2Apply_createBeforeDestroy_deposedCount(t *testing.T) { ctx := testContext2(t, &ContextOpts{ Module: m, - Providers: map[string]ResourceProviderFactory{ - "aws": testProviderFuncFixed(p), - }, + ProviderResolver: ResourceProviderResolverFixed( + map[string]ResourceProviderFactory{ + "aws": testProviderFuncFixed(p), + }, + ), State: state, }) @@ -1115,9 +1159,11 @@ func TestContext2Apply_createBeforeDestroy_deposedOnly(t *testing.T) { ctx := testContext2(t, &ContextOpts{ Module: m, - Providers: map[string]ResourceProviderFactory{ - "aws": testProviderFuncFixed(p), - }, + ProviderResolver: ResourceProviderResolverFixed( + map[string]ResourceProviderFactory{ + "aws": testProviderFuncFixed(p), + }, + ), State: state, }) @@ -1163,9 +1209,11 @@ func TestContext2Apply_destroyComputed(t *testing.T) { } ctx := testContext2(t, &ContextOpts{ Module: m, - Providers: map[string]ResourceProviderFactory{ - "aws": testProviderFuncFixed(p), - }, + ProviderResolver: ResourceProviderResolverFixed( + map[string]ResourceProviderFactory{ + "aws": testProviderFuncFixed(p), + }, + ), State: state, Destroy: true, }) @@ -1233,9 +1281,11 @@ func testContext2Apply_destroyDependsOn(t *testing.T) { ctx := testContext2(t, &ContextOpts{ Module: m, - Providers: map[string]ResourceProviderFactory{ - "aws": testProviderFuncFixed(p), - }, + ProviderResolver: ResourceProviderResolverFixed( + map[string]ResourceProviderFactory{ + "aws": testProviderFuncFixed(p), + }, + ), State: state, Destroy: true, Parallelism: 1, // To check ordering @@ -1309,9 +1359,11 @@ func testContext2Apply_destroyDependsOnStateOnly(t *testing.T) { ctx := testContext2(t, &ContextOpts{ Module: m, - Providers: map[string]ResourceProviderFactory{ - "aws": testProviderFuncFixed(p), - }, + ProviderResolver: ResourceProviderResolverFixed( + map[string]ResourceProviderFactory{ + "aws": testProviderFuncFixed(p), + }, + ), State: state, Destroy: true, Parallelism: 1, // To check ordering @@ -1385,9 +1437,11 @@ func testContext2Apply_destroyDependsOnStateOnlyModule(t *testing.T) { ctx := testContext2(t, &ContextOpts{ Module: m, - Providers: map[string]ResourceProviderFactory{ - "aws": testProviderFuncFixed(p), - }, + ProviderResolver: ResourceProviderResolverFixed( + map[string]ResourceProviderFactory{ + "aws": testProviderFuncFixed(p), + }, + ), State: state, Destroy: true, Parallelism: 1, // To check ordering @@ -1416,9 +1470,11 @@ func TestContext2Apply_dataBasic(t *testing.T) { ctx := testContext2(t, &ContextOpts{ Module: m, - Providers: map[string]ResourceProviderFactory{ - "null": testProviderFuncFixed(p), - }, + ProviderResolver: ResourceProviderResolverFixed( + map[string]ResourceProviderFactory{ + "null": testProviderFuncFixed(p), + }, + ), }) if p, err := ctx.Plan(); err != nil { @@ -1450,7 +1506,7 @@ func TestContext2Apply_destroyData(t *testing.T) { Path: rootModulePath, Resources: map[string]*ResourceState{ "data.null_data_source.testing": &ResourceState{ - Type: "aws_instance", + Type: "null_data_source", Primary: &InstanceState{ ID: "-", Attributes: map[string]string{ @@ -1465,9 +1521,11 @@ func TestContext2Apply_destroyData(t *testing.T) { } ctx := testContext2(t, &ContextOpts{ Module: m, - Providers: map[string]ResourceProviderFactory{ - "null": testProviderFuncFixed(p), - }, + ProviderResolver: ResourceProviderResolverFixed( + map[string]ResourceProviderFactory{ + "null": testProviderFuncFixed(p), + }, + ), State: state, Destroy: true, }) @@ -1524,9 +1582,11 @@ func TestContext2Apply_destroySkipsCBD(t *testing.T) { } ctx := testContext2(t, &ContextOpts{ Module: m, - Providers: map[string]ResourceProviderFactory{ - "aws": testProviderFuncFixed(p), - }, + ProviderResolver: ResourceProviderResolverFixed( + map[string]ResourceProviderFactory{ + "aws": testProviderFuncFixed(p), + }, + ), State: state, Destroy: true, }) @@ -1564,9 +1624,11 @@ func TestContext2Apply_destroyModuleVarProviderConfig(t *testing.T) { } ctx := testContext2(t, &ContextOpts{ Module: m, - Providers: map[string]ResourceProviderFactory{ - "aws": testProviderFuncFixed(p), - }, + ProviderResolver: ResourceProviderResolverFixed( + map[string]ResourceProviderFactory{ + "aws": testProviderFuncFixed(p), + }, + ), State: state, Destroy: true, }) @@ -1654,10 +1716,10 @@ func getContextForApply_destroyCrossProviders( }, } ctx := testContext2(t, &ContextOpts{ - Module: m, - Providers: providers, - State: state, - Destroy: true, + Module: m, + ProviderResolver: ResourceProviderResolverFixed(providers), + State: state, + Destroy: true, }) return ctx @@ -1670,9 +1732,11 @@ func TestContext2Apply_minimal(t *testing.T) { p.DiffFn = testDiffFn ctx := testContext2(t, &ContextOpts{ Module: m, - Providers: map[string]ResourceProviderFactory{ - "aws": testProviderFuncFixed(p), - }, + ProviderResolver: ResourceProviderResolverFixed( + map[string]ResourceProviderFactory{ + "aws": testProviderFuncFixed(p), + }, + ), }) if _, err := ctx.Plan(); err != nil { @@ -1698,9 +1762,11 @@ func TestContext2Apply_badDiff(t *testing.T) { p.DiffFn = testDiffFn ctx := testContext2(t, &ContextOpts{ Module: m, - Providers: map[string]ResourceProviderFactory{ - "aws": testProviderFuncFixed(p), - }, + ProviderResolver: ResourceProviderResolverFixed( + map[string]ResourceProviderFactory{ + "aws": testProviderFuncFixed(p), + }, + ), }) if _, err := ctx.Plan(); err != nil { @@ -1727,9 +1793,11 @@ func TestContext2Apply_cancel(t *testing.T) { p := testProvider("aws") ctx := testContext2(t, &ContextOpts{ Module: m, - Providers: map[string]ResourceProviderFactory{ - "aws": testProviderFuncFixed(p), - }, + ProviderResolver: ResourceProviderResolverFixed( + map[string]ResourceProviderFactory{ + "aws": testProviderFuncFixed(p), + }, + ), }) p.ApplyFn = func(*InstanceInfo, *InstanceState, *InstanceDiff) (*InstanceState, error) { @@ -1804,9 +1872,11 @@ func TestContext2Apply_cancelBlock(t *testing.T) { p := testProvider("aws") ctx := testContext2(t, &ContextOpts{ Module: m, - Providers: map[string]ResourceProviderFactory{ - "aws": testProviderFuncFixed(p), - }, + ProviderResolver: ResourceProviderResolverFixed( + map[string]ResourceProviderFactory{ + "aws": testProviderFuncFixed(p), + }, + ), }) applyCh := make(chan struct{}) @@ -1885,9 +1955,11 @@ func TestContext2Apply_cancelProvisioner(t *testing.T) { pr := testProvisioner() ctx := testContext2(t, &ContextOpts{ Module: m, - Providers: map[string]ResourceProviderFactory{ - "aws": testProviderFuncFixed(p), - }, + ProviderResolver: ResourceProviderResolverFixed( + map[string]ResourceProviderFactory{ + "aws": testProviderFuncFixed(p), + }, + ), Provisioners: map[string]ResourceProvisionerFactory{ "shell": testProvisionerFuncFixed(pr), }, @@ -1947,9 +2019,11 @@ func TestContext2Apply_compute(t *testing.T) { p.DiffFn = testDiffFn ctx := testContext2(t, &ContextOpts{ Module: m, - Providers: map[string]ResourceProviderFactory{ - "aws": testProviderFuncFixed(p), - }, + ProviderResolver: ResourceProviderResolverFixed( + map[string]ResourceProviderFactory{ + "aws": testProviderFuncFixed(p), + }, + ), }) if _, err := ctx.Plan(); err != nil { @@ -2015,9 +2089,11 @@ func TestContext2Apply_countDecrease(t *testing.T) { } ctx := testContext2(t, &ContextOpts{ Module: m, - Providers: map[string]ResourceProviderFactory{ - "aws": testProviderFuncFixed(p), - }, + ProviderResolver: ResourceProviderResolverFixed( + map[string]ResourceProviderFactory{ + "aws": testProviderFuncFixed(p), + }, + ), State: s, }) @@ -2075,9 +2151,11 @@ func TestContext2Apply_countDecreaseToOneX(t *testing.T) { } ctx := testContext2(t, &ContextOpts{ Module: m, - Providers: map[string]ResourceProviderFactory{ - "aws": testProviderFuncFixed(p), - }, + ProviderResolver: ResourceProviderResolverFixed( + map[string]ResourceProviderFactory{ + "aws": testProviderFuncFixed(p), + }, + ), State: s, }) @@ -2137,9 +2215,11 @@ func TestContext2Apply_countDecreaseToOneCorrupted(t *testing.T) { } ctx := testContext2(t, &ContextOpts{ Module: m, - Providers: map[string]ResourceProviderFactory{ - "aws": testProviderFuncFixed(p), - }, + ProviderResolver: ResourceProviderResolverFixed( + map[string]ResourceProviderFactory{ + "aws": testProviderFuncFixed(p), + }, + ), State: s, }) @@ -2187,9 +2267,11 @@ func TestContext2Apply_countTainted(t *testing.T) { } ctx := testContext2(t, &ContextOpts{ Module: m, - Providers: map[string]ResourceProviderFactory{ - "aws": testProviderFuncFixed(p), - }, + ProviderResolver: ResourceProviderResolverFixed( + map[string]ResourceProviderFactory{ + "aws": testProviderFuncFixed(p), + }, + ), State: s, }) @@ -2216,9 +2298,11 @@ func TestContext2Apply_countVariable(t *testing.T) { p.DiffFn = testDiffFn ctx := testContext2(t, &ContextOpts{ Module: m, - Providers: map[string]ResourceProviderFactory{ - "aws": testProviderFuncFixed(p), - }, + ProviderResolver: ResourceProviderResolverFixed( + map[string]ResourceProviderFactory{ + "aws": testProviderFuncFixed(p), + }, + ), }) if _, err := ctx.Plan(); err != nil { @@ -2244,9 +2328,11 @@ func TestContext2Apply_countVariableRef(t *testing.T) { p.DiffFn = testDiffFn ctx := testContext2(t, &ContextOpts{ Module: m, - Providers: map[string]ResourceProviderFactory{ - "aws": testProviderFuncFixed(p), - }, + ProviderResolver: ResourceProviderResolverFixed( + map[string]ResourceProviderFactory{ + "aws": testProviderFuncFixed(p), + }, + ), }) if _, err := ctx.Plan(); err != nil { @@ -2272,9 +2358,11 @@ func TestContext2Apply_mapVariableOverride(t *testing.T) { p.DiffFn = testDiffFn ctx := testContext2(t, &ContextOpts{ Module: m, - Providers: map[string]ResourceProviderFactory{ - "aws": testProviderFuncFixed(p), - }, + ProviderResolver: ResourceProviderResolverFixed( + map[string]ResourceProviderFactory{ + "aws": testProviderFuncFixed(p), + }, + ), Variables: map[string]interface{}{ "images": []map[string]interface{}{ map[string]interface{}{ @@ -2316,9 +2404,11 @@ func TestContext2Apply_moduleBasic(t *testing.T) { p.DiffFn = testDiffFn ctx := testContext2(t, &ContextOpts{ Module: m, - Providers: map[string]ResourceProviderFactory{ - "aws": testProviderFuncFixed(p), - }, + ProviderResolver: ResourceProviderResolverFixed( + map[string]ResourceProviderFactory{ + "aws": testProviderFuncFixed(p), + }, + ), }) if _, err := ctx.Plan(); err != nil { @@ -2393,9 +2483,11 @@ func TestContext2Apply_moduleDestroyOrder(t *testing.T) { ctx := testContext2(t, &ContextOpts{ Module: m, - Providers: map[string]ResourceProviderFactory{ - "aws": testProviderFuncFixed(p), - }, + ProviderResolver: ResourceProviderResolverFixed( + map[string]ResourceProviderFactory{ + "aws": testProviderFuncFixed(p), + }, + ), State: state, Destroy: true, }) @@ -2443,9 +2535,11 @@ func TestContext2Apply_moduleInheritAlias(t *testing.T) { ctx := testContext2(t, &ContextOpts{ Module: m, - Providers: map[string]ResourceProviderFactory{ - "aws": testProviderFuncFixed(p), - }, + ProviderResolver: ResourceProviderResolverFixed( + map[string]ResourceProviderFactory{ + "aws": testProviderFuncFixed(p), + }, + ), }) if _, err := ctx.Plan(); err != nil { @@ -2508,9 +2602,11 @@ func TestContext2Apply_moduleOrphanInheritAlias(t *testing.T) { ctx := testContext2(t, &ContextOpts{ Module: m, State: state, - Providers: map[string]ResourceProviderFactory{ - "aws": testProviderFuncFixed(p), - }, + ProviderResolver: ResourceProviderResolverFixed( + map[string]ResourceProviderFactory{ + "aws": testProviderFuncFixed(p), + }, + ), }) if _, err := ctx.Plan(); err != nil { @@ -2566,9 +2662,11 @@ func TestContext2Apply_moduleOrphanProvider(t *testing.T) { ctx := testContext2(t, &ContextOpts{ Module: m, State: state, - Providers: map[string]ResourceProviderFactory{ - "aws": testProviderFuncFixed(p), - }, + ProviderResolver: ResourceProviderResolverFixed( + map[string]ResourceProviderFactory{ + "aws": testProviderFuncFixed(p), + }, + ), }) if _, err := ctx.Plan(); err != nil { @@ -2614,9 +2712,11 @@ func TestContext2Apply_moduleOrphanGrandchildProvider(t *testing.T) { ctx := testContext2(t, &ContextOpts{ Module: m, State: state, - Providers: map[string]ResourceProviderFactory{ - "aws": testProviderFuncFixed(p), - }, + ProviderResolver: ResourceProviderResolverFixed( + map[string]ResourceProviderFactory{ + "aws": testProviderFuncFixed(p), + }, + ), }) if _, err := ctx.Plan(); err != nil { @@ -2649,9 +2749,11 @@ func TestContext2Apply_moduleGrandchildProvider(t *testing.T) { ctx := testContext2(t, &ContextOpts{ Module: m, - Providers: map[string]ResourceProviderFactory{ - "aws": testProviderFuncFixed(p), - }, + ProviderResolver: ResourceProviderResolverFixed( + map[string]ResourceProviderFactory{ + "aws": testProviderFuncFixed(p), + }, + ), }) if _, err := ctx.Plan(); err != nil { @@ -2684,10 +2786,12 @@ func TestContext2Apply_moduleOnlyProvider(t *testing.T) { ctx := testContext2(t, &ContextOpts{ Module: m, - Providers: map[string]ResourceProviderFactory{ - "aws": testProviderFuncFixed(p), - "test": testProviderFuncFixed(pTest), - }, + ProviderResolver: ResourceProviderResolverFixed( + map[string]ResourceProviderFactory{ + "aws": testProviderFuncFixed(p), + "test": testProviderFuncFixed(pTest), + }, + ), }) if _, err := ctx.Plan(); err != nil { @@ -2713,9 +2817,11 @@ func TestContext2Apply_moduleProviderAlias(t *testing.T) { p.DiffFn = testDiffFn ctx := testContext2(t, &ContextOpts{ Module: m, - Providers: map[string]ResourceProviderFactory{ - "aws": testProviderFuncFixed(p), - }, + ProviderResolver: ResourceProviderResolverFixed( + map[string]ResourceProviderFactory{ + "aws": testProviderFuncFixed(p), + }, + ), }) if _, err := ctx.Plan(); err != nil { @@ -2741,9 +2847,11 @@ func TestContext2Apply_moduleProviderAliasTargets(t *testing.T) { p.DiffFn = testDiffFn ctx := testContext2(t, &ContextOpts{ Module: m, - Providers: map[string]ResourceProviderFactory{ - "aws": testProviderFuncFixed(p), - }, + ProviderResolver: ResourceProviderResolverFixed( + map[string]ResourceProviderFactory{ + "aws": testProviderFuncFixed(p), + }, + ), Targets: []string{"no.thing"}, }) @@ -2772,9 +2880,11 @@ func TestContext2Apply_moduleProviderCloseNested(t *testing.T) { p.DiffFn = testDiffFn ctx := testContext2(t, &ContextOpts{ Module: m, - Providers: map[string]ResourceProviderFactory{ - "aws": testProviderFuncFixed(p), - }, + ProviderResolver: ResourceProviderResolverFixed( + map[string]ResourceProviderFactory{ + "aws": testProviderFuncFixed(p), + }, + ), State: &State{ Modules: []*ModuleState{ &ModuleState{ @@ -2834,9 +2944,11 @@ func TestContext2Apply_moduleVarRefExisting(t *testing.T) { ctx := testContext2(t, &ContextOpts{ Module: m, - Providers: map[string]ResourceProviderFactory{ - "aws": testProviderFuncFixed(p), - }, + ProviderResolver: ResourceProviderResolverFixed( + map[string]ResourceProviderFactory{ + "aws": testProviderFuncFixed(p), + }, + ), State: state, }) @@ -2863,9 +2975,11 @@ func TestContext2Apply_moduleVarResourceCount(t *testing.T) { p.DiffFn = testDiffFn ctx := testContext2(t, &ContextOpts{ Module: m, - Providers: map[string]ResourceProviderFactory{ - "aws": testProviderFuncFixed(p), - }, + ProviderResolver: ResourceProviderResolverFixed( + map[string]ResourceProviderFactory{ + "aws": testProviderFuncFixed(p), + }, + ), Variables: map[string]interface{}{ "count": "2", }, @@ -2882,9 +2996,11 @@ func TestContext2Apply_moduleVarResourceCount(t *testing.T) { ctx = testContext2(t, &ContextOpts{ Module: m, - Providers: map[string]ResourceProviderFactory{ - "aws": testProviderFuncFixed(p), - }, + ProviderResolver: ResourceProviderResolverFixed( + map[string]ResourceProviderFactory{ + "aws": testProviderFuncFixed(p), + }, + ), Variables: map[string]interface{}{ "count": "5", }, @@ -2907,9 +3023,11 @@ func TestContext2Apply_moduleBool(t *testing.T) { p.DiffFn = testDiffFn ctx := testContext2(t, &ContextOpts{ Module: m, - Providers: map[string]ResourceProviderFactory{ - "aws": testProviderFuncFixed(p), - }, + ProviderResolver: ResourceProviderResolverFixed( + map[string]ResourceProviderFactory{ + "aws": testProviderFuncFixed(p), + }, + ), }) if _, err := ctx.Plan(); err != nil { @@ -2937,9 +3055,11 @@ func TestContext2Apply_moduleTarget(t *testing.T) { p.DiffFn = testDiffFn ctx := testContext2(t, &ContextOpts{ Module: m, - Providers: map[string]ResourceProviderFactory{ - "aws": testProviderFuncFixed(p), - }, + ProviderResolver: ResourceProviderResolverFixed( + map[string]ResourceProviderFactory{ + "aws": testProviderFuncFixed(p), + }, + ), Targets: []string{"module.B"}, }) @@ -2983,10 +3103,12 @@ func TestContext2Apply_multiProvider(t *testing.T) { ctx := testContext2(t, &ContextOpts{ Module: m, - Providers: map[string]ResourceProviderFactory{ - "aws": testProviderFuncFixed(p), - "do": testProviderFuncFixed(pDO), - }, + ProviderResolver: ResourceProviderResolverFixed( + map[string]ResourceProviderFactory{ + "aws": testProviderFuncFixed(p), + "do": testProviderFuncFixed(pDO), + }, + ), }) if _, err := ctx.Plan(); err != nil { @@ -3026,10 +3148,12 @@ func TestContext2Apply_multiProviderDestroy(t *testing.T) { { ctx := testContext2(t, &ContextOpts{ Module: m, - Providers: map[string]ResourceProviderFactory{ - "aws": testProviderFuncFixed(p), - "vault": testProviderFuncFixed(p2), - }, + ProviderResolver: ResourceProviderResolverFixed( + map[string]ResourceProviderFactory{ + "aws": testProviderFuncFixed(p), + "vault": testProviderFuncFixed(p2), + }, + ), }) if _, err := ctx.Plan(); err != nil { @@ -3081,10 +3205,12 @@ func TestContext2Apply_multiProviderDestroy(t *testing.T) { Destroy: true, State: state, Module: m, - Providers: map[string]ResourceProviderFactory{ - "aws": testProviderFuncFixed(p), - "vault": testProviderFuncFixed(p2), - }, + ProviderResolver: ResourceProviderResolverFixed( + map[string]ResourceProviderFactory{ + "aws": testProviderFuncFixed(p), + "vault": testProviderFuncFixed(p2), + }, + ), }) if _, err := ctx.Plan(); err != nil { @@ -3125,10 +3251,12 @@ func TestContext2Apply_multiProviderDestroyChild(t *testing.T) { { ctx := testContext2(t, &ContextOpts{ Module: m, - Providers: map[string]ResourceProviderFactory{ - "aws": testProviderFuncFixed(p), - "vault": testProviderFuncFixed(p2), - }, + ProviderResolver: ResourceProviderResolverFixed( + map[string]ResourceProviderFactory{ + "aws": testProviderFuncFixed(p), + "vault": testProviderFuncFixed(p2), + }, + ), }) if _, err := ctx.Plan(); err != nil { @@ -3180,10 +3308,12 @@ func TestContext2Apply_multiProviderDestroyChild(t *testing.T) { Destroy: true, State: state, Module: m, - Providers: map[string]ResourceProviderFactory{ - "aws": testProviderFuncFixed(p), - "vault": testProviderFuncFixed(p2), - }, + ProviderResolver: ResourceProviderResolverFixed( + map[string]ResourceProviderFactory{ + "aws": testProviderFuncFixed(p), + "vault": testProviderFuncFixed(p2), + }, + ), }) if _, err := ctx.Plan(); err != nil { @@ -3218,9 +3348,11 @@ func TestContext2Apply_multiVar(t *testing.T) { // First, apply with a count of 3 ctx := testContext2(t, &ContextOpts{ Module: m, - Providers: map[string]ResourceProviderFactory{ - "aws": testProviderFuncFixed(p), - }, + ProviderResolver: ResourceProviderResolverFixed( + map[string]ResourceProviderFactory{ + "aws": testProviderFuncFixed(p), + }, + ), Variables: map[string]interface{}{ "count": "3", }, @@ -3248,9 +3380,11 @@ func TestContext2Apply_multiVar(t *testing.T) { ctx := testContext2(t, &ContextOpts{ Module: m, State: state, - Providers: map[string]ResourceProviderFactory{ - "aws": testProviderFuncFixed(p), - }, + ProviderResolver: ResourceProviderResolverFixed( + map[string]ResourceProviderFactory{ + "aws": testProviderFuncFixed(p), + }, + ), Variables: map[string]interface{}{ "count": "1", }, @@ -3313,9 +3447,11 @@ func TestContext2Apply_multiVarComprehensive(t *testing.T) { // First, apply with a count of 3 ctx := testContext2(t, &ContextOpts{ Module: m, - Providers: map[string]ResourceProviderFactory{ - "test": testProviderFuncFixed(p), - }, + ProviderResolver: ResourceProviderResolverFixed( + map[string]ResourceProviderFactory{ + "test": testProviderFuncFixed(p), + }, + ), Variables: map[string]interface{}{ "count": "3", }, @@ -3438,9 +3574,11 @@ func TestContext2Apply_multiVarOrder(t *testing.T) { // First, apply with a count of 3 ctx := testContext2(t, &ContextOpts{ Module: m, - Providers: map[string]ResourceProviderFactory{ - "aws": testProviderFuncFixed(p), - }, + ProviderResolver: ResourceProviderResolverFixed( + map[string]ResourceProviderFactory{ + "aws": testProviderFuncFixed(p), + }, + ), }) if _, err := ctx.Plan(); err != nil { @@ -3472,9 +3610,11 @@ func TestContext2Apply_multiVarOrderInterp(t *testing.T) { // First, apply with a count of 3 ctx := testContext2(t, &ContextOpts{ Module: m, - Providers: map[string]ResourceProviderFactory{ - "aws": testProviderFuncFixed(p), - }, + ProviderResolver: ResourceProviderResolverFixed( + map[string]ResourceProviderFactory{ + "aws": testProviderFuncFixed(p), + }, + ), }) if _, err := ctx.Plan(); err != nil { @@ -3508,9 +3648,11 @@ func TestContext2Apply_multiVarCountDec(t *testing.T) { p.DiffFn = testDiffFn ctx := testContext2(t, &ContextOpts{ Module: m, - Providers: map[string]ResourceProviderFactory{ - "aws": testProviderFuncFixed(p), - }, + ProviderResolver: ResourceProviderResolverFixed( + map[string]ResourceProviderFactory{ + "aws": testProviderFuncFixed(p), + }, + ), Variables: map[string]interface{}{ "count": "2", }, @@ -3569,9 +3711,11 @@ func TestContext2Apply_multiVarCountDec(t *testing.T) { ctx := testContext2(t, &ContextOpts{ State: s, Module: m, - Providers: map[string]ResourceProviderFactory{ - "aws": testProviderFuncFixed(p), - }, + ProviderResolver: ResourceProviderResolverFixed( + map[string]ResourceProviderFactory{ + "aws": testProviderFuncFixed(p), + }, + ), Variables: map[string]interface{}{ "count": "1", }, @@ -3609,9 +3753,11 @@ func TestContext2Apply_multiVarMissingState(t *testing.T) { // First, apply with a count of 3 ctx := testContext2(t, &ContextOpts{ Module: m, - Providers: map[string]ResourceProviderFactory{ - "test": testProviderFuncFixed(p), - }, + ProviderResolver: ResourceProviderResolverFixed( + map[string]ResourceProviderFactory{ + "test": testProviderFuncFixed(p), + }, + ), }) if _, err := ctx.Plan(); err != nil { @@ -3633,9 +3779,11 @@ func TestContext2Apply_nilDiff(t *testing.T) { p.DiffFn = testDiffFn ctx := testContext2(t, &ContextOpts{ Module: m, - Providers: map[string]ResourceProviderFactory{ - "aws": testProviderFuncFixed(p), - }, + ProviderResolver: ResourceProviderResolverFixed( + map[string]ResourceProviderFactory{ + "aws": testProviderFuncFixed(p), + }, + ), }) if _, err := ctx.Plan(); err != nil { @@ -3674,9 +3822,11 @@ func TestContext2Apply_outputDependsOn(t *testing.T) { ctx := testContext2(t, &ContextOpts{ Module: m, - Providers: map[string]ResourceProviderFactory{ - "aws": testProviderFuncFixed(p), - }, + ProviderResolver: ResourceProviderResolverFixed( + map[string]ResourceProviderFactory{ + "aws": testProviderFuncFixed(p), + }, + ), }) if _, err := ctx.Plan(); err != nil { @@ -3697,9 +3847,11 @@ func TestContext2Apply_outputDependsOn(t *testing.T) { ctx := testContext2(t, &ContextOpts{ Module: m, - Providers: map[string]ResourceProviderFactory{ - "aws": testProviderFuncFixed(p), - }, + ProviderResolver: ResourceProviderResolverFixed( + map[string]ResourceProviderFactory{ + "aws": testProviderFuncFixed(p), + }, + ), }) if _, err := ctx.Plan(); err != nil { @@ -3750,9 +3902,11 @@ func TestContext2Apply_outputOrphan(t *testing.T) { ctx := testContext2(t, &ContextOpts{ Module: m, - Providers: map[string]ResourceProviderFactory{ - "aws": testProviderFuncFixed(p), - }, + ProviderResolver: ResourceProviderResolverFixed( + map[string]ResourceProviderFactory{ + "aws": testProviderFuncFixed(p), + }, + ), State: state, }) @@ -3798,9 +3952,11 @@ func TestContext2Apply_outputOrphanModule(t *testing.T) { ctx := testContext2(t, &ContextOpts{ Module: m, - Providers: map[string]ResourceProviderFactory{ - "aws": testProviderFuncFixed(p), - }, + ProviderResolver: ResourceProviderResolverFixed( + map[string]ResourceProviderFactory{ + "aws": testProviderFuncFixed(p), + }, + ), State: state, }) @@ -3832,10 +3988,12 @@ func TestContext2Apply_providerComputedVar(t *testing.T) { ctx := testContext2(t, &ContextOpts{ Module: m, - Providers: map[string]ResourceProviderFactory{ - "aws": testProviderFuncFixed(p), - "test": testProviderFuncFixed(pTest), - }, + ProviderResolver: ResourceProviderResolverFixed( + map[string]ResourceProviderFactory{ + "aws": testProviderFuncFixed(p), + "test": testProviderFuncFixed(pTest), + }, + ), }) p.ConfigureFn = func(c *ResourceConfig) error { @@ -3882,9 +4040,11 @@ func TestContext2Apply_providerConfigureDisabled(t *testing.T) { ctx := testContext2(t, &ContextOpts{ Module: m, - Providers: map[string]ResourceProviderFactory{ - "aws": testProviderFuncFixed(p), - }, + ProviderResolver: ResourceProviderResolverFixed( + map[string]ResourceProviderFactory{ + "aws": testProviderFuncFixed(p), + }, + ), }) if _, err := ctx.Plan(); err != nil { @@ -3908,9 +4068,11 @@ func TestContext2Apply_provisionerModule(t *testing.T) { p.DiffFn = testDiffFn ctx := testContext2(t, &ContextOpts{ Module: m, - Providers: map[string]ResourceProviderFactory{ - "aws": testProviderFuncFixed(p), - }, + ProviderResolver: ResourceProviderResolverFixed( + map[string]ResourceProviderFactory{ + "aws": testProviderFuncFixed(p), + }, + ), Provisioners: map[string]ResourceProvisionerFactory{ "shell": testProvisionerFuncFixed(pr), }, @@ -3953,9 +4115,11 @@ func TestContext2Apply_Provisioner_compute(t *testing.T) { } ctx := testContext2(t, &ContextOpts{ Module: m, - Providers: map[string]ResourceProviderFactory{ - "aws": testProviderFuncFixed(p), - }, + ProviderResolver: ResourceProviderResolverFixed( + map[string]ResourceProviderFactory{ + "aws": testProviderFuncFixed(p), + }, + ), Provisioners: map[string]ResourceProvisionerFactory{ "shell": testProvisionerFuncFixed(pr), }, @@ -4001,9 +4165,11 @@ func TestContext2Apply_provisionerCreateFail(t *testing.T) { ctx := testContext2(t, &ContextOpts{ Module: m, - Providers: map[string]ResourceProviderFactory{ - "aws": testProviderFuncFixed(p), - }, + ProviderResolver: ResourceProviderResolverFixed( + map[string]ResourceProviderFactory{ + "aws": testProviderFuncFixed(p), + }, + ), Provisioners: map[string]ResourceProvisionerFactory{ "shell": testProvisionerFuncFixed(pr), }, @@ -4040,9 +4206,11 @@ func TestContext2Apply_provisionerCreateFailNoId(t *testing.T) { ctx := testContext2(t, &ContextOpts{ Module: m, - Providers: map[string]ResourceProviderFactory{ - "aws": testProviderFuncFixed(p), - }, + ProviderResolver: ResourceProviderResolverFixed( + map[string]ResourceProviderFactory{ + "aws": testProviderFuncFixed(p), + }, + ), Provisioners: map[string]ResourceProvisionerFactory{ "shell": testProvisionerFuncFixed(pr), }, @@ -4077,9 +4245,11 @@ func TestContext2Apply_provisionerFail(t *testing.T) { ctx := testContext2(t, &ContextOpts{ Module: m, - Providers: map[string]ResourceProviderFactory{ - "aws": testProviderFuncFixed(p), - }, + ProviderResolver: ResourceProviderResolverFixed( + map[string]ResourceProviderFactory{ + "aws": testProviderFuncFixed(p), + }, + ), Provisioners: map[string]ResourceProvisionerFactory{ "shell": testProvisionerFuncFixed(pr), }, @@ -4134,9 +4304,11 @@ func TestContext2Apply_provisionerFail_createBeforeDestroy(t *testing.T) { } ctx := testContext2(t, &ContextOpts{ Module: m, - Providers: map[string]ResourceProviderFactory{ - "aws": testProviderFuncFixed(p), - }, + ProviderResolver: ResourceProviderResolverFixed( + map[string]ResourceProviderFactory{ + "aws": testProviderFuncFixed(p), + }, + ), Provisioners: map[string]ResourceProvisionerFactory{ "shell": testProvisionerFuncFixed(pr), }, @@ -4182,9 +4354,11 @@ func TestContext2Apply_error_createBeforeDestroy(t *testing.T) { } ctx := testContext2(t, &ContextOpts{ Module: m, - Providers: map[string]ResourceProviderFactory{ - "aws": testProviderFuncFixed(p), - }, + ProviderResolver: ResourceProviderResolverFixed( + map[string]ResourceProviderFactory{ + "aws": testProviderFuncFixed(p), + }, + ), State: state, }) p.ApplyFn = func(info *InstanceInfo, is *InstanceState, id *InstanceDiff) (*InstanceState, error) { @@ -4231,9 +4405,11 @@ func TestContext2Apply_errorDestroy_createBeforeDestroy(t *testing.T) { } ctx := testContext2(t, &ContextOpts{ Module: m, - Providers: map[string]ResourceProviderFactory{ - "aws": testProviderFuncFixed(p), - }, + ProviderResolver: ResourceProviderResolverFixed( + map[string]ResourceProviderFactory{ + "aws": testProviderFuncFixed(p), + }, + ), State: state, }) p.ApplyFn = func(info *InstanceInfo, is *InstanceState, id *InstanceDiff) (*InstanceState, error) { @@ -4286,9 +4462,9 @@ func TestContext2Apply_multiDepose_createBeforeDestroy(t *testing.T) { } ctx := testContext2(t, &ContextOpts{ - Module: m, - Providers: ps, - State: state, + Module: m, + ProviderResolver: ResourceProviderResolverFixed(ps), + State: state, }) createdInstanceId := "bar" // Create works @@ -4326,9 +4502,9 @@ aws_instance.web: (1 deposed) createdInstanceId = "baz" ctx = testContext2(t, &ContextOpts{ - Module: m, - Providers: ps, - State: state, + Module: m, + ProviderResolver: ResourceProviderResolverFixed(ps), + State: state, }) if _, err := ctx.Plan(); err != nil { @@ -4411,9 +4587,11 @@ func TestContext2Apply_provisionerFailContinue(t *testing.T) { ctx := testContext2(t, &ContextOpts{ Module: m, - Providers: map[string]ResourceProviderFactory{ - "aws": testProviderFuncFixed(p), - }, + ProviderResolver: ResourceProviderResolverFixed( + map[string]ResourceProviderFactory{ + "aws": testProviderFuncFixed(p), + }, + ), Provisioners: map[string]ResourceProvisionerFactory{ "shell": testProvisionerFuncFixed(pr), }, @@ -4457,9 +4635,11 @@ func TestContext2Apply_provisionerFailContinueHook(t *testing.T) { ctx := testContext2(t, &ContextOpts{ Module: m, Hooks: []Hook{h}, - Providers: map[string]ResourceProviderFactory{ - "aws": testProviderFuncFixed(p), - }, + ProviderResolver: ResourceProviderResolverFixed( + map[string]ResourceProviderFactory{ + "aws": testProviderFuncFixed(p), + }, + ), Provisioners: map[string]ResourceProvisionerFactory{ "shell": testProvisionerFuncFixed(pr), }, @@ -4516,9 +4696,11 @@ func TestContext2Apply_provisionerDestroy(t *testing.T) { Module: m, State: state, Destroy: true, - Providers: map[string]ResourceProviderFactory{ - "aws": testProviderFuncFixed(p), - }, + ProviderResolver: ResourceProviderResolverFixed( + map[string]ResourceProviderFactory{ + "aws": testProviderFuncFixed(p), + }, + ), Provisioners: map[string]ResourceProvisionerFactory{ "shell": testProvisionerFuncFixed(pr), }, @@ -4572,9 +4754,11 @@ func TestContext2Apply_provisionerDestroyFail(t *testing.T) { Module: m, State: state, Destroy: true, - Providers: map[string]ResourceProviderFactory{ - "aws": testProviderFuncFixed(p), - }, + ProviderResolver: ResourceProviderResolverFixed( + map[string]ResourceProviderFactory{ + "aws": testProviderFuncFixed(p), + }, + ), Provisioners: map[string]ResourceProvisionerFactory{ "shell": testProvisionerFuncFixed(pr), }, @@ -4643,9 +4827,11 @@ func TestContext2Apply_provisionerDestroyFailContinue(t *testing.T) { Module: m, State: state, Destroy: true, - Providers: map[string]ResourceProviderFactory{ - "aws": testProviderFuncFixed(p), - }, + ProviderResolver: ResourceProviderResolverFixed( + map[string]ResourceProviderFactory{ + "aws": testProviderFuncFixed(p), + }, + ), Provisioners: map[string]ResourceProvisionerFactory{ "shell": testProvisionerFuncFixed(pr), }, @@ -4717,9 +4903,11 @@ func TestContext2Apply_provisionerDestroyFailContinueFail(t *testing.T) { Module: m, State: state, Destroy: true, - Providers: map[string]ResourceProviderFactory{ - "aws": testProviderFuncFixed(p), - }, + ProviderResolver: ResourceProviderResolverFixed( + map[string]ResourceProviderFactory{ + "aws": testProviderFuncFixed(p), + }, + ), Provisioners: map[string]ResourceProvisionerFactory{ "shell": testProvisionerFuncFixed(pr), }, @@ -4794,9 +4982,11 @@ func TestContext2Apply_provisionerDestroyTainted(t *testing.T) { ctx := testContext2(t, &ContextOpts{ Module: m, State: state, - Providers: map[string]ResourceProviderFactory{ - "aws": testProviderFuncFixed(p), - }, + ProviderResolver: ResourceProviderResolverFixed( + map[string]ResourceProviderFactory{ + "aws": testProviderFuncFixed(p), + }, + ), Provisioners: map[string]ResourceProvisionerFactory{ "shell": testProvisionerFuncFixed(pr), }, @@ -4863,9 +5053,11 @@ func TestContext2Apply_provisionerDestroyModule(t *testing.T) { Module: m, State: state, Destroy: true, - Providers: map[string]ResourceProviderFactory{ - "aws": testProviderFuncFixed(p), - }, + ProviderResolver: ResourceProviderResolverFixed( + map[string]ResourceProviderFactory{ + "aws": testProviderFuncFixed(p), + }, + ), Provisioners: map[string]ResourceProvisionerFactory{ "shell": testProvisionerFuncFixed(pr), }, @@ -4935,9 +5127,11 @@ func TestContext2Apply_provisionerDestroyRef(t *testing.T) { Module: m, State: state, Destroy: true, - Providers: map[string]ResourceProviderFactory{ - "aws": testProviderFuncFixed(p), - }, + ProviderResolver: ResourceProviderResolverFixed( + map[string]ResourceProviderFactory{ + "aws": testProviderFuncFixed(p), + }, + ), Provisioners: map[string]ResourceProvisionerFactory{ "shell": testProvisionerFuncFixed(pr), }, @@ -4998,9 +5192,11 @@ func TestContext2Apply_provisionerDestroyRefInvalid(t *testing.T) { Module: m, State: state, Destroy: true, - Providers: map[string]ResourceProviderFactory{ - "aws": testProviderFuncFixed(p), - }, + ProviderResolver: ResourceProviderResolverFixed( + map[string]ResourceProviderFactory{ + "aws": testProviderFuncFixed(p), + }, + ), Provisioners: map[string]ResourceProvisionerFactory{ "shell": testProvisionerFuncFixed(pr), }, @@ -5032,9 +5228,11 @@ func TestContext2Apply_provisionerResourceRef(t *testing.T) { ctx := testContext2(t, &ContextOpts{ Module: m, - Providers: map[string]ResourceProviderFactory{ - "aws": testProviderFuncFixed(p), - }, + ProviderResolver: ResourceProviderResolverFixed( + map[string]ResourceProviderFactory{ + "aws": testProviderFuncFixed(p), + }, + ), Provisioners: map[string]ResourceProvisionerFactory{ "shell": testProvisionerFuncFixed(pr), }, @@ -5078,9 +5276,11 @@ func TestContext2Apply_provisionerSelfRef(t *testing.T) { ctx := testContext2(t, &ContextOpts{ Module: m, - Providers: map[string]ResourceProviderFactory{ - "aws": testProviderFuncFixed(p), - }, + ProviderResolver: ResourceProviderResolverFixed( + map[string]ResourceProviderFactory{ + "aws": testProviderFuncFixed(p), + }, + ), Provisioners: map[string]ResourceProvisionerFactory{ "shell": testProvisionerFuncFixed(pr), }, @@ -5131,9 +5331,11 @@ func TestContext2Apply_provisionerMultiSelfRef(t *testing.T) { ctx := testContext2(t, &ContextOpts{ Module: m, - Providers: map[string]ResourceProviderFactory{ - "aws": testProviderFuncFixed(p), - }, + ProviderResolver: ResourceProviderResolverFixed( + map[string]ResourceProviderFactory{ + "aws": testProviderFuncFixed(p), + }, + ), Provisioners: map[string]ResourceProvisionerFactory{ "shell": testProvisionerFuncFixed(pr), }, @@ -5191,9 +5393,11 @@ func TestContext2Apply_provisionerMultiSelfRefSingle(t *testing.T) { ctx := testContext2(t, &ContextOpts{ Module: m, - Providers: map[string]ResourceProviderFactory{ - "aws": testProviderFuncFixed(p), - }, + ProviderResolver: ResourceProviderResolverFixed( + map[string]ResourceProviderFactory{ + "aws": testProviderFuncFixed(p), + }, + ), Provisioners: map[string]ResourceProvisionerFactory{ "shell": testProvisionerFuncFixed(pr), }, @@ -5251,9 +5455,11 @@ func TestContext2Apply_provisionerMultiSelfRefCount(t *testing.T) { ctx := testContext2(t, &ContextOpts{ Module: m, - Providers: map[string]ResourceProviderFactory{ - "aws": testProviderFuncFixed(p), - }, + ProviderResolver: ResourceProviderResolverFixed( + map[string]ResourceProviderFactory{ + "aws": testProviderFuncFixed(p), + }, + ), Provisioners: map[string]ResourceProvisionerFactory{ "shell": testProvisionerFuncFixed(pr), }, @@ -5299,9 +5505,11 @@ func TestContext2Apply_provisionerExplicitSelfRef(t *testing.T) { { ctx := testContext2(t, &ContextOpts{ Module: m, - Providers: map[string]ResourceProviderFactory{ - "aws": testProviderFuncFixed(p), - }, + ProviderResolver: ResourceProviderResolverFixed( + map[string]ResourceProviderFactory{ + "aws": testProviderFuncFixed(p), + }, + ), Provisioners: map[string]ResourceProvisionerFactory{ "shell": testProvisionerFuncFixed(pr), }, @@ -5328,9 +5536,11 @@ func TestContext2Apply_provisionerExplicitSelfRef(t *testing.T) { Module: m, Destroy: true, State: state, - Providers: map[string]ResourceProviderFactory{ - "aws": testProviderFuncFixed(p), - }, + ProviderResolver: ResourceProviderResolverFixed( + map[string]ResourceProviderFactory{ + "aws": testProviderFuncFixed(p), + }, + ), Provisioners: map[string]ResourceProvisionerFactory{ "shell": testProvisionerFuncFixed(pr), }, @@ -5362,9 +5572,11 @@ func TestContext2Apply_Provisioner_Diff(t *testing.T) { } ctx := testContext2(t, &ContextOpts{ Module: m, - Providers: map[string]ResourceProviderFactory{ - "aws": testProviderFuncFixed(p), - }, + ProviderResolver: ResourceProviderResolverFixed( + map[string]ResourceProviderFactory{ + "aws": testProviderFuncFixed(p), + }, + ), Provisioners: map[string]ResourceProvisionerFactory{ "shell": testProvisionerFuncFixed(pr), }, @@ -5398,9 +5610,11 @@ func TestContext2Apply_Provisioner_Diff(t *testing.T) { // Re-create context with state ctx = testContext2(t, &ContextOpts{ Module: m, - Providers: map[string]ResourceProviderFactory{ - "aws": testProviderFuncFixed(p), - }, + ProviderResolver: ResourceProviderResolverFixed( + map[string]ResourceProviderFactory{ + "aws": testProviderFuncFixed(p), + }, + ), Provisioners: map[string]ResourceProvisionerFactory{ "shell": testProvisionerFuncFixed(pr), }, @@ -5447,9 +5661,11 @@ func TestContext2Apply_outputDiffVars(t *testing.T) { } ctx := testContext2(t, &ContextOpts{ Module: m, - Providers: map[string]ResourceProviderFactory{ - "aws": testProviderFuncFixed(p), - }, + ProviderResolver: ResourceProviderResolverFixed( + map[string]ResourceProviderFactory{ + "aws": testProviderFuncFixed(p), + }, + ), State: s, }) @@ -5529,9 +5745,11 @@ func TestContext2Apply_Provisioner_ConnInfo(t *testing.T) { ctx := testContext2(t, &ContextOpts{ Module: m, - Providers: map[string]ResourceProviderFactory{ - "aws": testProviderFuncFixed(p), - }, + ProviderResolver: ResourceProviderResolverFixed( + map[string]ResourceProviderFactory{ + "aws": testProviderFuncFixed(p), + }, + ), Provisioners: map[string]ResourceProvisionerFactory{ "shell": testProvisionerFuncFixed(pr), }, @@ -5571,9 +5789,11 @@ func TestContext2Apply_destroyX(t *testing.T) { ctx := testContext2(t, &ContextOpts{ Module: m, Hooks: []Hook{h}, - Providers: map[string]ResourceProviderFactory{ - "aws": testProviderFuncFixed(p), - }, + ProviderResolver: ResourceProviderResolverFixed( + map[string]ResourceProviderFactory{ + "aws": testProviderFuncFixed(p), + }, + ), }) // First plan and apply a create operation @@ -5593,9 +5813,11 @@ func TestContext2Apply_destroyX(t *testing.T) { State: state, Module: m, Hooks: []Hook{h}, - Providers: map[string]ResourceProviderFactory{ - "aws": testProviderFuncFixed(p), - }, + ProviderResolver: ResourceProviderResolverFixed( + map[string]ResourceProviderFactory{ + "aws": testProviderFuncFixed(p), + }, + ), }) if _, err := ctx.Plan(); err != nil { @@ -5631,9 +5853,11 @@ func TestContext2Apply_destroyOrder(t *testing.T) { ctx := testContext2(t, &ContextOpts{ Module: m, Hooks: []Hook{h}, - Providers: map[string]ResourceProviderFactory{ - "aws": testProviderFuncFixed(p), - }, + ProviderResolver: ResourceProviderResolverFixed( + map[string]ResourceProviderFactory{ + "aws": testProviderFuncFixed(p), + }, + ), }) // First plan and apply a create operation @@ -5654,9 +5878,11 @@ func TestContext2Apply_destroyOrder(t *testing.T) { State: state, Module: module.NewEmptyTree(), Hooks: []Hook{h}, - Providers: map[string]ResourceProviderFactory{ - "aws": testProviderFuncFixed(p), - }, + ProviderResolver: ResourceProviderResolverFixed( + map[string]ResourceProviderFactory{ + "aws": testProviderFuncFixed(p), + }, + ), }) if _, err := ctx.Plan(); err != nil { @@ -5693,9 +5919,11 @@ func TestContext2Apply_destroyModulePrefix(t *testing.T) { ctx := testContext2(t, &ContextOpts{ Module: m, Hooks: []Hook{h}, - Providers: map[string]ResourceProviderFactory{ - "aws": testProviderFuncFixed(p), - }, + ProviderResolver: ResourceProviderResolverFixed( + map[string]ResourceProviderFactory{ + "aws": testProviderFuncFixed(p), + }, + ), }) // First plan and apply a create operation @@ -5720,9 +5948,11 @@ func TestContext2Apply_destroyModulePrefix(t *testing.T) { State: state, Module: m, Hooks: []Hook{h}, - Providers: map[string]ResourceProviderFactory{ - "aws": testProviderFuncFixed(p), - }, + ProviderResolver: ResourceProviderResolverFixed( + map[string]ResourceProviderFactory{ + "aws": testProviderFuncFixed(p), + }, + ), }) if _, err := ctx.Plan(); err != nil { @@ -5764,9 +5994,11 @@ func TestContext2Apply_destroyNestedModule(t *testing.T) { ctx := testContext2(t, &ContextOpts{ Module: m, - Providers: map[string]ResourceProviderFactory{ - "aws": testProviderFuncFixed(p), - }, + ProviderResolver: ResourceProviderResolverFixed( + map[string]ResourceProviderFactory{ + "aws": testProviderFuncFixed(p), + }, + ), State: s, }) @@ -5812,9 +6044,11 @@ func TestContext2Apply_destroyDeeplyNestedModule(t *testing.T) { ctx := testContext2(t, &ContextOpts{ Module: m, - Providers: map[string]ResourceProviderFactory{ - "aws": testProviderFuncFixed(p), - }, + ProviderResolver: ResourceProviderResolverFixed( + map[string]ResourceProviderFactory{ + "aws": testProviderFuncFixed(p), + }, + ), State: s, }) @@ -5851,9 +6085,11 @@ func TestContext2Apply_destroyModuleWithAttrsReferencingResource(t *testing.T) { { ctx := testContext2(t, &ContextOpts{ Module: m, - Providers: map[string]ResourceProviderFactory{ - "aws": testProviderFuncFixed(p), - }, + ProviderResolver: ResourceProviderResolverFixed( + map[string]ResourceProviderFactory{ + "aws": testProviderFuncFixed(p), + }, + ), }) // First plan and apply a create operation @@ -5880,9 +6116,11 @@ func TestContext2Apply_destroyModuleWithAttrsReferencingResource(t *testing.T) { Module: m, State: state, Hooks: []Hook{h}, - Providers: map[string]ResourceProviderFactory{ - "aws": testProviderFuncFixed(p), - }, + ProviderResolver: ResourceProviderResolverFixed( + map[string]ResourceProviderFactory{ + "aws": testProviderFuncFixed(p), + }, + ), Variables: map[string]interface{}{ "key_name": "foobarkey", }, @@ -5907,9 +6145,11 @@ func TestContext2Apply_destroyModuleWithAttrsReferencingResource(t *testing.T) { } ctx, err = planFromFile.Context(&ContextOpts{ - Providers: map[string]ResourceProviderFactory{ - "aws": testProviderFuncFixed(p), - }, + ProviderResolver: ResourceProviderResolverFixed( + map[string]ResourceProviderFactory{ + "aws": testProviderFuncFixed(p), + }, + ), }) if err != nil { t.Fatalf("err: %s", err) @@ -5946,9 +6186,11 @@ func TestContext2Apply_destroyWithModuleVariableAndCount(t *testing.T) { { ctx := testContext2(t, &ContextOpts{ Module: m, - Providers: map[string]ResourceProviderFactory{ - "aws": testProviderFuncFixed(p), - }, + ProviderResolver: ResourceProviderResolverFixed( + map[string]ResourceProviderFactory{ + "aws": testProviderFuncFixed(p), + }, + ), }) // First plan and apply a create operation @@ -5971,9 +6213,11 @@ func TestContext2Apply_destroyWithModuleVariableAndCount(t *testing.T) { Module: m, State: state, Hooks: []Hook{h}, - Providers: map[string]ResourceProviderFactory{ - "aws": testProviderFuncFixed(p), - }, + ProviderResolver: ResourceProviderResolverFixed( + map[string]ResourceProviderFactory{ + "aws": testProviderFuncFixed(p), + }, + ), }) // First plan and apply a create operation @@ -5993,9 +6237,11 @@ func TestContext2Apply_destroyWithModuleVariableAndCount(t *testing.T) { } ctx, err = planFromFile.Context(&ContextOpts{ - Providers: map[string]ResourceProviderFactory{ - "aws": testProviderFuncFixed(p), - }, + ProviderResolver: ResourceProviderResolverFixed( + map[string]ResourceProviderFactory{ + "aws": testProviderFuncFixed(p), + }, + ), }) if err != nil { t.Fatalf("err: %s", err) @@ -6030,9 +6276,11 @@ func TestContext2Apply_destroyTargetWithModuleVariableAndCount(t *testing.T) { { ctx := testContext2(t, &ContextOpts{ Module: m, - Providers: map[string]ResourceProviderFactory{ - "aws": testProviderFuncFixed(p), - }, + ProviderResolver: ResourceProviderResolverFixed( + map[string]ResourceProviderFactory{ + "aws": testProviderFuncFixed(p), + }, + ), }) // First plan and apply a create operation @@ -6051,9 +6299,11 @@ func TestContext2Apply_destroyTargetWithModuleVariableAndCount(t *testing.T) { Destroy: true, Module: m, State: state, - Providers: map[string]ResourceProviderFactory{ - "aws": testProviderFuncFixed(p), - }, + ProviderResolver: ResourceProviderResolverFixed( + map[string]ResourceProviderFactory{ + "aws": testProviderFuncFixed(p), + }, + ), Targets: []string{"module.child"}, }) @@ -6092,9 +6342,11 @@ func TestContext2Apply_destroyWithModuleVariableAndCountNested(t *testing.T) { { ctx := testContext2(t, &ContextOpts{ Module: m, - Providers: map[string]ResourceProviderFactory{ - "aws": testProviderFuncFixed(p), - }, + ProviderResolver: ResourceProviderResolverFixed( + map[string]ResourceProviderFactory{ + "aws": testProviderFuncFixed(p), + }, + ), }) // First plan and apply a create operation @@ -6117,9 +6369,11 @@ func TestContext2Apply_destroyWithModuleVariableAndCountNested(t *testing.T) { Module: m, State: state, Hooks: []Hook{h}, - Providers: map[string]ResourceProviderFactory{ - "aws": testProviderFuncFixed(p), - }, + ProviderResolver: ResourceProviderResolverFixed( + map[string]ResourceProviderFactory{ + "aws": testProviderFuncFixed(p), + }, + ), }) // First plan and apply a create operation @@ -6139,9 +6393,11 @@ func TestContext2Apply_destroyWithModuleVariableAndCountNested(t *testing.T) { } ctx, err = planFromFile.Context(&ContextOpts{ - Providers: map[string]ResourceProviderFactory{ - "aws": testProviderFuncFixed(p), - }, + ProviderResolver: ResourceProviderResolverFixed( + map[string]ResourceProviderFactory{ + "aws": testProviderFuncFixed(p), + }, + ), }) if err != nil { t.Fatalf("err: %s", err) @@ -6176,9 +6432,11 @@ func TestContext2Apply_destroyOutputs(t *testing.T) { ctx := testContext2(t, &ContextOpts{ Module: m, Hooks: []Hook{h}, - Providers: map[string]ResourceProviderFactory{ - "aws": testProviderFuncFixed(p), - }, + ProviderResolver: ResourceProviderResolverFixed( + map[string]ResourceProviderFactory{ + "aws": testProviderFuncFixed(p), + }, + ), }) // First plan and apply a create operation @@ -6199,9 +6457,11 @@ func TestContext2Apply_destroyOutputs(t *testing.T) { State: state, Module: m, Hooks: []Hook{h}, - Providers: map[string]ResourceProviderFactory{ - "aws": testProviderFuncFixed(p), - }, + ProviderResolver: ResourceProviderResolverFixed( + map[string]ResourceProviderFactory{ + "aws": testProviderFuncFixed(p), + }, + ), }) if _, err := ctx.Plan(); err != nil { @@ -6239,9 +6499,11 @@ func TestContext2Apply_destroyOrphan(t *testing.T) { } ctx := testContext2(t, &ContextOpts{ Module: m, - Providers: map[string]ResourceProviderFactory{ - "aws": testProviderFuncFixed(p), - }, + ProviderResolver: ResourceProviderResolverFixed( + map[string]ResourceProviderFactory{ + "aws": testProviderFuncFixed(p), + }, + ), State: s, }) @@ -6314,9 +6576,11 @@ func TestContext2Apply_destroyTaintedProvisioner(t *testing.T) { ctx := testContext2(t, &ContextOpts{ Module: m, - Providers: map[string]ResourceProviderFactory{ - "aws": testProviderFuncFixed(p), - }, + ProviderResolver: ResourceProviderResolverFixed( + map[string]ResourceProviderFactory{ + "aws": testProviderFuncFixed(p), + }, + ), Provisioners: map[string]ResourceProvisionerFactory{ "shell": testProvisionerFuncFixed(pr), }, @@ -6351,9 +6615,11 @@ func TestContext2Apply_error(t *testing.T) { p := testProvider("aws") ctx := testContext2(t, &ContextOpts{ Module: m, - Providers: map[string]ResourceProviderFactory{ - "aws": testProviderFuncFixed(p), - }, + ProviderResolver: ResourceProviderResolverFixed( + map[string]ResourceProviderFactory{ + "aws": testProviderFuncFixed(p), + }, + ), }) p.ApplyFn = func(*InstanceInfo, *InstanceState, *InstanceDiff) (*InstanceState, error) { @@ -6420,9 +6686,11 @@ func TestContext2Apply_errorPartial(t *testing.T) { } ctx := testContext2(t, &ContextOpts{ Module: m, - Providers: map[string]ResourceProviderFactory{ - "aws": testProviderFuncFixed(p), - }, + ProviderResolver: ResourceProviderResolverFixed( + map[string]ResourceProviderFactory{ + "aws": testProviderFuncFixed(p), + }, + ), State: s, }) @@ -6479,9 +6747,11 @@ func TestContext2Apply_hook(t *testing.T) { ctx := testContext2(t, &ContextOpts{ Module: m, Hooks: []Hook{h}, - Providers: map[string]ResourceProviderFactory{ - "aws": testProviderFuncFixed(p), - }, + ProviderResolver: ResourceProviderResolverFixed( + map[string]ResourceProviderFactory{ + "aws": testProviderFuncFixed(p), + }, + ), }) if _, err := ctx.Plan(); err != nil { @@ -6530,9 +6800,11 @@ func TestContext2Apply_hookOrphan(t *testing.T) { Module: m, State: state, Hooks: []Hook{h}, - Providers: map[string]ResourceProviderFactory{ - "aws": testProviderFuncFixed(p), - }, + ProviderResolver: ResourceProviderResolverFixed( + map[string]ResourceProviderFactory{ + "aws": testProviderFuncFixed(p), + }, + ), }) if _, err := ctx.Plan(); err != nil { @@ -6559,9 +6831,11 @@ func TestContext2Apply_idAttr(t *testing.T) { p := testProvider("aws") ctx := testContext2(t, &ContextOpts{ Module: m, - Providers: map[string]ResourceProviderFactory{ - "aws": testProviderFuncFixed(p), - }, + ProviderResolver: ResourceProviderResolverFixed( + map[string]ResourceProviderFactory{ + "aws": testProviderFuncFixed(p), + }, + ), }) p.ApplyFn = func(info *InstanceInfo, s *InstanceState, d *InstanceDiff) (*InstanceState, error) { @@ -6612,9 +6886,11 @@ func TestContext2Apply_outputBasic(t *testing.T) { p.DiffFn = testDiffFn ctx := testContext2(t, &ContextOpts{ Module: m, - Providers: map[string]ResourceProviderFactory{ - "aws": testProviderFuncFixed(p), - }, + ProviderResolver: ResourceProviderResolverFixed( + map[string]ResourceProviderFactory{ + "aws": testProviderFuncFixed(p), + }, + ), }) if _, err := ctx.Plan(); err != nil { @@ -6640,9 +6916,11 @@ func TestContext2Apply_outputInvalid(t *testing.T) { p.DiffFn = testDiffFn ctx := testContext2(t, &ContextOpts{ Module: m, - Providers: map[string]ResourceProviderFactory{ - "aws": testProviderFuncFixed(p), - }, + ProviderResolver: ResourceProviderResolverFixed( + map[string]ResourceProviderFactory{ + "aws": testProviderFuncFixed(p), + }, + ), }) _, err := ctx.Plan() @@ -6661,9 +6939,11 @@ func TestContext2Apply_outputAdd(t *testing.T) { p1.DiffFn = testDiffFn ctx1 := testContext2(t, &ContextOpts{ Module: m1, - Providers: map[string]ResourceProviderFactory{ - "aws": testProviderFuncFixed(p1), - }, + ProviderResolver: ResourceProviderResolverFixed( + map[string]ResourceProviderFactory{ + "aws": testProviderFuncFixed(p1), + }, + ), }) if _, err := ctx1.Plan(); err != nil { @@ -6681,9 +6961,11 @@ func TestContext2Apply_outputAdd(t *testing.T) { p2.DiffFn = testDiffFn ctx2 := testContext2(t, &ContextOpts{ Module: m2, - Providers: map[string]ResourceProviderFactory{ - "aws": testProviderFuncFixed(p2), - }, + ProviderResolver: ResourceProviderResolverFixed( + map[string]ResourceProviderFactory{ + "aws": testProviderFuncFixed(p2), + }, + ), State: state1, }) @@ -6710,9 +6992,11 @@ func TestContext2Apply_outputList(t *testing.T) { p.DiffFn = testDiffFn ctx := testContext2(t, &ContextOpts{ Module: m, - Providers: map[string]ResourceProviderFactory{ - "aws": testProviderFuncFixed(p), - }, + ProviderResolver: ResourceProviderResolverFixed( + map[string]ResourceProviderFactory{ + "aws": testProviderFuncFixed(p), + }, + ), }) if _, err := ctx.Plan(); err != nil { @@ -6738,9 +7022,11 @@ func TestContext2Apply_outputMulti(t *testing.T) { p.DiffFn = testDiffFn ctx := testContext2(t, &ContextOpts{ Module: m, - Providers: map[string]ResourceProviderFactory{ - "aws": testProviderFuncFixed(p), - }, + ProviderResolver: ResourceProviderResolverFixed( + map[string]ResourceProviderFactory{ + "aws": testProviderFuncFixed(p), + }, + ), }) if _, err := ctx.Plan(); err != nil { @@ -6766,9 +7052,11 @@ func TestContext2Apply_outputMultiIndex(t *testing.T) { p.DiffFn = testDiffFn ctx := testContext2(t, &ContextOpts{ Module: m, - Providers: map[string]ResourceProviderFactory{ - "aws": testProviderFuncFixed(p), - }, + ProviderResolver: ResourceProviderResolverFixed( + map[string]ResourceProviderFactory{ + "aws": testProviderFuncFixed(p), + }, + ), }) if _, err := ctx.Plan(); err != nil { @@ -6829,9 +7117,11 @@ func TestContext2Apply_taintX(t *testing.T) { } ctx := testContext2(t, &ContextOpts{ Module: m, - Providers: map[string]ResourceProviderFactory{ - "aws": testProviderFuncFixed(p), - }, + ProviderResolver: ResourceProviderResolverFixed( + map[string]ResourceProviderFactory{ + "aws": testProviderFuncFixed(p), + }, + ), State: s, }) @@ -6895,9 +7185,11 @@ func TestContext2Apply_taintDep(t *testing.T) { } ctx := testContext2(t, &ContextOpts{ Module: m, - Providers: map[string]ResourceProviderFactory{ - "aws": testProviderFuncFixed(p), - }, + ProviderResolver: ResourceProviderResolverFixed( + map[string]ResourceProviderFactory{ + "aws": testProviderFuncFixed(p), + }, + ), State: s, }) @@ -6957,9 +7249,11 @@ func TestContext2Apply_taintDepRequiresNew(t *testing.T) { } ctx := testContext2(t, &ContextOpts{ Module: m, - Providers: map[string]ResourceProviderFactory{ - "aws": testProviderFuncFixed(p), - }, + ProviderResolver: ResourceProviderResolverFixed( + map[string]ResourceProviderFactory{ + "aws": testProviderFuncFixed(p), + }, + ), State: s, }) @@ -6988,9 +7282,11 @@ func TestContext2Apply_targeted(t *testing.T) { p.DiffFn = testDiffFn ctx := testContext2(t, &ContextOpts{ Module: m, - Providers: map[string]ResourceProviderFactory{ - "aws": testProviderFuncFixed(p), - }, + ProviderResolver: ResourceProviderResolverFixed( + map[string]ResourceProviderFactory{ + "aws": testProviderFuncFixed(p), + }, + ), Targets: []string{"aws_instance.foo"}, }) @@ -7023,9 +7319,11 @@ func TestContext2Apply_targetedCount(t *testing.T) { p.DiffFn = testDiffFn ctx := testContext2(t, &ContextOpts{ Module: m, - Providers: map[string]ResourceProviderFactory{ - "aws": testProviderFuncFixed(p), - }, + ProviderResolver: ResourceProviderResolverFixed( + map[string]ResourceProviderFactory{ + "aws": testProviderFuncFixed(p), + }, + ), Targets: []string{"aws_instance.foo"}, }) @@ -7055,9 +7353,11 @@ func TestContext2Apply_targetedCountIndex(t *testing.T) { p.DiffFn = testDiffFn ctx := testContext2(t, &ContextOpts{ Module: m, - Providers: map[string]ResourceProviderFactory{ - "aws": testProviderFuncFixed(p), - }, + ProviderResolver: ResourceProviderResolverFixed( + map[string]ResourceProviderFactory{ + "aws": testProviderFuncFixed(p), + }, + ), Targets: []string{"aws_instance.foo[1]"}, }) @@ -7083,9 +7383,11 @@ func TestContext2Apply_targetedDestroy(t *testing.T) { p.DiffFn = testDiffFn ctx := testContext2(t, &ContextOpts{ Module: m, - Providers: map[string]ResourceProviderFactory{ - "aws": testProviderFuncFixed(p), - }, + ProviderResolver: ResourceProviderResolverFixed( + map[string]ResourceProviderFactory{ + "aws": testProviderFuncFixed(p), + }, + ), State: &State{ Modules: []*ModuleState{ &ModuleState{ @@ -7128,9 +7430,11 @@ func TestContext2Apply_targetedDestroyCountDeps(t *testing.T) { p.DiffFn = testDiffFn ctx := testContext2(t, &ContextOpts{ Module: m, - Providers: map[string]ResourceProviderFactory{ - "aws": testProviderFuncFixed(p), - }, + ProviderResolver: ResourceProviderResolverFixed( + map[string]ResourceProviderFactory{ + "aws": testProviderFuncFixed(p), + }, + ), State: &State{ Modules: []*ModuleState{ &ModuleState{ @@ -7166,9 +7470,11 @@ func TestContext2Apply_targetedDestroyModule(t *testing.T) { p.DiffFn = testDiffFn ctx := testContext2(t, &ContextOpts{ Module: m, - Providers: map[string]ResourceProviderFactory{ - "aws": testProviderFuncFixed(p), - }, + ProviderResolver: ResourceProviderResolverFixed( + map[string]ResourceProviderFactory{ + "aws": testProviderFuncFixed(p), + }, + ), State: &State{ Modules: []*ModuleState{ &ModuleState{ @@ -7219,9 +7525,11 @@ func TestContext2Apply_targetedDestroyCountIndex(t *testing.T) { p.DiffFn = testDiffFn ctx := testContext2(t, &ContextOpts{ Module: m, - Providers: map[string]ResourceProviderFactory{ - "aws": testProviderFuncFixed(p), - }, + ProviderResolver: ResourceProviderResolverFixed( + map[string]ResourceProviderFactory{ + "aws": testProviderFuncFixed(p), + }, + ), State: &State{ Modules: []*ModuleState{ &ModuleState{ @@ -7272,9 +7580,11 @@ func TestContext2Apply_targetedModule(t *testing.T) { p.DiffFn = testDiffFn ctx := testContext2(t, &ContextOpts{ Module: m, - Providers: map[string]ResourceProviderFactory{ - "aws": testProviderFuncFixed(p), - }, + ProviderResolver: ResourceProviderResolverFixed( + map[string]ResourceProviderFactory{ + "aws": testProviderFuncFixed(p), + }, + ), Targets: []string{"module.child"}, }) @@ -7317,9 +7627,11 @@ func TestContext2Apply_targetedModuleDep(t *testing.T) { p.DiffFn = testDiffFn ctx := testContext2(t, &ContextOpts{ Module: m, - Providers: map[string]ResourceProviderFactory{ - "aws": testProviderFuncFixed(p), - }, + ProviderResolver: ResourceProviderResolverFixed( + map[string]ResourceProviderFactory{ + "aws": testProviderFuncFixed(p), + }, + ), Targets: []string{"aws_instance.foo"}, }) @@ -7362,9 +7674,11 @@ func TestContext2Apply_targetedModuleUnrelatedOutputs(t *testing.T) { p.DiffFn = testDiffFn ctx := testContext2(t, &ContextOpts{ Module: m, - Providers: map[string]ResourceProviderFactory{ - "aws": testProviderFuncFixed(p), - }, + ProviderResolver: ResourceProviderResolverFixed( + map[string]ResourceProviderFactory{ + "aws": testProviderFuncFixed(p), + }, + ), Targets: []string{"module.child2"}, State: &State{ Modules: []*ModuleState{ @@ -7432,9 +7746,11 @@ func TestContext2Apply_targetedModuleResource(t *testing.T) { p.DiffFn = testDiffFn ctx := testContext2(t, &ContextOpts{ Module: m, - Providers: map[string]ResourceProviderFactory{ - "aws": testProviderFuncFixed(p), - }, + ProviderResolver: ResourceProviderResolverFixed( + map[string]ResourceProviderFactory{ + "aws": testProviderFuncFixed(p), + }, + ), Targets: []string{"module.child.aws_instance.foo"}, }) @@ -7469,9 +7785,11 @@ func TestContext2Apply_unknownAttribute(t *testing.T) { p.DiffFn = testDiffFn ctx := testContext2(t, &ContextOpts{ Module: m, - Providers: map[string]ResourceProviderFactory{ - "aws": testProviderFuncFixed(p), - }, + ProviderResolver: ResourceProviderResolverFixed( + map[string]ResourceProviderFactory{ + "aws": testProviderFuncFixed(p), + }, + ), }) if _, err := ctx.Plan(); err != nil { @@ -7497,9 +7815,11 @@ func TestContext2Apply_unknownAttributeInterpolate(t *testing.T) { p.DiffFn = testDiffFn ctx := testContext2(t, &ContextOpts{ Module: m, - Providers: map[string]ResourceProviderFactory{ - "aws": testProviderFuncFixed(p), - }, + ProviderResolver: ResourceProviderResolverFixed( + map[string]ResourceProviderFactory{ + "aws": testProviderFuncFixed(p), + }, + ), }) if _, err := ctx.Plan(); err == nil { @@ -7514,9 +7834,11 @@ func TestContext2Apply_vars(t *testing.T) { p.DiffFn = testDiffFn ctx := testContext2(t, &ContextOpts{ Module: m, - Providers: map[string]ResourceProviderFactory{ - "aws": testProviderFuncFixed(p), - }, + ProviderResolver: ResourceProviderResolverFixed( + map[string]ResourceProviderFactory{ + "aws": testProviderFuncFixed(p), + }, + ), Variables: map[string]interface{}{ "foo": "us-west-2", "test_list": []interface{}{"Hello", "World"}, @@ -7569,9 +7891,11 @@ func TestContext2Apply_varsEnv(t *testing.T) { p.DiffFn = testDiffFn ctx := testContext2(t, &ContextOpts{ Module: m, - Providers: map[string]ResourceProviderFactory{ - "aws": testProviderFuncFixed(p), - }, + ProviderResolver: ResourceProviderResolverFixed( + map[string]ResourceProviderFactory{ + "aws": testProviderFuncFixed(p), + }, + ), }) w, e := ctx.Validate() @@ -7634,9 +7958,11 @@ func TestContext2Apply_createBefore_depends(t *testing.T) { ctx := testContext2(t, &ContextOpts{ Module: m, Hooks: []Hook{h}, - Providers: map[string]ResourceProviderFactory{ - "aws": testProviderFuncFixed(p), - }, + ProviderResolver: ResourceProviderResolverFixed( + map[string]ResourceProviderFactory{ + "aws": testProviderFuncFixed(p), + }, + ), State: state, }) @@ -7745,9 +8071,11 @@ func TestContext2Apply_singleDestroy(t *testing.T) { ctx := testContext2(t, &ContextOpts{ Module: m, Hooks: []Hook{h}, - Providers: map[string]ResourceProviderFactory{ - "aws": testProviderFuncFixed(p), - }, + ProviderResolver: ResourceProviderResolverFixed( + map[string]ResourceProviderFactory{ + "aws": testProviderFuncFixed(p), + }, + ), State: state, }) @@ -7779,9 +8107,11 @@ func TestContext2Apply_issue7824(t *testing.T) { // Apply cleanly step 0 ctx := testContext2(t, &ContextOpts{ Module: testModule(t, "issue-7824"), - Providers: map[string]ResourceProviderFactory{ - "template": testProviderFuncFixed(p), - }, + ProviderResolver: ResourceProviderResolverFixed( + map[string]ResourceProviderFactory{ + "template": testProviderFuncFixed(p), + }, + ), }) plan, err := ctx.Plan() @@ -7801,9 +8131,11 @@ func TestContext2Apply_issue7824(t *testing.T) { } ctx, err = planFromFile.Context(&ContextOpts{ - Providers: map[string]ResourceProviderFactory{ - "template": testProviderFuncFixed(p), - }, + ProviderResolver: ResourceProviderResolverFixed( + map[string]ResourceProviderFactory{ + "template": testProviderFuncFixed(p), + }, + ), }) if err != nil { t.Fatalf("err: %s", err) @@ -7830,9 +8162,11 @@ func TestContext2Apply_issue5254(t *testing.T) { // Apply cleanly step 0 ctx := testContext2(t, &ContextOpts{ Module: testModule(t, "issue-5254/step-0"), - Providers: map[string]ResourceProviderFactory{ - "template": testProviderFuncFixed(p), - }, + ProviderResolver: ResourceProviderResolverFixed( + map[string]ResourceProviderFactory{ + "template": testProviderFuncFixed(p), + }, + ), }) plan, err := ctx.Plan() @@ -7849,9 +8183,11 @@ func TestContext2Apply_issue5254(t *testing.T) { ctx = testContext2(t, &ContextOpts{ Module: testModule(t, "issue-5254/step-1"), State: state, - Providers: map[string]ResourceProviderFactory{ - "template": testProviderFuncFixed(p), - }, + ProviderResolver: ResourceProviderResolverFixed( + map[string]ResourceProviderFactory{ + "template": testProviderFuncFixed(p), + }, + ), }) plan, err = ctx.Plan() @@ -7871,9 +8207,11 @@ func TestContext2Apply_issue5254(t *testing.T) { } ctx, err = planFromFile.Context(&ContextOpts{ - Providers: map[string]ResourceProviderFactory{ - "template": testProviderFuncFixed(p), - }, + ProviderResolver: ResourceProviderResolverFixed( + map[string]ResourceProviderFactory{ + "template": testProviderFuncFixed(p), + }, + ), }) if err != nil { t.Fatalf("err: %s", err) @@ -7909,9 +8247,11 @@ func TestContext2Apply_targetedWithTaintedInState(t *testing.T) { p.ApplyFn = testApplyFn ctx := testContext2(t, &ContextOpts{ Module: testModule(t, "apply-tainted-targets"), - Providers: map[string]ResourceProviderFactory{ - "aws": testProviderFuncFixed(p), - }, + ProviderResolver: ResourceProviderResolverFixed( + map[string]ResourceProviderFactory{ + "aws": testProviderFuncFixed(p), + }, + ), Targets: []string{"aws_instance.iambeingadded"}, State: &State{ Modules: []*ModuleState{ @@ -7949,9 +8289,11 @@ func TestContext2Apply_targetedWithTaintedInState(t *testing.T) { ctx, err = planFromFile.Context(&ContextOpts{ Module: testModule(t, "apply-tainted-targets"), - Providers: map[string]ResourceProviderFactory{ - "aws": testProviderFuncFixed(p), - }, + ProviderResolver: ResourceProviderResolverFixed( + map[string]ResourceProviderFactory{ + "aws": testProviderFuncFixed(p), + }, + ), }) if err != nil { t.Fatalf("err: %s", err) @@ -7983,9 +8325,11 @@ func TestContext2Apply_ignoreChangesCreate(t *testing.T) { p.DiffFn = testDiffFn ctx := testContext2(t, &ContextOpts{ Module: m, - Providers: map[string]ResourceProviderFactory{ - "aws": testProviderFuncFixed(p), - }, + ProviderResolver: ResourceProviderResolverFixed( + map[string]ResourceProviderFactory{ + "aws": testProviderFuncFixed(p), + }, + ), }) if p, err := ctx.Plan(); err != nil { @@ -8092,9 +8436,11 @@ func TestContext2Apply_ignoreChangesWithDep(t *testing.T) { } ctx := testContext2(t, &ContextOpts{ Module: m, - Providers: map[string]ResourceProviderFactory{ - "aws": testProviderFuncFixed(p), - }, + ProviderResolver: ResourceProviderResolverFixed( + map[string]ResourceProviderFactory{ + "aws": testProviderFuncFixed(p), + }, + ), State: s, }) @@ -8123,9 +8469,11 @@ func TestContext2Apply_ignoreChangesWildcard(t *testing.T) { p.DiffFn = testDiffFn ctx := testContext2(t, &ContextOpts{ Module: m, - Providers: map[string]ResourceProviderFactory{ - "aws": testProviderFuncFixed(p), - }, + ProviderResolver: ResourceProviderResolverFixed( + map[string]ResourceProviderFactory{ + "aws": testProviderFuncFixed(p), + }, + ), }) if p, err := ctx.Plan(); err != nil { @@ -8169,9 +8517,11 @@ func TestContext2Apply_destroyNestedModuleWithAttrsReferencingResource(t *testin { ctx := testContext2(t, &ContextOpts{ Module: m, - Providers: map[string]ResourceProviderFactory{ - "null": testProviderFuncFixed(p), - }, + ProviderResolver: ResourceProviderResolverFixed( + map[string]ResourceProviderFactory{ + "null": testProviderFuncFixed(p), + }, + ), }) // First plan and apply a create operation @@ -8190,9 +8540,11 @@ func TestContext2Apply_destroyNestedModuleWithAttrsReferencingResource(t *testin Destroy: true, Module: m, State: state, - Providers: map[string]ResourceProviderFactory{ - "null": testProviderFuncFixed(p), - }, + ProviderResolver: ResourceProviderResolverFixed( + map[string]ResourceProviderFactory{ + "null": testProviderFuncFixed(p), + }, + ), }) plan, err := ctx.Plan() @@ -8211,9 +8563,11 @@ func TestContext2Apply_destroyNestedModuleWithAttrsReferencingResource(t *testin } ctx, err = planFromFile.Context(&ContextOpts{ - Providers: map[string]ResourceProviderFactory{ - "null": testProviderFuncFixed(p), - }, + ProviderResolver: ResourceProviderResolverFixed( + map[string]ResourceProviderFactory{ + "null": testProviderFuncFixed(p), + }, + ), }) if err != nil { t.Fatalf("err: %s", err) @@ -8247,9 +8601,11 @@ func TestContext2Apply_dataDependsOn(t *testing.T) { ctx := testContext2(t, &ContextOpts{ Module: m, - Providers: map[string]ResourceProviderFactory{ - "null": testProviderFuncFixed(p), - }, + ProviderResolver: ResourceProviderResolverFixed( + map[string]ResourceProviderFactory{ + "null": testProviderFuncFixed(p), + }, + ), }) // the "provisioner" here writes to this variable, because the intent is to @@ -8310,9 +8666,11 @@ func TestContext2Apply_terraformEnv(t *testing.T) { ctx := testContext2(t, &ContextOpts{ Meta: &ContextMeta{Env: "foo"}, Module: m, - Providers: map[string]ResourceProviderFactory{ - "aws": testProviderFuncFixed(p), - }, + ProviderResolver: ResourceProviderResolverFixed( + map[string]ResourceProviderFactory{ + "aws": testProviderFuncFixed(p), + }, + ), }) if _, err := ctx.Plan(); err != nil { @@ -8340,9 +8698,11 @@ func TestContext2Apply_multiRef(t *testing.T) { ctx := testContext2(t, &ContextOpts{ Module: m, - Providers: map[string]ResourceProviderFactory{ - "aws": testProviderFuncFixed(p), - }, + ProviderResolver: ResourceProviderResolverFixed( + map[string]ResourceProviderFactory{ + "aws": testProviderFuncFixed(p), + }, + ), }) if _, err := ctx.Plan(); err != nil { diff --git a/terraform/context_import_test.go b/terraform/context_import_test.go index 3d87622ad..ed05b947b 100644 --- a/terraform/context_import_test.go +++ b/terraform/context_import_test.go @@ -9,9 +9,11 @@ import ( func TestContextImport_basic(t *testing.T) { p := testProvider("aws") ctx := testContext2(t, &ContextOpts{ - Providers: map[string]ResourceProviderFactory{ - "aws": testProviderFuncFixed(p), - }, + ProviderResolver: ResourceProviderResolverFixed( + map[string]ResourceProviderFactory{ + "aws": testProviderFuncFixed(p), + }, + ), }) p.ImportStateReturn = []*InstanceState{ @@ -42,9 +44,11 @@ func TestContextImport_basic(t *testing.T) { func TestContextImport_countIndex(t *testing.T) { p := testProvider("aws") ctx := testContext2(t, &ContextOpts{ - Providers: map[string]ResourceProviderFactory{ - "aws": testProviderFuncFixed(p), - }, + ProviderResolver: ResourceProviderResolverFixed( + map[string]ResourceProviderFactory{ + "aws": testProviderFuncFixed(p), + }, + ), }) p.ImportStateReturn = []*InstanceState{ @@ -76,9 +80,11 @@ func TestContextImport_countIndex(t *testing.T) { func TestContextImport_collision(t *testing.T) { p := testProvider("aws") ctx := testContext2(t, &ContextOpts{ - Providers: map[string]ResourceProviderFactory{ - "aws": testProviderFuncFixed(p), - }, + ProviderResolver: ResourceProviderResolverFixed( + map[string]ResourceProviderFactory{ + "aws": testProviderFuncFixed(p), + }, + ), State: &State{ Modules: []*ModuleState{ @@ -126,9 +132,11 @@ func TestContextImport_collision(t *testing.T) { func TestContextImport_missingType(t *testing.T) { p := testProvider("aws") ctx := testContext2(t, &ContextOpts{ - Providers: map[string]ResourceProviderFactory{ - "aws": testProviderFuncFixed(p), - }, + ProviderResolver: ResourceProviderResolverFixed( + map[string]ResourceProviderFactory{ + "aws": testProviderFuncFixed(p), + }, + ), }) p.ImportStateReturn = []*InstanceState{ @@ -159,9 +167,11 @@ func TestContextImport_missingType(t *testing.T) { func TestContextImport_moduleProvider(t *testing.T) { p := testProvider("aws") ctx := testContext2(t, &ContextOpts{ - Providers: map[string]ResourceProviderFactory{ - "aws": testProviderFuncFixed(p), - }, + ProviderResolver: ResourceProviderResolverFixed( + map[string]ResourceProviderFactory{ + "aws": testProviderFuncFixed(p), + }, + ), }) p.ImportStateReturn = []*InstanceState{ @@ -212,9 +222,11 @@ func TestContextImport_moduleProvider(t *testing.T) { func TestContextImport_providerInherit(t *testing.T) { p := testProvider("aws") ctx := testContext2(t, &ContextOpts{ - Providers: map[string]ResourceProviderFactory{ - "aws": testProviderFuncFixed(p), - }, + ProviderResolver: ResourceProviderResolverFixed( + map[string]ResourceProviderFactory{ + "aws": testProviderFuncFixed(p), + }, + ), }) p.ImportStateReturn = []*InstanceState{ @@ -261,9 +273,11 @@ func TestContextImport_providerVarConfig(t *testing.T) { p := testProvider("aws") ctx := testContext2(t, &ContextOpts{ Module: testModule(t, "import-provider-vars"), - Providers: map[string]ResourceProviderFactory{ - "aws": testProviderFuncFixed(p), - }, + ProviderResolver: ResourceProviderResolverFixed( + map[string]ResourceProviderFactory{ + "aws": testProviderFuncFixed(p), + }, + ), Variables: map[string]interface{}{ "foo": "bar", }, @@ -315,9 +329,11 @@ func TestContextImport_providerNonVarConfig(t *testing.T) { p := testProvider("aws") ctx := testContext2(t, &ContextOpts{ Module: testModule(t, "import-provider-non-vars"), - Providers: map[string]ResourceProviderFactory{ - "aws": testProviderFuncFixed(p), - }, + ProviderResolver: ResourceProviderResolverFixed( + map[string]ResourceProviderFactory{ + "aws": testProviderFuncFixed(p), + }, + ), }) p.ImportStateReturn = []*InstanceState{ @@ -343,9 +359,11 @@ func TestContextImport_providerNonVarConfig(t *testing.T) { func TestContextImport_refresh(t *testing.T) { p := testProvider("aws") ctx := testContext2(t, &ContextOpts{ - Providers: map[string]ResourceProviderFactory{ - "aws": testProviderFuncFixed(p), - }, + ProviderResolver: ResourceProviderResolverFixed( + map[string]ResourceProviderFactory{ + "aws": testProviderFuncFixed(p), + }, + ), }) p.ImportStateReturn = []*InstanceState{ @@ -384,9 +402,11 @@ func TestContextImport_refresh(t *testing.T) { func TestContextImport_refreshNil(t *testing.T) { p := testProvider("aws") ctx := testContext2(t, &ContextOpts{ - Providers: map[string]ResourceProviderFactory{ - "aws": testProviderFuncFixed(p), - }, + ProviderResolver: ResourceProviderResolverFixed( + map[string]ResourceProviderFactory{ + "aws": testProviderFuncFixed(p), + }, + ), }) p.ImportStateReturn = []*InstanceState{ @@ -422,9 +442,11 @@ func TestContextImport_refreshNil(t *testing.T) { func TestContextImport_module(t *testing.T) { p := testProvider("aws") ctx := testContext2(t, &ContextOpts{ - Providers: map[string]ResourceProviderFactory{ - "aws": testProviderFuncFixed(p), - }, + ProviderResolver: ResourceProviderResolverFixed( + map[string]ResourceProviderFactory{ + "aws": testProviderFuncFixed(p), + }, + ), }) p.ImportStateReturn = []*InstanceState{ @@ -456,9 +478,11 @@ func TestContextImport_module(t *testing.T) { func TestContextImport_moduleDepth2(t *testing.T) { p := testProvider("aws") ctx := testContext2(t, &ContextOpts{ - Providers: map[string]ResourceProviderFactory{ - "aws": testProviderFuncFixed(p), - }, + ProviderResolver: ResourceProviderResolverFixed( + map[string]ResourceProviderFactory{ + "aws": testProviderFuncFixed(p), + }, + ), }) p.ImportStateReturn = []*InstanceState{ @@ -490,9 +514,11 @@ func TestContextImport_moduleDepth2(t *testing.T) { func TestContextImport_moduleDiff(t *testing.T) { p := testProvider("aws") ctx := testContext2(t, &ContextOpts{ - Providers: map[string]ResourceProviderFactory{ - "aws": testProviderFuncFixed(p), - }, + ProviderResolver: ResourceProviderResolverFixed( + map[string]ResourceProviderFactory{ + "aws": testProviderFuncFixed(p), + }, + ), State: &State{ Modules: []*ModuleState{ @@ -540,9 +566,11 @@ func TestContextImport_moduleDiff(t *testing.T) { func TestContextImport_moduleExisting(t *testing.T) { p := testProvider("aws") ctx := testContext2(t, &ContextOpts{ - Providers: map[string]ResourceProviderFactory{ - "aws": testProviderFuncFixed(p), - }, + ProviderResolver: ResourceProviderResolverFixed( + map[string]ResourceProviderFactory{ + "aws": testProviderFuncFixed(p), + }, + ), State: &State{ Modules: []*ModuleState{ @@ -590,9 +618,11 @@ func TestContextImport_moduleExisting(t *testing.T) { func TestContextImport_multiState(t *testing.T) { p := testProvider("aws") ctx := testContext2(t, &ContextOpts{ - Providers: map[string]ResourceProviderFactory{ - "aws": testProviderFuncFixed(p), - }, + ProviderResolver: ResourceProviderResolverFixed( + map[string]ResourceProviderFactory{ + "aws": testProviderFuncFixed(p), + }, + ), }) p.ImportStateReturn = []*InstanceState{ @@ -628,9 +658,11 @@ func TestContextImport_multiState(t *testing.T) { func TestContextImport_multiStateSame(t *testing.T) { p := testProvider("aws") ctx := testContext2(t, &ContextOpts{ - Providers: map[string]ResourceProviderFactory{ - "aws": testProviderFuncFixed(p), - }, + ProviderResolver: ResourceProviderResolverFixed( + map[string]ResourceProviderFactory{ + "aws": testProviderFuncFixed(p), + }, + ), }) p.ImportStateReturn = []*InstanceState{ @@ -670,9 +702,11 @@ func TestContextImport_multiStateSame(t *testing.T) { func TestContextImport_customProvider(t *testing.T) { p := testProvider("aws") ctx := testContext2(t, &ContextOpts{ - Providers: map[string]ResourceProviderFactory{ - "aws": testProviderFuncFixed(p), - }, + ProviderResolver: ResourceProviderResolverFixed( + map[string]ResourceProviderFactory{ + "aws": testProviderFuncFixed(p), + }, + ), }) p.ImportStateReturn = []*InstanceState{ diff --git a/terraform/context_input_test.go b/terraform/context_input_test.go index 5e3434bd8..928c11477 100644 --- a/terraform/context_input_test.go +++ b/terraform/context_input_test.go @@ -15,9 +15,11 @@ func TestContext2Input(t *testing.T) { p.DiffFn = testDiffFn ctx := testContext2(t, &ContextOpts{ Module: m, - Providers: map[string]ResourceProviderFactory{ - "aws": testProviderFuncFixed(p), - }, + ProviderResolver: ResourceProviderResolverFixed( + map[string]ResourceProviderFactory{ + "aws": testProviderFuncFixed(p), + }, + ), Variables: map[string]interface{}{ "foo": "us-west-2", "amis": []map[string]interface{}{ @@ -60,9 +62,11 @@ func TestContext2Input_moduleComputedOutputElement(t *testing.T) { p.DiffFn = testDiffFn ctx := testContext2(t, &ContextOpts{ Module: m, - Providers: map[string]ResourceProviderFactory{ - "aws": testProviderFuncFixed(p), - }, + ProviderResolver: ResourceProviderResolverFixed( + map[string]ResourceProviderFactory{ + "aws": testProviderFuncFixed(p), + }, + ), }) p.InputFn = func(i UIInput, c *ResourceConfig) (*ResourceConfig, error) { @@ -81,9 +85,11 @@ func TestContext2Input_badVarDefault(t *testing.T) { p.DiffFn = testDiffFn ctx := testContext2(t, &ContextOpts{ Module: m, - Providers: map[string]ResourceProviderFactory{ - "aws": testProviderFuncFixed(p), - }, + ProviderResolver: ResourceProviderResolverFixed( + map[string]ResourceProviderFactory{ + "aws": testProviderFuncFixed(p), + }, + ), }) p.InputFn = func(i UIInput, c *ResourceConfig) (*ResourceConfig, error) { @@ -103,9 +109,11 @@ func TestContext2Input_provider(t *testing.T) { p.DiffFn = testDiffFn ctx := testContext2(t, &ContextOpts{ Module: m, - Providers: map[string]ResourceProviderFactory{ - "aws": testProviderFuncFixed(p), - }, + ProviderResolver: ResourceProviderResolverFixed( + map[string]ResourceProviderFactory{ + "aws": testProviderFuncFixed(p), + }, + ), }) var actual interface{} @@ -145,9 +153,11 @@ func TestContext2Input_providerMulti(t *testing.T) { p.DiffFn = testDiffFn ctx := testContext2(t, &ContextOpts{ Module: m, - Providers: map[string]ResourceProviderFactory{ - "aws": testProviderFuncFixed(p), - }, + ProviderResolver: ResourceProviderResolverFixed( + map[string]ResourceProviderFactory{ + "aws": testProviderFuncFixed(p), + }, + ), }) var actual []interface{} @@ -191,9 +201,11 @@ func TestContext2Input_providerOnce(t *testing.T) { p.DiffFn = testDiffFn ctx := testContext2(t, &ContextOpts{ Module: m, - Providers: map[string]ResourceProviderFactory{ - "aws": testProviderFuncFixed(p), - }, + ProviderResolver: ResourceProviderResolverFixed( + map[string]ResourceProviderFactory{ + "aws": testProviderFuncFixed(p), + }, + ), }) count := 0 @@ -219,9 +231,11 @@ func TestContext2Input_providerId(t *testing.T) { p.DiffFn = testDiffFn ctx := testContext2(t, &ContextOpts{ Module: m, - Providers: map[string]ResourceProviderFactory{ - "aws": testProviderFuncFixed(p), - }, + ProviderResolver: ResourceProviderResolverFixed( + map[string]ResourceProviderFactory{ + "aws": testProviderFuncFixed(p), + }, + ), UIInput: input, }) @@ -269,9 +283,11 @@ func TestContext2Input_providerOnly(t *testing.T) { p.DiffFn = testDiffFn ctx := testContext2(t, &ContextOpts{ Module: m, - Providers: map[string]ResourceProviderFactory{ - "aws": testProviderFuncFixed(p), - }, + ProviderResolver: ResourceProviderResolverFixed( + map[string]ResourceProviderFactory{ + "aws": testProviderFuncFixed(p), + }, + ), Variables: map[string]interface{}{ "foo": "us-west-2", }, @@ -324,9 +340,11 @@ func TestContext2Input_providerVars(t *testing.T) { p.DiffFn = testDiffFn ctx := testContext2(t, &ContextOpts{ Module: m, - Providers: map[string]ResourceProviderFactory{ - "aws": testProviderFuncFixed(p), - }, + ProviderResolver: ResourceProviderResolverFixed( + map[string]ResourceProviderFactory{ + "aws": testProviderFuncFixed(p), + }, + ), Variables: map[string]interface{}{ "foo": "bar", }, @@ -372,9 +390,11 @@ func TestContext2Input_providerVarsModuleInherit(t *testing.T) { p.DiffFn = testDiffFn ctx := testContext2(t, &ContextOpts{ Module: m, - Providers: map[string]ResourceProviderFactory{ - "aws": testProviderFuncFixed(p), - }, + ProviderResolver: ResourceProviderResolverFixed( + map[string]ResourceProviderFactory{ + "aws": testProviderFuncFixed(p), + }, + ), UIInput: input, }) @@ -401,9 +421,11 @@ func TestContext2Input_varOnly(t *testing.T) { p.DiffFn = testDiffFn ctx := testContext2(t, &ContextOpts{ Module: m, - Providers: map[string]ResourceProviderFactory{ - "aws": testProviderFuncFixed(p), - }, + ProviderResolver: ResourceProviderResolverFixed( + map[string]ResourceProviderFactory{ + "aws": testProviderFuncFixed(p), + }, + ), Variables: map[string]interface{}{ "foo": "us-west-2", }, @@ -456,9 +478,11 @@ func TestContext2Input_varOnlyUnset(t *testing.T) { p.DiffFn = testDiffFn ctx := testContext2(t, &ContextOpts{ Module: m, - Providers: map[string]ResourceProviderFactory{ - "aws": testProviderFuncFixed(p), - }, + ProviderResolver: ResourceProviderResolverFixed( + map[string]ResourceProviderFactory{ + "aws": testProviderFuncFixed(p), + }, + ), Variables: map[string]interface{}{ "foo": "foovalue", }, @@ -498,9 +522,11 @@ func TestContext2Input_varWithDefault(t *testing.T) { p.DiffFn = testDiffFn ctx := testContext2(t, &ContextOpts{ Module: m, - Providers: map[string]ResourceProviderFactory{ - "aws": testProviderFuncFixed(p), - }, + ProviderResolver: ResourceProviderResolverFixed( + map[string]ResourceProviderFactory{ + "aws": testProviderFuncFixed(p), + }, + ), Variables: map[string]interface{}{}, UIInput: input, }) @@ -544,9 +570,11 @@ func TestContext2Input_varPartiallyComputed(t *testing.T) { p.DiffFn = testDiffFn ctx := testContext2(t, &ContextOpts{ Module: m, - Providers: map[string]ResourceProviderFactory{ - "aws": testProviderFuncFixed(p), - }, + ProviderResolver: ResourceProviderResolverFixed( + map[string]ResourceProviderFactory{ + "aws": testProviderFuncFixed(p), + }, + ), Variables: map[string]interface{}{ "foo": "foovalue", }, @@ -607,9 +635,11 @@ func TestContext2Input_interpolateVar(t *testing.T) { ctx := testContext2(t, &ContextOpts{ Module: m, - Providers: map[string]ResourceProviderFactory{ - "template": testProviderFuncFixed(p), - }, + ProviderResolver: ResourceProviderResolverFixed( + map[string]ResourceProviderFactory{ + "template": testProviderFuncFixed(p), + }, + ), UIInput: input, }) @@ -626,9 +656,11 @@ func TestContext2Input_hcl(t *testing.T) { p.DiffFn = testDiffFn ctx := testContext2(t, &ContextOpts{ Module: m, - Providers: map[string]ResourceProviderFactory{ - "hcl": testProviderFuncFixed(p), - }, + ProviderResolver: ResourceProviderResolverFixed( + map[string]ResourceProviderFactory{ + "hcl": testProviderFuncFixed(p), + }, + ), Variables: map[string]interface{}{}, UIInput: input, }) @@ -668,9 +700,11 @@ func TestContext2Input_submoduleTriggersInvalidCount(t *testing.T) { p.DiffFn = testDiffFn ctx := testContext2(t, &ContextOpts{ Module: m, - Providers: map[string]ResourceProviderFactory{ - "aws": testProviderFuncFixed(p), - }, + ProviderResolver: ResourceProviderResolverFixed( + map[string]ResourceProviderFactory{ + "aws": testProviderFuncFixed(p), + }, + ), UIInput: input, }) diff --git a/terraform/context_plan_test.go b/terraform/context_plan_test.go index 69ab38516..7c231063f 100644 --- a/terraform/context_plan_test.go +++ b/terraform/context_plan_test.go @@ -17,9 +17,11 @@ func TestContext2Plan_basic(t *testing.T) { p.DiffFn = testDiffFn ctx := testContext2(t, &ContextOpts{ Module: m, - Providers: map[string]ResourceProviderFactory{ - "aws": testProviderFuncFixed(p), - }, + ProviderResolver: ResourceProviderResolverFixed( + map[string]ResourceProviderFactory{ + "aws": testProviderFuncFixed(p), + }, + ), }) plan, err := ctx.Plan() @@ -64,9 +66,11 @@ func TestContext2Plan_createBefore_deposed(t *testing.T) { ctx := testContext2(t, &ContextOpts{ Module: m, - Providers: map[string]ResourceProviderFactory{ - "aws": testProviderFuncFixed(p), - }, + ProviderResolver: ResourceProviderResolverFixed( + map[string]ResourceProviderFactory{ + "aws": testProviderFuncFixed(p), + }, + ), State: s, }) @@ -98,9 +102,11 @@ func TestContext2Plan_createBefore_maintainRoot(t *testing.T) { p.DiffFn = testDiffFn ctx := testContext2(t, &ContextOpts{ Module: m, - Providers: map[string]ResourceProviderFactory{ - "aws": testProviderFuncFixed(p), - }, + ProviderResolver: ResourceProviderResolverFixed( + map[string]ResourceProviderFactory{ + "aws": testProviderFuncFixed(p), + }, + ), Variables: map[string]interface{}{ "in": "a,b,c", }, @@ -141,9 +147,11 @@ func TestContext2Plan_emptyDiff(t *testing.T) { ctx := testContext2(t, &ContextOpts{ Module: m, - Providers: map[string]ResourceProviderFactory{ - "aws": testProviderFuncFixed(p), - }, + ProviderResolver: ResourceProviderResolverFixed( + map[string]ResourceProviderFactory{ + "aws": testProviderFuncFixed(p), + }, + ), }) plan, err := ctx.Plan() @@ -164,9 +172,11 @@ func TestContext2Plan_escapedVar(t *testing.T) { p.DiffFn = testDiffFn ctx := testContext2(t, &ContextOpts{ Module: m, - Providers: map[string]ResourceProviderFactory{ - "aws": testProviderFuncFixed(p), - }, + ProviderResolver: ResourceProviderResolverFixed( + map[string]ResourceProviderFactory{ + "aws": testProviderFuncFixed(p), + }, + ), }) plan, err := ctx.Plan() @@ -187,9 +197,11 @@ func TestContext2Plan_minimal(t *testing.T) { p.DiffFn = testDiffFn ctx := testContext2(t, &ContextOpts{ Module: m, - Providers: map[string]ResourceProviderFactory{ - "aws": testProviderFuncFixed(p), - }, + ProviderResolver: ResourceProviderResolverFixed( + map[string]ResourceProviderFactory{ + "aws": testProviderFuncFixed(p), + }, + ), }) plan, err := ctx.Plan() @@ -210,9 +222,11 @@ func TestContext2Plan_modules(t *testing.T) { p.DiffFn = testDiffFn ctx := testContext2(t, &ContextOpts{ Module: m, - Providers: map[string]ResourceProviderFactory{ - "aws": testProviderFuncFixed(p), - }, + ProviderResolver: ResourceProviderResolverFixed( + map[string]ResourceProviderFactory{ + "aws": testProviderFuncFixed(p), + }, + ), }) plan, err := ctx.Plan() @@ -234,9 +248,11 @@ func TestContext2Plan_moduleCycle(t *testing.T) { p.DiffFn = testDiffFn ctx := testContext2(t, &ContextOpts{ Module: m, - Providers: map[string]ResourceProviderFactory{ - "aws": testProviderFuncFixed(p), - }, + ProviderResolver: ResourceProviderResolverFixed( + map[string]ResourceProviderFactory{ + "aws": testProviderFuncFixed(p), + }, + ), }) plan, err := ctx.Plan() @@ -259,9 +275,11 @@ func TestContext2Plan_moduleDeadlock(t *testing.T) { ctx := testContext2(t, &ContextOpts{ Module: m, - Providers: map[string]ResourceProviderFactory{ - "aws": testProviderFuncFixed(p), - }, + ProviderResolver: ResourceProviderResolverFixed( + map[string]ResourceProviderFactory{ + "aws": testProviderFuncFixed(p), + }, + ), }) plan, err := ctx.Plan() @@ -294,9 +312,11 @@ func TestContext2Plan_moduleInput(t *testing.T) { p.DiffFn = testDiffFn ctx := testContext2(t, &ContextOpts{ Module: m, - Providers: map[string]ResourceProviderFactory{ - "aws": testProviderFuncFixed(p), - }, + ProviderResolver: ResourceProviderResolverFixed( + map[string]ResourceProviderFactory{ + "aws": testProviderFuncFixed(p), + }, + ), }) plan, err := ctx.Plan() @@ -317,9 +337,11 @@ func TestContext2Plan_moduleInputComputed(t *testing.T) { p.DiffFn = testDiffFn ctx := testContext2(t, &ContextOpts{ Module: m, - Providers: map[string]ResourceProviderFactory{ - "aws": testProviderFuncFixed(p), - }, + ProviderResolver: ResourceProviderResolverFixed( + map[string]ResourceProviderFactory{ + "aws": testProviderFuncFixed(p), + }, + ), }) plan, err := ctx.Plan() @@ -340,9 +362,11 @@ func TestContext2Plan_moduleInputFromVar(t *testing.T) { p.DiffFn = testDiffFn ctx := testContext2(t, &ContextOpts{ Module: m, - Providers: map[string]ResourceProviderFactory{ - "aws": testProviderFuncFixed(p), - }, + ProviderResolver: ResourceProviderResolverFixed( + map[string]ResourceProviderFactory{ + "aws": testProviderFuncFixed(p), + }, + ), Variables: map[string]interface{}{ "foo": "52", }, @@ -366,9 +390,11 @@ func TestContext2Plan_moduleMultiVar(t *testing.T) { p.DiffFn = testDiffFn ctx := testContext2(t, &ContextOpts{ Module: m, - Providers: map[string]ResourceProviderFactory{ - "aws": testProviderFuncFixed(p), - }, + ProviderResolver: ResourceProviderResolverFixed( + map[string]ResourceProviderFactory{ + "aws": testProviderFuncFixed(p), + }, + ), }) plan, err := ctx.Plan() @@ -404,9 +430,11 @@ func TestContext2Plan_moduleOrphans(t *testing.T) { } ctx := testContext2(t, &ContextOpts{ Module: m, - Providers: map[string]ResourceProviderFactory{ - "aws": testProviderFuncFixed(p), - }, + ProviderResolver: ResourceProviderResolverFixed( + map[string]ResourceProviderFactory{ + "aws": testProviderFuncFixed(p), + }, + ), State: s, }) @@ -467,9 +495,11 @@ func TestContext2Plan_moduleOrphansWithProvisioner(t *testing.T) { } ctx := testContext2(t, &ContextOpts{ Module: m, - Providers: map[string]ResourceProviderFactory{ - "aws": testProviderFuncFixed(p), - }, + ProviderResolver: ResourceProviderResolverFixed( + map[string]ResourceProviderFactory{ + "aws": testProviderFuncFixed(p), + }, + ), Provisioners: map[string]ResourceProvisionerFactory{ "shell": testProvisionerFuncFixed(pr), }, @@ -514,33 +544,35 @@ func TestContext2Plan_moduleProviderInherit(t *testing.T) { m := testModule(t, "plan-module-provider-inherit") ctx := testContext2(t, &ContextOpts{ Module: m, - Providers: map[string]ResourceProviderFactory{ - "aws": func() (ResourceProvider, error) { - l.Lock() - defer l.Unlock() - - p := testProvider("aws") - p.ConfigureFn = func(c *ResourceConfig) error { - if v, ok := c.Get("from"); !ok || v.(string) != "root" { - return fmt.Errorf("bad") - } - - return nil - } - p.DiffFn = func( - info *InstanceInfo, - state *InstanceState, - c *ResourceConfig) (*InstanceDiff, error) { - v, _ := c.Get("from") - + ProviderResolver: ResourceProviderResolverFixed( + map[string]ResourceProviderFactory{ + "aws": func() (ResourceProvider, error) { l.Lock() defer l.Unlock() - calls = append(calls, v.(string)) - return testDiffFn(info, state, c) - } - return p, nil + + p := testProvider("aws") + p.ConfigureFn = func(c *ResourceConfig) error { + if v, ok := c.Get("from"); !ok || v.(string) != "root" { + return fmt.Errorf("bad") + } + + return nil + } + p.DiffFn = func( + info *InstanceInfo, + state *InstanceState, + c *ResourceConfig) (*InstanceDiff, error) { + v, _ := c.Get("from") + + l.Lock() + defer l.Unlock() + calls = append(calls, v.(string)) + return testDiffFn(info, state, c) + } + return p, nil + }, }, - }, + ), }) _, err := ctx.Plan() @@ -564,36 +596,38 @@ func TestContext2Plan_moduleProviderInheritDeep(t *testing.T) { m := testModule(t, "plan-module-provider-inherit-deep") ctx := testContext2(t, &ContextOpts{ Module: m, - Providers: map[string]ResourceProviderFactory{ - "aws": func() (ResourceProvider, error) { - l.Lock() - defer l.Unlock() + ProviderResolver: ResourceProviderResolverFixed( + map[string]ResourceProviderFactory{ + "aws": func() (ResourceProvider, error) { + l.Lock() + defer l.Unlock() - var from string - p := testProvider("aws") - p.ConfigureFn = func(c *ResourceConfig) error { - v, ok := c.Get("from") - if !ok || v.(string) != "root" { - return fmt.Errorf("bad") + var from string + p := testProvider("aws") + p.ConfigureFn = func(c *ResourceConfig) error { + v, ok := c.Get("from") + if !ok || v.(string) != "root" { + return fmt.Errorf("bad") + } + + from = v.(string) + return nil } - from = v.(string) - return nil - } + p.DiffFn = func( + info *InstanceInfo, + state *InstanceState, + c *ResourceConfig) (*InstanceDiff, error) { + if from != "root" { + return nil, fmt.Errorf("bad resource") + } - p.DiffFn = func( - info *InstanceInfo, - state *InstanceState, - c *ResourceConfig) (*InstanceDiff, error) { - if from != "root" { - return nil, fmt.Errorf("bad resource") + return testDiffFn(info, state, c) } - - return testDiffFn(info, state, c) - } - return p, nil + return p, nil + }, }, - }, + ), }) _, err := ctx.Plan() @@ -610,36 +644,38 @@ func TestContext2Plan_moduleProviderDefaults(t *testing.T) { m := testModule(t, "plan-module-provider-defaults") ctx := testContext2(t, &ContextOpts{ Module: m, - Providers: map[string]ResourceProviderFactory{ - "aws": func() (ResourceProvider, error) { - l.Lock() - defer l.Unlock() - - p := testProvider("aws") - p.ConfigureFn = func(c *ResourceConfig) error { - if v, ok := c.Get("from"); !ok || v.(string) != "root" { - return fmt.Errorf("bad") - } - if v, ok := c.Get("to"); ok && v.(string) == "child" { - toCount++ - } - - return nil - } - p.DiffFn = func( - info *InstanceInfo, - state *InstanceState, - c *ResourceConfig) (*InstanceDiff, error) { - v, _ := c.Get("from") - + ProviderResolver: ResourceProviderResolverFixed( + map[string]ResourceProviderFactory{ + "aws": func() (ResourceProvider, error) { l.Lock() defer l.Unlock() - calls = append(calls, v.(string)) - return testDiffFn(info, state, c) - } - return p, nil + + p := testProvider("aws") + p.ConfigureFn = func(c *ResourceConfig) error { + if v, ok := c.Get("from"); !ok || v.(string) != "root" { + return fmt.Errorf("bad") + } + if v, ok := c.Get("to"); ok && v.(string) == "child" { + toCount++ + } + + return nil + } + p.DiffFn = func( + info *InstanceInfo, + state *InstanceState, + c *ResourceConfig) (*InstanceDiff, error) { + v, _ := c.Get("from") + + l.Lock() + defer l.Unlock() + calls = append(calls, v.(string)) + return testDiffFn(info, state, c) + } + return p, nil + }, }, - }, + ), }) _, err := ctx.Plan() @@ -668,30 +704,32 @@ func TestContext2Plan_moduleProviderDefaultsVar(t *testing.T) { m := testModule(t, "plan-module-provider-defaults-var") ctx := testContext2(t, &ContextOpts{ Module: m, - Providers: map[string]ResourceProviderFactory{ - "aws": func() (ResourceProvider, error) { - l.Lock() - defer l.Unlock() - - p := testProvider("aws") - p.ConfigureFn = func(c *ResourceConfig) error { - var buf bytes.Buffer - if v, ok := c.Get("from"); ok { - buf.WriteString(v.(string) + "\n") - } - if v, ok := c.Get("to"); ok { - buf.WriteString(v.(string) + "\n") - } - + ProviderResolver: ResourceProviderResolverFixed( + map[string]ResourceProviderFactory{ + "aws": func() (ResourceProvider, error) { l.Lock() defer l.Unlock() - calls = append(calls, buf.String()) - return nil - } - p.DiffFn = testDiffFn - return p, nil + + p := testProvider("aws") + p.ConfigureFn = func(c *ResourceConfig) error { + var buf bytes.Buffer + if v, ok := c.Get("from"); ok { + buf.WriteString(v.(string) + "\n") + } + if v, ok := c.Get("to"); ok { + buf.WriteString(v.(string) + "\n") + } + + l.Lock() + defer l.Unlock() + calls = append(calls, buf.String()) + return nil + } + p.DiffFn = testDiffFn + return p, nil + }, }, - }, + ), Variables: map[string]interface{}{ "foo": "root", }, @@ -717,9 +755,11 @@ func TestContext2Plan_moduleProviderVar(t *testing.T) { p.DiffFn = testDiffFn ctx := testContext2(t, &ContextOpts{ Module: m, - Providers: map[string]ResourceProviderFactory{ - "aws": testProviderFuncFixed(p), - }, + ProviderResolver: ResourceProviderResolverFixed( + map[string]ResourceProviderFactory{ + "aws": testProviderFuncFixed(p), + }, + ), }) plan, err := ctx.Plan() @@ -740,9 +780,11 @@ func TestContext2Plan_moduleVar(t *testing.T) { p.DiffFn = testDiffFn ctx := testContext2(t, &ContextOpts{ Module: m, - Providers: map[string]ResourceProviderFactory{ - "aws": testProviderFuncFixed(p), - }, + ProviderResolver: ResourceProviderResolverFixed( + map[string]ResourceProviderFactory{ + "aws": testProviderFuncFixed(p), + }, + ), }) plan, err := ctx.Plan() @@ -763,9 +805,11 @@ func TestContext2Plan_moduleVarWrongTypeBasic(t *testing.T) { p.DiffFn = testDiffFn ctx := testContext2(t, &ContextOpts{ Module: m, - Providers: map[string]ResourceProviderFactory{ - "aws": testProviderFuncFixed(p), - }, + ProviderResolver: ResourceProviderResolverFixed( + map[string]ResourceProviderFactory{ + "aws": testProviderFuncFixed(p), + }, + ), }) _, err := ctx.Plan() @@ -776,13 +820,15 @@ func TestContext2Plan_moduleVarWrongTypeBasic(t *testing.T) { func TestContext2Plan_moduleVarWrongTypeNested(t *testing.T) { m := testModule(t, "plan-module-wrong-var-type-nested") - p := testProvider("aws") + p := testProvider("null") p.DiffFn = testDiffFn ctx := testContext2(t, &ContextOpts{ Module: m, - Providers: map[string]ResourceProviderFactory{ - "aws": testProviderFuncFixed(p), - }, + ProviderResolver: ResourceProviderResolverFixed( + map[string]ResourceProviderFactory{ + "null": testProviderFuncFixed(p), + }, + ), }) _, err := ctx.Plan() @@ -797,9 +843,11 @@ func TestContext2Plan_moduleVarWithDefaultValue(t *testing.T) { p.DiffFn = testDiffFn ctx := testContext2(t, &ContextOpts{ Module: m, - Providers: map[string]ResourceProviderFactory{ - "null": testProviderFuncFixed(p), - }, + ProviderResolver: ResourceProviderResolverFixed( + map[string]ResourceProviderFactory{ + "null": testProviderFuncFixed(p), + }, + ), }) _, err := ctx.Plan() @@ -814,9 +862,11 @@ func TestContext2Plan_moduleVarComputed(t *testing.T) { p.DiffFn = testDiffFn ctx := testContext2(t, &ContextOpts{ Module: m, - Providers: map[string]ResourceProviderFactory{ - "aws": testProviderFuncFixed(p), - }, + ProviderResolver: ResourceProviderResolverFixed( + map[string]ResourceProviderFactory{ + "aws": testProviderFuncFixed(p), + }, + ), }) plan, err := ctx.Plan() @@ -837,9 +887,11 @@ func TestContext2Plan_nil(t *testing.T) { p.DiffFn = testDiffFn ctx := testContext2(t, &ContextOpts{ Module: m, - Providers: map[string]ResourceProviderFactory{ - "aws": testProviderFuncFixed(p), - }, + ProviderResolver: ResourceProviderResolverFixed( + map[string]ResourceProviderFactory{ + "aws": testProviderFuncFixed(p), + }, + ), State: &State{ Modules: []*ModuleState{ &ModuleState{ @@ -872,9 +924,11 @@ func TestContext2Plan_preventDestroy_bad(t *testing.T) { p.DiffFn = testDiffFn ctx := testContext2(t, &ContextOpts{ Module: m, - Providers: map[string]ResourceProviderFactory{ - "aws": testProviderFuncFixed(p), - }, + ProviderResolver: ResourceProviderResolverFixed( + map[string]ResourceProviderFactory{ + "aws": testProviderFuncFixed(p), + }, + ), State: &State{ Modules: []*ModuleState{ &ModuleState{ @@ -907,9 +961,11 @@ func TestContext2Plan_preventDestroy_good(t *testing.T) { p.DiffFn = testDiffFn ctx := testContext2(t, &ContextOpts{ Module: m, - Providers: map[string]ResourceProviderFactory{ - "aws": testProviderFuncFixed(p), - }, + ProviderResolver: ResourceProviderResolverFixed( + map[string]ResourceProviderFactory{ + "aws": testProviderFuncFixed(p), + }, + ), State: &State{ Modules: []*ModuleState{ &ModuleState{ @@ -942,9 +998,11 @@ func TestContext2Plan_preventDestroy_countBad(t *testing.T) { p.DiffFn = testDiffFn ctx := testContext2(t, &ContextOpts{ Module: m, - Providers: map[string]ResourceProviderFactory{ - "aws": testProviderFuncFixed(p), - }, + ProviderResolver: ResourceProviderResolverFixed( + map[string]ResourceProviderFactory{ + "aws": testProviderFuncFixed(p), + }, + ), State: &State{ Modules: []*ModuleState{ &ModuleState{ @@ -983,9 +1041,11 @@ func TestContext2Plan_preventDestroy_countGood(t *testing.T) { p.DiffFn = testDiffFn ctx := testContext2(t, &ContextOpts{ Module: m, - Providers: map[string]ResourceProviderFactory{ - "aws": testProviderFuncFixed(p), - }, + ProviderResolver: ResourceProviderResolverFixed( + map[string]ResourceProviderFactory{ + "aws": testProviderFuncFixed(p), + }, + ), State: &State{ Modules: []*ModuleState{ &ModuleState{ @@ -1024,9 +1084,11 @@ func TestContext2Plan_preventDestroy_countGoodNoChange(t *testing.T) { p.DiffFn = testDiffFn ctx := testContext2(t, &ContextOpts{ Module: m, - Providers: map[string]ResourceProviderFactory{ - "aws": testProviderFuncFixed(p), - }, + ProviderResolver: ResourceProviderResolverFixed( + map[string]ResourceProviderFactory{ + "aws": testProviderFuncFixed(p), + }, + ), State: &State{ Modules: []*ModuleState{ &ModuleState{ @@ -1063,9 +1125,11 @@ func TestContext2Plan_preventDestroy_destroyPlan(t *testing.T) { p.DiffFn = testDiffFn ctx := testContext2(t, &ContextOpts{ Module: m, - Providers: map[string]ResourceProviderFactory{ - "aws": testProviderFuncFixed(p), - }, + ProviderResolver: ResourceProviderResolverFixed( + map[string]ResourceProviderFactory{ + "aws": testProviderFuncFixed(p), + }, + ), State: &State{ Modules: []*ModuleState{ &ModuleState{ @@ -1100,9 +1164,11 @@ func TestContext2Plan_provisionerCycle(t *testing.T) { pr := testProvisioner() ctx := testContext2(t, &ContextOpts{ Module: m, - Providers: map[string]ResourceProviderFactory{ - "aws": testProviderFuncFixed(p), - }, + ProviderResolver: ResourceProviderResolverFixed( + map[string]ResourceProviderFactory{ + "aws": testProviderFuncFixed(p), + }, + ), Provisioners: map[string]ResourceProvisionerFactory{ "local-exec": testProvisionerFuncFixed(pr), }, @@ -1120,9 +1186,11 @@ func TestContext2Plan_computed(t *testing.T) { p.DiffFn = testDiffFn ctx := testContext2(t, &ContextOpts{ Module: m, - Providers: map[string]ResourceProviderFactory{ - "aws": testProviderFuncFixed(p), - }, + ProviderResolver: ResourceProviderResolverFixed( + map[string]ResourceProviderFactory{ + "aws": testProviderFuncFixed(p), + }, + ), }) plan, err := ctx.Plan() @@ -1143,9 +1211,11 @@ func TestContext2Plan_computedDataResource(t *testing.T) { p.DiffFn = testDiffFn ctx := testContext2(t, &ContextOpts{ Module: m, - Providers: map[string]ResourceProviderFactory{ - "aws": testProviderFuncFixed(p), - }, + ProviderResolver: ResourceProviderResolverFixed( + map[string]ResourceProviderFactory{ + "aws": testProviderFuncFixed(p), + }, + ), }) plan, err := ctx.Plan() @@ -1190,9 +1260,11 @@ func TestContext2Plan_computedDataCountResource(t *testing.T) { p.DiffFn = testDiffFn ctx := testContext2(t, &ContextOpts{ Module: m, - Providers: map[string]ResourceProviderFactory{ - "aws": testProviderFuncFixed(p), - }, + ProviderResolver: ResourceProviderResolverFixed( + map[string]ResourceProviderFactory{ + "aws": testProviderFuncFixed(p), + }, + ), }) plan, err := ctx.Plan() @@ -1266,9 +1338,11 @@ func TestContext2Plan_dataSourceTypeMismatch(t *testing.T) { }, }, }, - Providers: map[string]ResourceProviderFactory{ - "aws": testProviderFuncFixed(p), - }, + ProviderResolver: ResourceProviderResolverFixed( + map[string]ResourceProviderFactory{ + "aws": testProviderFuncFixed(p), + }, + ), }) _, err := ctx.Plan() @@ -1314,9 +1388,11 @@ func TestContext2Plan_dataResourceBecomesComputed(t *testing.T) { ctx := testContext2(t, &ContextOpts{ Module: m, - Providers: map[string]ResourceProviderFactory{ - "aws": testProviderFuncFixed(p), - }, + ProviderResolver: ResourceProviderResolverFixed( + map[string]ResourceProviderFactory{ + "aws": testProviderFuncFixed(p), + }, + ), State: &State{ Modules: []*ModuleState{ &ModuleState{ @@ -1379,9 +1455,11 @@ func TestContext2Plan_computedList(t *testing.T) { p.DiffFn = testDiffFn ctx := testContext2(t, &ContextOpts{ Module: m, - Providers: map[string]ResourceProviderFactory{ - "aws": testProviderFuncFixed(p), - }, + ProviderResolver: ResourceProviderResolverFixed( + map[string]ResourceProviderFactory{ + "aws": testProviderFuncFixed(p), + }, + ), }) plan, err := ctx.Plan() @@ -1404,9 +1482,11 @@ func TestContext2Plan_computedMultiIndex(t *testing.T) { p.DiffFn = testDiffFn ctx := testContext2(t, &ContextOpts{ Module: m, - Providers: map[string]ResourceProviderFactory{ - "aws": testProviderFuncFixed(p), - }, + ProviderResolver: ResourceProviderResolverFixed( + map[string]ResourceProviderFactory{ + "aws": testProviderFuncFixed(p), + }, + ), }) plan, err := ctx.Plan() @@ -1427,9 +1507,11 @@ func TestContext2Plan_count(t *testing.T) { p.DiffFn = testDiffFn ctx := testContext2(t, &ContextOpts{ Module: m, - Providers: map[string]ResourceProviderFactory{ - "aws": testProviderFuncFixed(p), - }, + ProviderResolver: ResourceProviderResolverFixed( + map[string]ResourceProviderFactory{ + "aws": testProviderFuncFixed(p), + }, + ), }) plan, err := ctx.Plan() @@ -1454,9 +1536,11 @@ func TestContext2Plan_countComputed(t *testing.T) { p.DiffFn = testDiffFn ctx := testContext2(t, &ContextOpts{ Module: m, - Providers: map[string]ResourceProviderFactory{ - "aws": testProviderFuncFixed(p), - }, + ProviderResolver: ResourceProviderResolverFixed( + map[string]ResourceProviderFactory{ + "aws": testProviderFuncFixed(p), + }, + ), }) _, err := ctx.Plan() @@ -1471,9 +1555,11 @@ func TestContext2Plan_countComputedModule(t *testing.T) { p.DiffFn = testDiffFn ctx := testContext2(t, &ContextOpts{ Module: m, - Providers: map[string]ResourceProviderFactory{ - "aws": testProviderFuncFixed(p), - }, + ProviderResolver: ResourceProviderResolverFixed( + map[string]ResourceProviderFactory{ + "aws": testProviderFuncFixed(p), + }, + ), }) _, err := ctx.Plan() @@ -1491,9 +1577,11 @@ func TestContext2Plan_countModuleStatic(t *testing.T) { p.DiffFn = testDiffFn ctx := testContext2(t, &ContextOpts{ Module: m, - Providers: map[string]ResourceProviderFactory{ - "aws": testProviderFuncFixed(p), - }, + ProviderResolver: ResourceProviderResolverFixed( + map[string]ResourceProviderFactory{ + "aws": testProviderFuncFixed(p), + }, + ), }) plan, err := ctx.Plan() @@ -1525,9 +1613,11 @@ func TestContext2Plan_countModuleStaticGrandchild(t *testing.T) { p.DiffFn = testDiffFn ctx := testContext2(t, &ContextOpts{ Module: m, - Providers: map[string]ResourceProviderFactory{ - "aws": testProviderFuncFixed(p), - }, + ProviderResolver: ResourceProviderResolverFixed( + map[string]ResourceProviderFactory{ + "aws": testProviderFuncFixed(p), + }, + ), }) plan, err := ctx.Plan() @@ -1559,9 +1649,11 @@ func TestContext2Plan_countIndex(t *testing.T) { p.DiffFn = testDiffFn ctx := testContext2(t, &ContextOpts{ Module: m, - Providers: map[string]ResourceProviderFactory{ - "aws": testProviderFuncFixed(p), - }, + ProviderResolver: ResourceProviderResolverFixed( + map[string]ResourceProviderFactory{ + "aws": testProviderFuncFixed(p), + }, + ), }) plan, err := ctx.Plan() @@ -1582,9 +1674,11 @@ func TestContext2Plan_countIndexZero(t *testing.T) { p.DiffFn = testDiffFn ctx := testContext2(t, &ContextOpts{ Module: m, - Providers: map[string]ResourceProviderFactory{ - "aws": testProviderFuncFixed(p), - }, + ProviderResolver: ResourceProviderResolverFixed( + map[string]ResourceProviderFactory{ + "aws": testProviderFuncFixed(p), + }, + ), }) plan, err := ctx.Plan() @@ -1605,9 +1699,11 @@ func TestContext2Plan_countVar(t *testing.T) { p.DiffFn = testDiffFn ctx := testContext2(t, &ContextOpts{ Module: m, - Providers: map[string]ResourceProviderFactory{ - "aws": testProviderFuncFixed(p), - }, + ProviderResolver: ResourceProviderResolverFixed( + map[string]ResourceProviderFactory{ + "aws": testProviderFuncFixed(p), + }, + ), Variables: map[string]interface{}{ "count": "3", }, @@ -1631,9 +1727,11 @@ func TestContext2Plan_countZero(t *testing.T) { p.DiffFn = testDiffFn ctx := testContext2(t, &ContextOpts{ Module: m, - Providers: map[string]ResourceProviderFactory{ - "aws": testProviderFuncFixed(p), - }, + ProviderResolver: ResourceProviderResolverFixed( + map[string]ResourceProviderFactory{ + "aws": testProviderFuncFixed(p), + }, + ), }) plan, err := ctx.Plan() @@ -1655,9 +1753,11 @@ func TestContext2Plan_countOneIndex(t *testing.T) { p.DiffFn = testDiffFn ctx := testContext2(t, &ContextOpts{ Module: m, - Providers: map[string]ResourceProviderFactory{ - "aws": testProviderFuncFixed(p), - }, + ProviderResolver: ResourceProviderResolverFixed( + map[string]ResourceProviderFactory{ + "aws": testProviderFuncFixed(p), + }, + ), }) plan, err := ctx.Plan() @@ -1709,9 +1809,11 @@ func TestContext2Plan_countDecreaseToOne(t *testing.T) { } ctx := testContext2(t, &ContextOpts{ Module: m, - Providers: map[string]ResourceProviderFactory{ - "aws": testProviderFuncFixed(p), - }, + ProviderResolver: ResourceProviderResolverFixed( + map[string]ResourceProviderFactory{ + "aws": testProviderFuncFixed(p), + }, + ), State: s, }) @@ -1752,9 +1854,11 @@ func TestContext2Plan_countIncreaseFromNotSet(t *testing.T) { } ctx := testContext2(t, &ContextOpts{ Module: m, - Providers: map[string]ResourceProviderFactory{ - "aws": testProviderFuncFixed(p), - }, + ProviderResolver: ResourceProviderResolverFixed( + map[string]ResourceProviderFactory{ + "aws": testProviderFuncFixed(p), + }, + ), State: s, }) @@ -1795,9 +1899,11 @@ func TestContext2Plan_countIncreaseFromOne(t *testing.T) { } ctx := testContext2(t, &ContextOpts{ Module: m, - Providers: map[string]ResourceProviderFactory{ - "aws": testProviderFuncFixed(p), - }, + ProviderResolver: ResourceProviderResolverFixed( + map[string]ResourceProviderFactory{ + "aws": testProviderFuncFixed(p), + }, + ), State: s, }) @@ -1853,9 +1959,11 @@ func TestContext2Plan_countIncreaseFromOneCorrupted(t *testing.T) { } ctx := testContext2(t, &ContextOpts{ Module: m, - Providers: map[string]ResourceProviderFactory{ - "aws": testProviderFuncFixed(p), - }, + ProviderResolver: ResourceProviderResolverFixed( + map[string]ResourceProviderFactory{ + "aws": testProviderFuncFixed(p), + }, + ), State: s, }) @@ -1930,9 +2038,11 @@ func TestContext2Plan_countIncreaseWithSplatReference(t *testing.T) { } ctx := testContext2(t, &ContextOpts{ Module: m, - Providers: map[string]ResourceProviderFactory{ - "aws": testProviderFuncFixed(p), - }, + ProviderResolver: ResourceProviderResolverFixed( + map[string]ResourceProviderFactory{ + "aws": testProviderFuncFixed(p), + }, + ), State: s, }) @@ -1999,9 +2109,11 @@ func TestContext2Plan_destroy(t *testing.T) { } ctx := testContext2(t, &ContextOpts{ Module: m, - Providers: map[string]ResourceProviderFactory{ - "aws": testProviderFuncFixed(p), - }, + ProviderResolver: ResourceProviderResolverFixed( + map[string]ResourceProviderFactory{ + "aws": testProviderFuncFixed(p), + }, + ), State: s, Destroy: true, }) @@ -2054,9 +2166,11 @@ func TestContext2Plan_moduleDestroy(t *testing.T) { } ctx := testContext2(t, &ContextOpts{ Module: m, - Providers: map[string]ResourceProviderFactory{ - "aws": testProviderFuncFixed(p), - }, + ProviderResolver: ResourceProviderResolverFixed( + map[string]ResourceProviderFactory{ + "aws": testProviderFuncFixed(p), + }, + ), State: s, Destroy: true, }) @@ -2106,9 +2220,11 @@ func TestContext2Plan_moduleDestroyCycle(t *testing.T) { } ctx := testContext2(t, &ContextOpts{ Module: m, - Providers: map[string]ResourceProviderFactory{ - "aws": testProviderFuncFixed(p), - }, + ProviderResolver: ResourceProviderResolverFixed( + map[string]ResourceProviderFactory{ + "aws": testProviderFuncFixed(p), + }, + ), State: s, Destroy: true, }) @@ -2156,9 +2272,11 @@ func TestContext2Plan_moduleDestroyMultivar(t *testing.T) { } ctx := testContext2(t, &ContextOpts{ Module: m, - Providers: map[string]ResourceProviderFactory{ - "aws": testProviderFuncFixed(p), - }, + ProviderResolver: ResourceProviderResolverFixed( + map[string]ResourceProviderFactory{ + "aws": testProviderFuncFixed(p), + }, + ), State: s, Destroy: true, }) @@ -2186,9 +2304,11 @@ func TestContext2Plan_pathVar(t *testing.T) { p.DiffFn = testDiffFn ctx := testContext2(t, &ContextOpts{ Module: m, - Providers: map[string]ResourceProviderFactory{ - "aws": testProviderFuncFixed(p), - }, + ProviderResolver: ResourceProviderResolverFixed( + map[string]ResourceProviderFactory{ + "aws": testProviderFuncFixed(p), + }, + ), }) plan, err := ctx.Plan() @@ -2221,6 +2341,7 @@ func TestContext2Plan_diffVar(t *testing.T) { Path: rootModulePath, Resources: map[string]*ResourceState{ "aws_instance.foo": &ResourceState{ + Type: "aws_instance", Primary: &InstanceState{ ID: "bar", Attributes: map[string]string{ @@ -2234,9 +2355,11 @@ func TestContext2Plan_diffVar(t *testing.T) { } ctx := testContext2(t, &ContextOpts{ Module: m, - Providers: map[string]ResourceProviderFactory{ - "aws": testProviderFuncFixed(p), - }, + ProviderResolver: ResourceProviderResolverFixed( + map[string]ResourceProviderFactory{ + "aws": testProviderFuncFixed(p), + }, + ), State: s, }) @@ -2278,9 +2401,11 @@ func TestContext2Plan_hook(t *testing.T) { ctx := testContext2(t, &ContextOpts{ Module: m, Hooks: []Hook{h}, - Providers: map[string]ResourceProviderFactory{ - "aws": testProviderFuncFixed(p), - }, + ProviderResolver: ResourceProviderResolverFixed( + map[string]ResourceProviderFactory{ + "aws": testProviderFuncFixed(p), + }, + ), }) _, err := ctx.Plan() @@ -2317,9 +2442,11 @@ func TestContext2Plan_orphan(t *testing.T) { } ctx := testContext2(t, &ContextOpts{ Module: m, - Providers: map[string]ResourceProviderFactory{ - "aws": testProviderFuncFixed(p), - }, + ProviderResolver: ResourceProviderResolverFixed( + map[string]ResourceProviderFactory{ + "aws": testProviderFuncFixed(p), + }, + ), State: s, }) @@ -2343,9 +2470,11 @@ func TestContext2Plan_shadowUuid(t *testing.T) { p.DiffFn = testDiffFn ctx := testContext2(t, &ContextOpts{ Module: m, - Providers: map[string]ResourceProviderFactory{ - "aws": testProviderFuncFixed(p), - }, + ProviderResolver: ResourceProviderResolverFixed( + map[string]ResourceProviderFactory{ + "aws": testProviderFuncFixed(p), + }, + ), }) _, err := ctx.Plan() @@ -2364,6 +2493,7 @@ func TestContext2Plan_state(t *testing.T) { Path: rootModulePath, Resources: map[string]*ResourceState{ "aws_instance.foo": &ResourceState{ + Type: "aws_instance", Primary: &InstanceState{ ID: "bar", }, @@ -2374,9 +2504,11 @@ func TestContext2Plan_state(t *testing.T) { } ctx := testContext2(t, &ContextOpts{ Module: m, - Providers: map[string]ResourceProviderFactory{ - "aws": testProviderFuncFixed(p), - }, + ProviderResolver: ResourceProviderResolverFixed( + map[string]ResourceProviderFactory{ + "aws": testProviderFuncFixed(p), + }, + ), State: s, }) @@ -2425,9 +2557,11 @@ func TestContext2Plan_taint(t *testing.T) { } ctx := testContext2(t, &ContextOpts{ Module: m, - Providers: map[string]ResourceProviderFactory{ - "aws": testProviderFuncFixed(p), - }, + ProviderResolver: ResourceProviderResolverFixed( + map[string]ResourceProviderFactory{ + "aws": testProviderFuncFixed(p), + }, + ), State: s, }) @@ -2470,9 +2604,11 @@ func TestContext2Apply_taintIgnoreChanges(t *testing.T) { } ctx := testContext2(t, &ContextOpts{ Module: m, - Providers: map[string]ResourceProviderFactory{ - "aws": testProviderFuncFixed(p), - }, + ProviderResolver: ResourceProviderResolverFixed( + map[string]ResourceProviderFactory{ + "aws": testProviderFuncFixed(p), + }, + ), State: s, }) @@ -2519,9 +2655,11 @@ func TestContext2Plan_taintDestroyInterpolatedCountRace(t *testing.T) { } ctx := testContext2(t, &ContextOpts{ Module: m, - Providers: map[string]ResourceProviderFactory{ - "aws": testProviderFuncFixed(p), - }, + ProviderResolver: ResourceProviderResolverFixed( + map[string]ResourceProviderFactory{ + "aws": testProviderFuncFixed(p), + }, + ), State: s, }) @@ -2559,9 +2697,11 @@ func TestContext2Plan_targeted(t *testing.T) { p.DiffFn = testDiffFn ctx := testContext2(t, &ContextOpts{ Module: m, - Providers: map[string]ResourceProviderFactory{ - "aws": testProviderFuncFixed(p), - }, + ProviderResolver: ResourceProviderResolverFixed( + map[string]ResourceProviderFactory{ + "aws": testProviderFuncFixed(p), + }, + ), Targets: []string{"aws_instance.foo"}, }) @@ -2595,9 +2735,11 @@ func TestContext2Plan_targetedCrossModule(t *testing.T) { p.DiffFn = testDiffFn ctx := testContext2(t, &ContextOpts{ Module: m, - Providers: map[string]ResourceProviderFactory{ - "aws": testProviderFuncFixed(p), - }, + ProviderResolver: ResourceProviderResolverFixed( + map[string]ResourceProviderFactory{ + "aws": testProviderFuncFixed(p), + }, + ), Targets: []string{"module.B"}, }) @@ -2634,9 +2776,11 @@ func TestContext2Plan_targetedModuleWithProvider(t *testing.T) { p.DiffFn = testDiffFn ctx := testContext2(t, &ContextOpts{ Module: m, - Providers: map[string]ResourceProviderFactory{ - "null": testProviderFuncFixed(p), - }, + ProviderResolver: ResourceProviderResolverFixed( + map[string]ResourceProviderFactory{ + "null": testProviderFuncFixed(p), + }, + ), Targets: []string{"module.child2"}, }) @@ -2667,9 +2811,11 @@ func TestContext2Plan_targetedOrphan(t *testing.T) { p.DiffFn = testDiffFn ctx := testContext2(t, &ContextOpts{ Module: m, - Providers: map[string]ResourceProviderFactory{ - "aws": testProviderFuncFixed(p), - }, + ProviderResolver: ResourceProviderResolverFixed( + map[string]ResourceProviderFactory{ + "aws": testProviderFuncFixed(p), + }, + ), State: &State{ Modules: []*ModuleState{ &ModuleState{ @@ -2724,9 +2870,11 @@ func TestContext2Plan_targetedModuleOrphan(t *testing.T) { p.DiffFn = testDiffFn ctx := testContext2(t, &ContextOpts{ Module: m, - Providers: map[string]ResourceProviderFactory{ - "aws": testProviderFuncFixed(p), - }, + ProviderResolver: ResourceProviderResolverFixed( + map[string]ResourceProviderFactory{ + "aws": testProviderFuncFixed(p), + }, + ), State: &State{ Modules: []*ModuleState{ &ModuleState{ @@ -2782,9 +2930,11 @@ func TestContext2Plan_targetedModuleUntargetedVariable(t *testing.T) { p.DiffFn = testDiffFn ctx := testContext2(t, &ContextOpts{ Module: m, - Providers: map[string]ResourceProviderFactory{ - "aws": testProviderFuncFixed(p), - }, + ProviderResolver: ResourceProviderResolverFixed( + map[string]ResourceProviderFactory{ + "aws": testProviderFuncFixed(p), + }, + ), Targets: []string{"aws_instance.blue", "module.blue_mod"}, }) @@ -2833,9 +2983,11 @@ func TestContext2Plan_targetedOverTen(t *testing.T) { } ctx := testContext2(t, &ContextOpts{ Module: m, - Providers: map[string]ResourceProviderFactory{ - "aws": testProviderFuncFixed(p), - }, + ProviderResolver: ResourceProviderResolverFixed( + map[string]ResourceProviderFactory{ + "aws": testProviderFuncFixed(p), + }, + ), State: &State{ Modules: []*ModuleState{ &ModuleState{ @@ -2906,9 +3058,11 @@ func TestContext2Plan_provider(t *testing.T) { ctx := testContext2(t, &ContextOpts{ Module: m, - Providers: map[string]ResourceProviderFactory{ - "aws": testProviderFuncFixed(p), - }, + ProviderResolver: ResourceProviderResolverFixed( + map[string]ResourceProviderFactory{ + "aws": testProviderFuncFixed(p), + }, + ), Variables: map[string]interface{}{ "foo": "bar", }, @@ -2928,9 +3082,11 @@ func TestContext2Plan_varListErr(t *testing.T) { p := testProvider("aws") ctx := testContext2(t, &ContextOpts{ Module: m, - Providers: map[string]ResourceProviderFactory{ - "aws": testProviderFuncFixed(p), - }, + ProviderResolver: ResourceProviderResolverFixed( + map[string]ResourceProviderFactory{ + "aws": testProviderFuncFixed(p), + }, + ), }) _, err := ctx.Plan() @@ -2962,9 +3118,11 @@ func TestContext2Plan_ignoreChanges(t *testing.T) { } ctx := testContext2(t, &ContextOpts{ Module: m, - Providers: map[string]ResourceProviderFactory{ - "aws": testProviderFuncFixed(p), - }, + ProviderResolver: ResourceProviderResolverFixed( + map[string]ResourceProviderFactory{ + "aws": testProviderFuncFixed(p), + }, + ), Variables: map[string]interface{}{ "foo": "ami-1234abcd", }, @@ -2997,6 +3155,7 @@ func TestContext2Plan_ignoreChangesWildcard(t *testing.T) { Path: rootModulePath, Resources: map[string]*ResourceState{ "aws_instance.foo": &ResourceState{ + Type: "aws_instance", Primary: &InstanceState{ ID: "bar", Attributes: map[string]string{ @@ -3011,9 +3170,11 @@ func TestContext2Plan_ignoreChangesWildcard(t *testing.T) { } ctx := testContext2(t, &ContextOpts{ Module: m, - Providers: map[string]ResourceProviderFactory{ - "aws": testProviderFuncFixed(p), - }, + ProviderResolver: ResourceProviderResolverFixed( + map[string]ResourceProviderFactory{ + "aws": testProviderFuncFixed(p), + }, + ), Variables: map[string]interface{}{ "foo": "ami-1234abcd", "bar": "t2.small", @@ -3066,9 +3227,11 @@ func TestContext2Plan_moduleMapLiteral(t *testing.T) { } ctx := testContext2(t, &ContextOpts{ Module: m, - Providers: map[string]ResourceProviderFactory{ - "aws": testProviderFuncFixed(p), - }, + ProviderResolver: ResourceProviderResolverFixed( + map[string]ResourceProviderFactory{ + "aws": testProviderFuncFixed(p), + }, + ), }) if _, err := ctx.Plan(); err != nil { @@ -3095,9 +3258,11 @@ func TestContext2Plan_computedValueInMap(t *testing.T) { } ctx := testContext2(t, &ContextOpts{ Module: m, - Providers: map[string]ResourceProviderFactory{ - "aws": testProviderFuncFixed(p), - }, + ProviderResolver: ResourceProviderResolverFixed( + map[string]ResourceProviderFactory{ + "aws": testProviderFuncFixed(p), + }, + ), }) if _, err := ctx.Plan(); err != nil { @@ -3122,9 +3287,11 @@ func TestContext2Plan_moduleVariableFromSplat(t *testing.T) { p.DiffFn = testDiffFn ctx := testContext2(t, &ContextOpts{ Module: m, - Providers: map[string]ResourceProviderFactory{ - "aws": testProviderFuncFixed(p), - }, + ProviderResolver: ResourceProviderResolverFixed( + map[string]ResourceProviderFactory{ + "aws": testProviderFuncFixed(p), + }, + ), }) if _, err := ctx.Plan(); err != nil { @@ -3149,9 +3316,11 @@ func TestContext2Plan_createBeforeDestroy_depends_datasource(t *testing.T) { p.DiffFn = testDiffFn ctx := testContext2(t, &ContextOpts{ Module: m, - Providers: map[string]ResourceProviderFactory{ - "aws": testProviderFuncFixed(p), - }, + ProviderResolver: ResourceProviderResolverFixed( + map[string]ResourceProviderFactory{ + "aws": testProviderFuncFixed(p), + }, + ), }) plan, err := ctx.Plan() @@ -3187,9 +3356,11 @@ func TestContext2Plan_listOrder(t *testing.T) { p.DiffFn = testDiffFn ctx := testContext2(t, &ContextOpts{ Module: m, - Providers: map[string]ResourceProviderFactory{ - "aws": testProviderFuncFixed(p), - }, + ProviderResolver: ResourceProviderResolverFixed( + map[string]ResourceProviderFactory{ + "aws": testProviderFuncFixed(p), + }, + ), }) plan, err := ctx.Plan() @@ -3239,9 +3410,11 @@ func TestContext2Plan_ignoreChangesWithFlatmaps(t *testing.T) { } ctx := testContext2(t, &ContextOpts{ Module: m, - Providers: map[string]ResourceProviderFactory{ - "aws": testProviderFuncFixed(p), - }, + ProviderResolver: ResourceProviderResolverFixed( + map[string]ResourceProviderFactory{ + "aws": testProviderFuncFixed(p), + }, + ), State: s, }) @@ -3338,9 +3511,11 @@ func TestContext2Plan_resourceNestedCount(t *testing.T) { } ctx := testContext2(t, &ContextOpts{ Module: m, - Providers: map[string]ResourceProviderFactory{ - "aws": testProviderFuncFixed(p), - }, + ProviderResolver: ResourceProviderResolverFixed( + map[string]ResourceProviderFactory{ + "aws": testProviderFuncFixed(p), + }, + ), State: s, }) diff --git a/terraform/context_refresh_test.go b/terraform/context_refresh_test.go index 0276b05d5..0a977b4cc 100644 --- a/terraform/context_refresh_test.go +++ b/terraform/context_refresh_test.go @@ -13,9 +13,11 @@ func TestContext2Refresh(t *testing.T) { m := testModule(t, "refresh-basic") ctx := testContext2(t, &ContextOpts{ Module: m, - Providers: map[string]ResourceProviderFactory{ - "aws": testProviderFuncFixed(p), - }, + ProviderResolver: ResourceProviderResolverFixed( + map[string]ResourceProviderFactory{ + "aws": testProviderFuncFixed(p), + }, + ), State: &State{ Modules: []*ModuleState{ &ModuleState{ @@ -65,9 +67,11 @@ func TestContext2Refresh_dataComputedModuleVar(t *testing.T) { m := testModule(t, "refresh-data-module-var") ctx := testContext2(t, &ContextOpts{ Module: m, - Providers: map[string]ResourceProviderFactory{ - "aws": testProviderFuncFixed(p), - }, + ProviderResolver: ResourceProviderResolverFixed( + map[string]ResourceProviderFactory{ + "aws": testProviderFuncFixed(p), + }, + ), }) p.RefreshFn = nil @@ -91,9 +95,11 @@ func TestContext2Refresh_targeted(t *testing.T) { m := testModule(t, "refresh-targeted") ctx := testContext2(t, &ContextOpts{ Module: m, - Providers: map[string]ResourceProviderFactory{ - "aws": testProviderFuncFixed(p), - }, + ProviderResolver: ResourceProviderResolverFixed( + map[string]ResourceProviderFactory{ + "aws": testProviderFuncFixed(p), + }, + ), State: &State{ Modules: []*ModuleState{ &ModuleState{ @@ -132,9 +138,11 @@ func TestContext2Refresh_targetedCount(t *testing.T) { m := testModule(t, "refresh-targeted-count") ctx := testContext2(t, &ContextOpts{ Module: m, - Providers: map[string]ResourceProviderFactory{ - "aws": testProviderFuncFixed(p), - }, + ProviderResolver: ResourceProviderResolverFixed( + map[string]ResourceProviderFactory{ + "aws": testProviderFuncFixed(p), + }, + ), State: &State{ Modules: []*ModuleState{ &ModuleState{ @@ -183,9 +191,11 @@ func TestContext2Refresh_targetedCountIndex(t *testing.T) { m := testModule(t, "refresh-targeted-count") ctx := testContext2(t, &ContextOpts{ Module: m, - Providers: map[string]ResourceProviderFactory{ - "aws": testProviderFuncFixed(p), - }, + ProviderResolver: ResourceProviderResolverFixed( + map[string]ResourceProviderFactory{ + "aws": testProviderFuncFixed(p), + }, + ), State: &State{ Modules: []*ModuleState{ &ModuleState{ @@ -226,9 +236,11 @@ func TestContext2Refresh_moduleComputedVar(t *testing.T) { m := testModule(t, "refresh-module-computed-var") ctx := testContext2(t, &ContextOpts{ Module: m, - Providers: map[string]ResourceProviderFactory{ - "aws": testProviderFuncFixed(p), - }, + ProviderResolver: ResourceProviderResolverFixed( + map[string]ResourceProviderFactory{ + "aws": testProviderFuncFixed(p), + }, + ), }) // This was failing (see GH-2188) at some point, so this test just @@ -243,9 +255,11 @@ func TestContext2Refresh_delete(t *testing.T) { m := testModule(t, "refresh-basic") ctx := testContext2(t, &ContextOpts{ Module: m, - Providers: map[string]ResourceProviderFactory{ - "aws": testProviderFuncFixed(p), - }, + ProviderResolver: ResourceProviderResolverFixed( + map[string]ResourceProviderFactory{ + "aws": testProviderFuncFixed(p), + }, + ), State: &State{ Modules: []*ModuleState{ &ModuleState{ @@ -282,9 +296,11 @@ func TestContext2Refresh_ignoreUncreated(t *testing.T) { m := testModule(t, "refresh-basic") ctx := testContext2(t, &ContextOpts{ Module: m, - Providers: map[string]ResourceProviderFactory{ - "aws": testProviderFuncFixed(p), - }, + ProviderResolver: ResourceProviderResolverFixed( + map[string]ResourceProviderFactory{ + "aws": testProviderFuncFixed(p), + }, + ), State: nil, }) @@ -309,9 +325,11 @@ func TestContext2Refresh_hook(t *testing.T) { ctx := testContext2(t, &ContextOpts{ Module: m, Hooks: []Hook{h}, - Providers: map[string]ResourceProviderFactory{ - "aws": testProviderFuncFixed(p), - }, + ProviderResolver: ResourceProviderResolverFixed( + map[string]ResourceProviderFactory{ + "aws": testProviderFuncFixed(p), + }, + ), State: &State{ Modules: []*ModuleState{ &ModuleState{ @@ -373,9 +391,11 @@ func TestContext2Refresh_modules(t *testing.T) { } ctx := testContext2(t, &ContextOpts{ Module: m, - Providers: map[string]ResourceProviderFactory{ - "aws": testProviderFuncFixed(p), - }, + ProviderResolver: ResourceProviderResolverFixed( + map[string]ResourceProviderFactory{ + "aws": testProviderFuncFixed(p), + }, + ), State: state, }) @@ -406,9 +426,11 @@ func TestContext2Refresh_moduleInputComputedOutput(t *testing.T) { p.DiffFn = testDiffFn ctx := testContext2(t, &ContextOpts{ Module: m, - Providers: map[string]ResourceProviderFactory{ - "aws": testProviderFuncFixed(p), - }, + ProviderResolver: ResourceProviderResolverFixed( + map[string]ResourceProviderFactory{ + "aws": testProviderFuncFixed(p), + }, + ), }) if _, err := ctx.Refresh(); err != nil { @@ -422,9 +444,11 @@ func TestContext2Refresh_moduleVarModule(t *testing.T) { p.DiffFn = testDiffFn ctx := testContext2(t, &ContextOpts{ Module: m, - Providers: map[string]ResourceProviderFactory{ - "aws": testProviderFuncFixed(p), - }, + ProviderResolver: ResourceProviderResolverFixed( + map[string]ResourceProviderFactory{ + "aws": testProviderFuncFixed(p), + }, + ), }) if _, err := ctx.Refresh(); err != nil { @@ -438,9 +462,11 @@ func TestContext2Refresh_noState(t *testing.T) { m := testModule(t, "refresh-no-state") ctx := testContext2(t, &ContextOpts{ Module: m, - Providers: map[string]ResourceProviderFactory{ - "aws": testProviderFuncFixed(p), - }, + ProviderResolver: ResourceProviderResolverFixed( + map[string]ResourceProviderFactory{ + "aws": testProviderFuncFixed(p), + }, + ), }) p.RefreshFn = nil @@ -458,9 +484,11 @@ func TestContext2Refresh_output(t *testing.T) { m := testModule(t, "refresh-output") ctx := testContext2(t, &ContextOpts{ Module: m, - Providers: map[string]ResourceProviderFactory{ - "aws": testProviderFuncFixed(p), - }, + ProviderResolver: ResourceProviderResolverFixed( + map[string]ResourceProviderFactory{ + "aws": testProviderFuncFixed(p), + }, + ), State: &State{ Modules: []*ModuleState{ &ModuleState{ @@ -510,9 +538,11 @@ func TestContext2Refresh_outputPartial(t *testing.T) { m := testModule(t, "refresh-output-partial") ctx := testContext2(t, &ContextOpts{ Module: m, - Providers: map[string]ResourceProviderFactory{ - "aws": testProviderFuncFixed(p), - }, + ProviderResolver: ResourceProviderResolverFixed( + map[string]ResourceProviderFactory{ + "aws": testProviderFuncFixed(p), + }, + ), State: &State{ Modules: []*ModuleState{ &ModuleState{ @@ -566,9 +596,11 @@ func TestContext2Refresh_stateBasic(t *testing.T) { } ctx := testContext2(t, &ContextOpts{ Module: m, - Providers: map[string]ResourceProviderFactory{ - "aws": testProviderFuncFixed(p), - }, + ProviderResolver: ResourceProviderResolverFixed( + map[string]ResourceProviderFactory{ + "aws": testProviderFuncFixed(p), + }, + ), State: state, }) @@ -615,9 +647,11 @@ func TestContext2Refresh_dataOrphan(t *testing.T) { }, } ctx := testContext2(t, &ContextOpts{ - Providers: map[string]ResourceProviderFactory{ - "null": testProviderFuncFixed(p), - }, + ProviderResolver: ResourceProviderResolverFixed( + map[string]ResourceProviderFactory{ + "null": testProviderFuncFixed(p), + }, + ), State: state, }) @@ -645,9 +679,11 @@ func TestContext2Refresh_dataState(t *testing.T) { } ctx := testContext2(t, &ContextOpts{ Module: m, - Providers: map[string]ResourceProviderFactory{ - "null": testProviderFuncFixed(p), - }, + ProviderResolver: ResourceProviderResolverFixed( + map[string]ResourceProviderFactory{ + "null": testProviderFuncFixed(p), + }, + ), State: state, }) @@ -715,9 +751,11 @@ func TestContext2Refresh_dataStateRefData(t *testing.T) { } ctx := testContext2(t, &ContextOpts{ Module: m, - Providers: map[string]ResourceProviderFactory{ - "null": testProviderFuncFixed(p), - }, + ProviderResolver: ResourceProviderResolverFixed( + map[string]ResourceProviderFactory{ + "null": testProviderFuncFixed(p), + }, + ), State: state, }) @@ -757,9 +795,11 @@ func TestContext2Refresh_tainted(t *testing.T) { } ctx := testContext2(t, &ContextOpts{ Module: m, - Providers: map[string]ResourceProviderFactory{ - "aws": testProviderFuncFixed(p), - }, + ProviderResolver: ResourceProviderResolverFixed( + map[string]ResourceProviderFactory{ + "aws": testProviderFuncFixed(p), + }, + ), State: state, }) @@ -793,9 +833,13 @@ func TestContext2Refresh_unknownProvider(t *testing.T) { p := testProvider("aws") p.ApplyFn = testApplyFn p.DiffFn = testDiffFn - ctx := testContext2(t, &ContextOpts{ - Module: m, - Providers: map[string]ResourceProviderFactory{}, + + _, err := NewContext(&ContextOpts{ + Module: m, + ProviderResolver: ResourceProviderResolverFixed( + map[string]ResourceProviderFactory{}, + ), + Shadow: true, State: &State{ Modules: []*ModuleState{ &ModuleState{ @@ -813,8 +857,12 @@ func TestContext2Refresh_unknownProvider(t *testing.T) { }, }) - if _, err := ctx.Refresh(); err == nil { - t.Fatal("should error") + if err == nil { + t.Fatal("successfully created context; want error") + } + + if !strings.Contains(err.Error(), "Can't satisfy provider requirements") { + t.Fatalf("wrong error: %s", err) } } @@ -823,9 +871,11 @@ func TestContext2Refresh_vars(t *testing.T) { m := testModule(t, "refresh-vars") ctx := testContext2(t, &ContextOpts{ Module: m, - Providers: map[string]ResourceProviderFactory{ - "aws": testProviderFuncFixed(p), - }, + ProviderResolver: ResourceProviderResolverFixed( + map[string]ResourceProviderFactory{ + "aws": testProviderFuncFixed(p), + }, + ), State: &State{ Modules: []*ModuleState{ @@ -957,9 +1007,11 @@ func TestContext2Refresh_orphanModule(t *testing.T) { } ctx := testContext2(t, &ContextOpts{ Module: m, - Providers: map[string]ResourceProviderFactory{ - "aws": testProviderFuncFixed(p), - }, + ProviderResolver: ResourceProviderResolverFixed( + map[string]ResourceProviderFactory{ + "aws": testProviderFuncFixed(p), + }, + ), State: state, }) @@ -982,9 +1034,11 @@ func TestContext2Validate(t *testing.T) { m := testModule(t, "validate-good") c := testContext2(t, &ContextOpts{ Module: m, - Providers: map[string]ResourceProviderFactory{ - "aws": testProviderFuncFixed(p), - }, + ProviderResolver: ResourceProviderResolverFixed( + map[string]ResourceProviderFactory{ + "aws": testProviderFuncFixed(p), + }, + ), }) w, e := c.Validate() diff --git a/terraform/context_validate_test.go b/terraform/context_validate_test.go index e2442e823..4e9ab910d 100644 --- a/terraform/context_validate_test.go +++ b/terraform/context_validate_test.go @@ -11,9 +11,11 @@ func TestContext2Validate_badCount(t *testing.T) { m := testModule(t, "validate-bad-count") c := testContext2(t, &ContextOpts{ Module: m, - Providers: map[string]ResourceProviderFactory{ - "aws": testProviderFuncFixed(p), - }, + ProviderResolver: ResourceProviderResolverFixed( + map[string]ResourceProviderFactory{ + "aws": testProviderFuncFixed(p), + }, + ), }) w, e := c.Validate() @@ -30,9 +32,11 @@ func TestContext2Validate_badVar(t *testing.T) { m := testModule(t, "validate-bad-var") c := testContext2(t, &ContextOpts{ Module: m, - Providers: map[string]ResourceProviderFactory{ - "aws": testProviderFuncFixed(p), - }, + ProviderResolver: ResourceProviderResolverFixed( + map[string]ResourceProviderFactory{ + "aws": testProviderFuncFixed(p), + }, + ), }) w, e := c.Validate() @@ -49,9 +53,11 @@ func TestContext2Validate_varMapOverrideOld(t *testing.T) { p := testProvider("aws") c := testContext2(t, &ContextOpts{ Module: m, - Providers: map[string]ResourceProviderFactory{ - "aws": testProviderFuncFixed(p), - }, + ProviderResolver: ResourceProviderResolverFixed( + map[string]ResourceProviderFactory{ + "aws": testProviderFuncFixed(p), + }, + ), Variables: map[string]interface{}{ "foo.foo": "bar", }, @@ -86,10 +92,12 @@ func TestContext2Validate_computedVar(t *testing.T) { m := testModule(t, "validate-computed-var") c := testContext2(t, &ContextOpts{ Module: m, - Providers: map[string]ResourceProviderFactory{ - "aws": testProviderFuncFixed(p), - "test": testProviderFuncFixed(testProvider("test")), - }, + ProviderResolver: ResourceProviderResolverFixed( + map[string]ResourceProviderFactory{ + "aws": testProviderFuncFixed(p), + "test": testProviderFuncFixed(testProvider("test")), + }, + ), }) p.ValidateFn = func(c *ResourceConfig) ([]string, []error) { @@ -123,9 +131,11 @@ func TestContext2Validate_countComputed(t *testing.T) { m := testModule(t, "validate-count-computed") c := testContext2(t, &ContextOpts{ Module: m, - Providers: map[string]ResourceProviderFactory{ - "aws": testProviderFuncFixed(p), - }, + ProviderResolver: ResourceProviderResolverFixed( + map[string]ResourceProviderFactory{ + "aws": testProviderFuncFixed(p), + }, + ), }) w, e := c.Validate() @@ -142,9 +152,11 @@ func TestContext2Validate_countNegative(t *testing.T) { m := testModule(t, "validate-count-negative") c := testContext2(t, &ContextOpts{ Module: m, - Providers: map[string]ResourceProviderFactory{ - "aws": testProviderFuncFixed(p), - }, + ProviderResolver: ResourceProviderResolverFixed( + map[string]ResourceProviderFactory{ + "aws": testProviderFuncFixed(p), + }, + ), }) w, e := c.Validate() @@ -161,9 +173,11 @@ func TestContext2Validate_countVariable(t *testing.T) { m := testModule(t, "apply-count-variable") c := testContext2(t, &ContextOpts{ Module: m, - Providers: map[string]ResourceProviderFactory{ - "aws": testProviderFuncFixed(p), - }, + ProviderResolver: ResourceProviderResolverFixed( + map[string]ResourceProviderFactory{ + "aws": testProviderFuncFixed(p), + }, + ), }) w, e := c.Validate() @@ -180,9 +194,11 @@ func TestContext2Validate_countVariableNoDefault(t *testing.T) { m := testModule(t, "validate-count-variable") c := testContext2(t, &ContextOpts{ Module: m, - Providers: map[string]ResourceProviderFactory{ - "aws": testProviderFuncFixed(p), - }, + ProviderResolver: ResourceProviderResolverFixed( + map[string]ResourceProviderFactory{ + "aws": testProviderFuncFixed(p), + }, + ), }) w, e := c.Validate() @@ -201,9 +217,11 @@ func TestContext2Validate_cycle(t *testing.T) { m := testModule(t, "validate-cycle") c := testContext2(t, &ContextOpts{ Module: m, - Providers: map[string]ResourceProviderFactory{ - "aws": testProviderFuncFixed(p), - }, + ProviderResolver: ResourceProviderResolverFixed( + map[string]ResourceProviderFactory{ + "aws": testProviderFuncFixed(p), + }, + ), }) w, e := c.Validate() @@ -221,9 +239,11 @@ func TestContext2Validate_moduleBadOutput(t *testing.T) { m := testModule(t, "validate-bad-module-output") c := testContext2(t, &ContextOpts{ Module: m, - Providers: map[string]ResourceProviderFactory{ - "aws": testProviderFuncFixed(p), - }, + ProviderResolver: ResourceProviderResolverFixed( + map[string]ResourceProviderFactory{ + "aws": testProviderFuncFixed(p), + }, + ), }) w, e := c.Validate() @@ -240,9 +260,11 @@ func TestContext2Validate_moduleGood(t *testing.T) { m := testModule(t, "validate-good-module") c := testContext2(t, &ContextOpts{ Module: m, - Providers: map[string]ResourceProviderFactory{ - "aws": testProviderFuncFixed(p), - }, + ProviderResolver: ResourceProviderResolverFixed( + map[string]ResourceProviderFactory{ + "aws": testProviderFuncFixed(p), + }, + ), }) w, e := c.Validate() @@ -259,9 +281,11 @@ func TestContext2Validate_moduleBadResource(t *testing.T) { p := testProvider("aws") c := testContext2(t, &ContextOpts{ Module: m, - Providers: map[string]ResourceProviderFactory{ - "aws": testProviderFuncFixed(p), - }, + ProviderResolver: ResourceProviderResolverFixed( + map[string]ResourceProviderFactory{ + "aws": testProviderFuncFixed(p), + }, + ), }) p.ValidateResourceReturnErrors = []error{fmt.Errorf("bad")} @@ -280,9 +304,11 @@ func TestContext2Validate_moduleDepsShouldNotCycle(t *testing.T) { p := testProvider("aws") ctx := testContext2(t, &ContextOpts{ Module: m, - Providers: map[string]ResourceProviderFactory{ - "aws": testProviderFuncFixed(p), - }, + ProviderResolver: ResourceProviderResolverFixed( + map[string]ResourceProviderFactory{ + "aws": testProviderFuncFixed(p), + }, + ), }) w, e := ctx.Validate() @@ -300,9 +326,11 @@ func TestContext2Validate_moduleProviderInherit(t *testing.T) { p := testProvider("aws") c := testContext2(t, &ContextOpts{ Module: m, - Providers: map[string]ResourceProviderFactory{ - "aws": testProviderFuncFixed(p), - }, + ProviderResolver: ResourceProviderResolverFixed( + map[string]ResourceProviderFactory{ + "aws": testProviderFuncFixed(p), + }, + ), }) p.ValidateFn = func(c *ResourceConfig) ([]string, []error) { @@ -323,9 +351,11 @@ func TestContext2Validate_moduleProviderInheritOrphan(t *testing.T) { p := testProvider("aws") c := testContext2(t, &ContextOpts{ Module: m, - Providers: map[string]ResourceProviderFactory{ - "aws": testProviderFuncFixed(p), - }, + ProviderResolver: ResourceProviderResolverFixed( + map[string]ResourceProviderFactory{ + "aws": testProviderFuncFixed(p), + }, + ), State: &State{ Modules: []*ModuleState{ &ModuleState{ @@ -369,9 +399,11 @@ func TestContext2Validate_moduleProviderVar(t *testing.T) { p := testProvider("aws") c := testContext2(t, &ContextOpts{ Module: m, - Providers: map[string]ResourceProviderFactory{ - "aws": testProviderFuncFixed(p), - }, + ProviderResolver: ResourceProviderResolverFixed( + map[string]ResourceProviderFactory{ + "aws": testProviderFuncFixed(p), + }, + ), Variables: map[string]interface{}{ "provider_var": "bar", }, @@ -395,9 +427,11 @@ func TestContext2Validate_moduleProviderInheritUnused(t *testing.T) { p := testProvider("aws") c := testContext2(t, &ContextOpts{ Module: m, - Providers: map[string]ResourceProviderFactory{ - "aws": testProviderFuncFixed(p), - }, + ProviderResolver: ResourceProviderResolverFixed( + map[string]ResourceProviderFactory{ + "aws": testProviderFuncFixed(p), + }, + ), }) p.ValidateFn = func(c *ResourceConfig) ([]string, []error) { @@ -433,9 +467,11 @@ func TestContext2Validate_orphans(t *testing.T) { } c := testContext2(t, &ContextOpts{ Module: m, - Providers: map[string]ResourceProviderFactory{ - "aws": testProviderFuncFixed(p), - }, + ProviderResolver: ResourceProviderResolverFixed( + map[string]ResourceProviderFactory{ + "aws": testProviderFuncFixed(p), + }, + ), State: state, }) @@ -458,9 +494,11 @@ func TestContext2Validate_providerConfig_bad(t *testing.T) { p := testProvider("aws") c := testContext2(t, &ContextOpts{ Module: m, - Providers: map[string]ResourceProviderFactory{ - "aws": testProviderFuncFixed(p), - }, + ProviderResolver: ResourceProviderResolverFixed( + map[string]ResourceProviderFactory{ + "aws": testProviderFuncFixed(p), + }, + ), }) p.ValidateReturnErrors = []error{fmt.Errorf("bad")} @@ -482,9 +520,11 @@ func TestContext2Validate_providerConfig_badEmpty(t *testing.T) { p := testProvider("aws") c := testContext2(t, &ContextOpts{ Module: m, - Providers: map[string]ResourceProviderFactory{ - "aws": testProviderFuncFixed(p), - }, + ProviderResolver: ResourceProviderResolverFixed( + map[string]ResourceProviderFactory{ + "aws": testProviderFuncFixed(p), + }, + ), }) p.ValidateReturnErrors = []error{fmt.Errorf("bad")} @@ -503,9 +543,11 @@ func TestContext2Validate_providerConfig_good(t *testing.T) { p := testProvider("aws") c := testContext2(t, &ContextOpts{ Module: m, - Providers: map[string]ResourceProviderFactory{ - "aws": testProviderFuncFixed(p), - }, + ProviderResolver: ResourceProviderResolverFixed( + map[string]ResourceProviderFactory{ + "aws": testProviderFuncFixed(p), + }, + ), }) w, e := c.Validate() @@ -523,9 +565,11 @@ func TestContext2Validate_provisionerConfig_bad(t *testing.T) { pr := testProvisioner() c := testContext2(t, &ContextOpts{ Module: m, - Providers: map[string]ResourceProviderFactory{ - "aws": testProviderFuncFixed(p), - }, + ProviderResolver: ResourceProviderResolverFixed( + map[string]ResourceProviderFactory{ + "aws": testProviderFuncFixed(p), + }, + ), Provisioners: map[string]ResourceProvisionerFactory{ "shell": testProvisionerFuncFixed(pr), }, @@ -554,9 +598,11 @@ func TestContext2Validate_provisionerConfig_good(t *testing.T) { } c := testContext2(t, &ContextOpts{ Module: m, - Providers: map[string]ResourceProviderFactory{ - "aws": testProviderFuncFixed(p), - }, + ProviderResolver: ResourceProviderResolverFixed( + map[string]ResourceProviderFactory{ + "aws": testProviderFuncFixed(p), + }, + ), Provisioners: map[string]ResourceProvisionerFactory{ "shell": testProvisionerFuncFixed(pr), }, @@ -576,9 +622,11 @@ func TestContext2Validate_requiredVar(t *testing.T) { p := testProvider("aws") c := testContext2(t, &ContextOpts{ Module: m, - Providers: map[string]ResourceProviderFactory{ - "aws": testProviderFuncFixed(p), - }, + ProviderResolver: ResourceProviderResolverFixed( + map[string]ResourceProviderFactory{ + "aws": testProviderFuncFixed(p), + }, + ), }) w, e := c.Validate() @@ -595,9 +643,11 @@ func TestContext2Validate_resourceConfig_bad(t *testing.T) { p := testProvider("aws") c := testContext2(t, &ContextOpts{ Module: m, - Providers: map[string]ResourceProviderFactory{ - "aws": testProviderFuncFixed(p), - }, + ProviderResolver: ResourceProviderResolverFixed( + map[string]ResourceProviderFactory{ + "aws": testProviderFuncFixed(p), + }, + ), }) p.ValidateResourceReturnErrors = []error{fmt.Errorf("bad")} @@ -616,9 +666,11 @@ func TestContext2Validate_resourceConfig_good(t *testing.T) { p := testProvider("aws") c := testContext2(t, &ContextOpts{ Module: m, - Providers: map[string]ResourceProviderFactory{ - "aws": testProviderFuncFixed(p), - }, + ProviderResolver: ResourceProviderResolverFixed( + map[string]ResourceProviderFactory{ + "aws": testProviderFuncFixed(p), + }, + ), }) w, e := c.Validate() @@ -635,9 +687,11 @@ func TestContext2Validate_resourceNameSymbol(t *testing.T) { m := testModule(t, "validate-resource-name-symbol") c := testContext2(t, &ContextOpts{ Module: m, - Providers: map[string]ResourceProviderFactory{ - "aws": testProviderFuncFixed(p), - }, + ProviderResolver: ResourceProviderResolverFixed( + map[string]ResourceProviderFactory{ + "aws": testProviderFuncFixed(p), + }, + ), }) w, e := c.Validate() @@ -654,9 +708,11 @@ func TestContext2Validate_selfRef(t *testing.T) { m := testModule(t, "validate-self-ref") c := testContext2(t, &ContextOpts{ Module: m, - Providers: map[string]ResourceProviderFactory{ - "aws": testProviderFuncFixed(p), - }, + ProviderResolver: ResourceProviderResolverFixed( + map[string]ResourceProviderFactory{ + "aws": testProviderFuncFixed(p), + }, + ), }) w, e := c.Validate() @@ -673,9 +729,11 @@ func TestContext2Validate_selfRefMulti(t *testing.T) { m := testModule(t, "validate-self-ref-multi") c := testContext2(t, &ContextOpts{ Module: m, - Providers: map[string]ResourceProviderFactory{ - "aws": testProviderFuncFixed(p), - }, + ProviderResolver: ResourceProviderResolverFixed( + map[string]ResourceProviderFactory{ + "aws": testProviderFuncFixed(p), + }, + ), }) w, e := c.Validate() @@ -692,9 +750,11 @@ func TestContext2Validate_selfRefMultiAll(t *testing.T) { m := testModule(t, "validate-self-ref-multi-all") c := testContext2(t, &ContextOpts{ Module: m, - Providers: map[string]ResourceProviderFactory{ - "aws": testProviderFuncFixed(p), - }, + ProviderResolver: ResourceProviderResolverFixed( + map[string]ResourceProviderFactory{ + "aws": testProviderFuncFixed(p), + }, + ), }) w, e := c.Validate() @@ -727,9 +787,11 @@ func TestContext2Validate_tainted(t *testing.T) { } c := testContext2(t, &ContextOpts{ Module: m, - Providers: map[string]ResourceProviderFactory{ - "aws": testProviderFuncFixed(p), - }, + ProviderResolver: ResourceProviderResolverFixed( + map[string]ResourceProviderFactory{ + "aws": testProviderFuncFixed(p), + }, + ), State: state, }) @@ -755,9 +817,11 @@ func TestContext2Validate_targetedDestroy(t *testing.T) { p.DiffFn = testDiffFn ctx := testContext2(t, &ContextOpts{ Module: m, - Providers: map[string]ResourceProviderFactory{ - "aws": testProviderFuncFixed(p), - }, + ProviderResolver: ResourceProviderResolverFixed( + map[string]ResourceProviderFactory{ + "aws": testProviderFuncFixed(p), + }, + ), Provisioners: map[string]ResourceProvisionerFactory{ "shell": testProvisionerFuncFixed(pr), }, @@ -794,9 +858,11 @@ func TestContext2Validate_varRefFilled(t *testing.T) { p := testProvider("aws") c := testContext2(t, &ContextOpts{ Module: m, - Providers: map[string]ResourceProviderFactory{ - "aws": testProviderFuncFixed(p), - }, + ProviderResolver: ResourceProviderResolverFixed( + map[string]ResourceProviderFactory{ + "aws": testProviderFuncFixed(p), + }, + ), Variables: map[string]interface{}{ "foo": "bar", }, @@ -826,9 +892,11 @@ func TestContext2Validate_interpolateVar(t *testing.T) { ctx := testContext2(t, &ContextOpts{ Module: m, - Providers: map[string]ResourceProviderFactory{ - "template": testProviderFuncFixed(p), - }, + ProviderResolver: ResourceProviderResolverFixed( + map[string]ResourceProviderFactory{ + "template": testProviderFuncFixed(p), + }, + ), UIInput: input, }) @@ -853,9 +921,11 @@ func TestContext2Validate_interpolateComputedModuleVarDef(t *testing.T) { ctx := testContext2(t, &ContextOpts{ Module: m, - Providers: map[string]ResourceProviderFactory{ - "aws": testProviderFuncFixed(p), - }, + ProviderResolver: ResourceProviderResolverFixed( + map[string]ResourceProviderFactory{ + "aws": testProviderFuncFixed(p), + }, + ), UIInput: input, }) @@ -879,9 +949,11 @@ func TestContext2Validate_interpolateMap(t *testing.T) { ctx := testContext2(t, &ContextOpts{ Module: m, - Providers: map[string]ResourceProviderFactory{ - "template": testProviderFuncFixed(p), - }, + ProviderResolver: ResourceProviderResolverFixed( + map[string]ResourceProviderFactory{ + "template": testProviderFuncFixed(p), + }, + ), UIInput: input, }) @@ -902,9 +974,11 @@ func TestContext2Validate_PlanGraphBuilder(t *testing.T) { p.DiffFn = testDiffFn c := testContext2(t, &ContextOpts{ Module: m, - Providers: map[string]ResourceProviderFactory{ - "aws": testProviderFuncFixed(p), - }, + ProviderResolver: ResourceProviderResolverFixed( + map[string]ResourceProviderFactory{ + "aws": testProviderFuncFixed(p), + }, + ), Variables: map[string]interface{}{ "foo": "us-west-2", "test_list": []interface{}{"Hello", "World"}, diff --git a/terraform/debug_test.go b/terraform/debug_test.go index b80111fc7..6e75116cd 100644 --- a/terraform/debug_test.go +++ b/terraform/debug_test.go @@ -98,9 +98,11 @@ func TestDebug_plan(t *testing.T) { p.DiffFn = testDiffFn ctx := testContext2(t, &ContextOpts{ Module: m, - Providers: map[string]ResourceProviderFactory{ - "aws": testProviderFuncFixed(p), - }, + ProviderResolver: ResourceProviderResolverFixed( + map[string]ResourceProviderFactory{ + "aws": testProviderFuncFixed(p), + }, + ), }) _, err = ctx.Plan()