Skip to content

Commit

Permalink
convert /terraform to use new provider config
Browse files Browse the repository at this point in the history
Change all ModuleInstances in provider types to plain Modules
  • Loading branch information
jbardin committed Mar 11, 2020
1 parent 8497adc commit 98cfb51
Show file tree
Hide file tree
Showing 18 changed files with 98 additions and 108 deletions.
50 changes: 25 additions & 25 deletions terraform/context_apply_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -1333,7 +1333,7 @@ func TestContext2Apply_destroyDependsOnStateOnly(t *testing.T) {
},
addrs.AbsProviderConfig{
Provider: addrs.NewLegacyProvider("aws"),
Module: addrs.RootModuleInstance,
Module: addrs.RootModule,
},
)
root.SetResourceInstanceCurrent(
Expand All @@ -1358,7 +1358,7 @@ func TestContext2Apply_destroyDependsOnStateOnly(t *testing.T) {
},
addrs.AbsProviderConfig{
Provider: addrs.NewLegacyProvider("aws"),
Module: addrs.RootModuleInstance,
Module: addrs.RootModule,
},
)

Expand Down Expand Up @@ -1431,7 +1431,7 @@ func TestContext2Apply_destroyDependsOnStateOnlyModule(t *testing.T) {
},
addrs.AbsProviderConfig{
Provider: addrs.NewLegacyProvider("aws"),
Module: addrs.RootModuleInstance,
Module: addrs.RootModule,
},
)
child.SetResourceInstanceCurrent(
Expand All @@ -1456,7 +1456,7 @@ func TestContext2Apply_destroyDependsOnStateOnlyModule(t *testing.T) {
},
addrs.AbsProviderConfig{
Provider: addrs.NewLegacyProvider("aws"),
Module: addrs.RootModuleInstance,
Module: addrs.RootModule,
},
)

Expand Down Expand Up @@ -2828,7 +2828,7 @@ func TestContext2Apply_orphanResource(t *testing.T) {
want := states.BuildState(func(s *states.SyncState) {
providerAddr := addrs.AbsProviderConfig{
Provider: addrs.NewLegacyProvider("test"),
Module: addrs.RootModuleInstance,
Module: addrs.RootModule,
}
zeroAddr := addrs.Resource{
Mode: addrs.ManagedResourceMode,
Expand Down Expand Up @@ -7051,7 +7051,7 @@ func TestContext2Apply_errorDestroy(t *testing.T) {
},
addrs.AbsProviderConfig{
Provider: addrs.NewLegacyProvider("test"),
Module: addrs.RootModuleInstance,
Module: addrs.RootModule,
},
)
}),
Expand Down Expand Up @@ -7191,7 +7191,7 @@ func TestContext2Apply_errorUpdateNullNew(t *testing.T) {
},
addrs.AbsProviderConfig{
Provider: addrs.NewLegacyProvider("aws"),
Module: addrs.RootModuleInstance,
Module: addrs.RootModule,
},
)
}),
Expand Down Expand Up @@ -8618,7 +8618,7 @@ func TestContext2Apply_createBefore_depends(t *testing.T) {
},
addrs.AbsProviderConfig{
Provider: addrs.NewLegacyProvider("aws"),
Module: addrs.RootModuleInstance,
Module: addrs.RootModule,
},
)

Expand All @@ -8644,7 +8644,7 @@ func TestContext2Apply_createBefore_depends(t *testing.T) {
},
addrs.AbsProviderConfig{
Provider: addrs.NewLegacyProvider("aws"),
Module: addrs.RootModuleInstance,
Module: addrs.RootModule,
},
)

Expand Down Expand Up @@ -8751,7 +8751,7 @@ func TestContext2Apply_singleDestroy(t *testing.T) {
},
addrs.AbsProviderConfig{
Provider: addrs.NewLegacyProvider("aws"),
Module: addrs.RootModuleInstance,
Module: addrs.RootModule,
},
)

Expand All @@ -8777,7 +8777,7 @@ func TestContext2Apply_singleDestroy(t *testing.T) {
},
addrs.AbsProviderConfig{
Provider: addrs.NewLegacyProvider("aws"),
Module: addrs.RootModuleInstance,
Module: addrs.RootModule,
},
)

Expand Down Expand Up @@ -9684,7 +9684,7 @@ func TestContext2Apply_destroyWithProviders(t *testing.T) {
state.Modules["module.mod.module.removed"].Resources["aws_instance.child"].ProviderConfig = addrs.AbsProviderConfig{
Provider: addrs.NewLegacyProvider("aws"),
Alias: "bar",
Module: addrs.RootModuleInstance,
Module: addrs.RootModule,
}

if _, diags := ctx.Plan(); diags.HasErrors() {
Expand Down Expand Up @@ -10108,7 +10108,7 @@ func TestContext2Apply_issue19908(t *testing.T) {
},
addrs.AbsProviderConfig{
Provider: addrs.NewLegacyProvider("test"),
Module: addrs.RootModuleInstance,
Module: addrs.RootModule,
},
)
}),
Expand Down Expand Up @@ -10236,7 +10236,7 @@ func TestContext2Apply_moduleReplaceCycle(t *testing.T) {
},
addrs.AbsProviderConfig{
Provider: addrs.NewLegacyProvider("aws"),
Module: addrs.RootModuleInstance,
Module: addrs.RootModule,
},
)

Expand All @@ -10253,7 +10253,7 @@ func TestContext2Apply_moduleReplaceCycle(t *testing.T) {
},
addrs.AbsProviderConfig{
Provider: addrs.NewLegacyProvider("aws"),
Module: addrs.RootModuleInstance,
Module: addrs.RootModule,
},
)

Expand Down Expand Up @@ -10296,7 +10296,7 @@ func TestContext2Apply_moduleReplaceCycle(t *testing.T) {
}.Instance(addrs.NoKey).Absolute(addrs.RootModuleInstance.Child("a", addrs.NoKey)),
ProviderAddr: addrs.AbsProviderConfig{
Provider: addrs.NewLegacyProvider("aws"),
Module: addrs.RootModuleInstance,
Module: addrs.RootModule,
},
ChangeSrc: plans.ChangeSrc{
Action: aAction,
Expand All @@ -10312,7 +10312,7 @@ func TestContext2Apply_moduleReplaceCycle(t *testing.T) {
}.Instance(addrs.IntKey(0)).Absolute(addrs.RootModuleInstance.Child("b", addrs.NoKey)),
ProviderAddr: addrs.AbsProviderConfig{
Provider: addrs.NewLegacyProvider("aws"),
Module: addrs.RootModuleInstance,
Module: addrs.RootModule,
},
ChangeSrc: plans.ChangeSrc{
Action: plans.DeleteThenCreate,
Expand Down Expand Up @@ -10363,7 +10363,7 @@ func TestContext2Apply_destroyDataCycle(t *testing.T) {
},
addrs.AbsProviderConfig{
Provider: addrs.NewLegacyProvider("null"),
Module: addrs.RootModuleInstance,
Module: addrs.RootModule,
},
)
root.SetResourceInstanceCurrent(
Expand All @@ -10378,7 +10378,7 @@ func TestContext2Apply_destroyDataCycle(t *testing.T) {
},
addrs.AbsProviderConfig{
Provider: addrs.NewLegacyProvider("null"),
Module: addrs.RootModuleInstance,
Module: addrs.RootModule,
},
)

Expand Down Expand Up @@ -10453,7 +10453,7 @@ func TestContext2Apply_taintedDestroyFailure(t *testing.T) {
},
addrs.AbsProviderConfig{
Provider: addrs.NewLegacyProvider("test"),
Module: addrs.RootModuleInstance,
Module: addrs.RootModule,
},
)
root.SetResourceInstanceCurrent(
Expand All @@ -10468,7 +10468,7 @@ func TestContext2Apply_taintedDestroyFailure(t *testing.T) {
},
addrs.AbsProviderConfig{
Provider: addrs.NewLegacyProvider("test"),
Module: addrs.RootModuleInstance,
Module: addrs.RootModule,
},
)
root.SetResourceInstanceCurrent(
Expand All @@ -10483,7 +10483,7 @@ func TestContext2Apply_taintedDestroyFailure(t *testing.T) {
},
addrs.AbsProviderConfig{
Provider: addrs.NewLegacyProvider("test"),
Module: addrs.RootModuleInstance,
Module: addrs.RootModule,
},
)

Expand Down Expand Up @@ -10660,7 +10660,7 @@ func TestContext2Apply_cbdCycle(t *testing.T) {
},
addrs.AbsProviderConfig{
Provider: addrs.NewLegacyProvider("test"),
Module: addrs.RootModuleInstance,
Module: addrs.RootModule,
},
)
root.SetResourceInstanceCurrent(
Expand All @@ -10685,7 +10685,7 @@ func TestContext2Apply_cbdCycle(t *testing.T) {
},
addrs.AbsProviderConfig{
Provider: addrs.NewLegacyProvider("test"),
Module: addrs.RootModuleInstance,
Module: addrs.RootModule,
},
)
root.SetResourceInstanceCurrent(
Expand All @@ -10700,7 +10700,7 @@ func TestContext2Apply_cbdCycle(t *testing.T) {
},
addrs.AbsProviderConfig{
Provider: addrs.NewLegacyProvider("test"),
Module: addrs.RootModuleInstance,
Module: addrs.RootModule,
},
)

Expand Down
6 changes: 3 additions & 3 deletions terraform/context_import_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -117,7 +117,7 @@ func TestContextImport_collision(t *testing.T) {
},
addrs.AbsProviderConfig{
Provider: addrs.NewLegacyProvider("aws"),
Module: addrs.RootModuleInstance,
Module: addrs.RootModule,
},
)
}),
Expand Down Expand Up @@ -606,7 +606,7 @@ func TestContextImport_moduleDiff(t *testing.T) {
},
addrs.AbsProviderConfig{
Provider: addrs.NewLegacyProvider("aws"),
Module: addrs.RootModuleInstance,
Module: addrs.RootModule,
},
)
}),
Expand Down Expand Up @@ -667,7 +667,7 @@ func TestContextImport_moduleExisting(t *testing.T) {
},
addrs.AbsProviderConfig{
Provider: addrs.NewLegacyProvider("aws"),
Module: addrs.RootModuleInstance,
Module: addrs.RootModule,
},
)
}),
Expand Down
2 changes: 1 addition & 1 deletion terraform/context_input.go
Original file line number Diff line number Diff line change
Expand Up @@ -160,7 +160,7 @@ func (c *Context) Input(mode InputMode) tfdiags.Diagnostics {
absConfigAddr := addrs.AbsProviderConfig{
Provider: providerFqn,
Alias: pa.Alias,
Module: c.Config().Path.UnkeyedInstanceShim(),
Module: c.Config().Path,
}
c.providerInputConfig[absConfigAddr.String()] = vals

Expand Down
2 changes: 1 addition & 1 deletion terraform/context_input_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -480,7 +480,7 @@ func TestContext2Input_dataSourceRequiresRefresh(t *testing.T) {
},
addrs.AbsProviderConfig{
Provider: addrs.NewLegacyProvider("null"),
Module: addrs.RootModuleInstance,
Module: addrs.RootModule,
},
)
})
Expand Down
2 changes: 1 addition & 1 deletion terraform/context_plan_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -5052,7 +5052,7 @@ func TestContext2Plan_ignoreChangesInMap(t *testing.T) {
},
addrs.AbsProviderConfig{
Provider: addrs.NewLegacyProvider("test"),
Module: addrs.RootModuleInstance,
Module: addrs.RootModule,
},
)
})
Expand Down
10 changes: 5 additions & 5 deletions terraform/context_refresh_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -105,7 +105,7 @@ func TestContext2Refresh_dynamicAttr(t *testing.T) {
},
addrs.AbsProviderConfig{
Provider: addrs.NewLegacyProvider("test"),
Module: addrs.RootModuleInstance,
Module: addrs.RootModule,
},
)
})
Expand Down Expand Up @@ -1742,7 +1742,7 @@ func TestContext2Refresh_schemaUpgradeFlatmap(t *testing.T) {
},
addrs.AbsProviderConfig{
Provider: addrs.NewLegacyProvider("test"),
Module: addrs.RootModuleInstance,
Module: addrs.RootModule,
},
)
})
Expand Down Expand Up @@ -1828,7 +1828,7 @@ func TestContext2Refresh_schemaUpgradeJSON(t *testing.T) {
},
addrs.AbsProviderConfig{
Provider: addrs.NewLegacyProvider("test"),
Module: addrs.RootModuleInstance,
Module: addrs.RootModule,
},
)
})
Expand Down Expand Up @@ -1999,7 +1999,7 @@ func TestRefresh_updateDependencies(t *testing.T) {
},
addrs.AbsProviderConfig{
Provider: addrs.NewLegacyProvider("aws"),
Module: addrs.RootModuleInstance,
Module: addrs.RootModule,
},
)
root.SetResourceInstanceCurrent(
Expand All @@ -2014,7 +2014,7 @@ func TestRefresh_updateDependencies(t *testing.T) {
},
addrs.AbsProviderConfig{
Provider: addrs.NewLegacyProvider("aws"),
Module: addrs.RootModuleInstance,
Module: addrs.RootModule,
},
)

Expand Down
10 changes: 5 additions & 5 deletions terraform/eval_context_builtin.go
Original file line number Diff line number Diff line change
Expand Up @@ -108,7 +108,7 @@ func (ctx *BuiltinEvalContext) Input() UIInput {
func (ctx *BuiltinEvalContext) InitProvider(addr addrs.AbsProviderConfig) (providers.Interface, error) {
ctx.once.Do(ctx.init)
absAddr := addr
if !absAddr.Module.Equal(ctx.Path()) {
if !absAddr.Module.Equal(ctx.Path().Module()) {
// This indicates incorrect use of InitProvider: it should be used
// only from the module that the provider configuration belongs to.
panic(fmt.Sprintf("%s initialized by wrong module %s", absAddr, ctx.Path()))
Expand Down Expand Up @@ -153,7 +153,7 @@ func (ctx *BuiltinEvalContext) ProviderSchema(addr addrs.AbsProviderConfig) *Pro

func (ctx *BuiltinEvalContext) CloseProvider(addr addrs.AbsProviderConfig) error {
ctx.once.Do(ctx.init)
if !addr.Module.Equal(ctx.Path()) {
if !addr.Module.Equal(ctx.Path().Module()) {
// This indicates incorrect use of CloseProvider: it should be used
// only from the module that the provider configuration belongs to.
panic(fmt.Sprintf("%s closed by wrong module %s", addr, ctx.Path()))
Expand All @@ -175,7 +175,7 @@ func (ctx *BuiltinEvalContext) CloseProvider(addr addrs.AbsProviderConfig) error
func (ctx *BuiltinEvalContext) ConfigureProvider(addr addrs.AbsProviderConfig, cfg cty.Value) tfdiags.Diagnostics {
var diags tfdiags.Diagnostics
absAddr := addr
if !absAddr.Module.Equal(ctx.Path()) {
if !absAddr.Module.Equal(ctx.Path().Module()) {
// This indicates incorrect use of ConfigureProvider: it should be used
// only from the module that the provider configuration belongs to.
panic(fmt.Sprintf("%s configured by wrong module %s", absAddr, ctx.Path()))
Expand Down Expand Up @@ -206,7 +206,7 @@ func (ctx *BuiltinEvalContext) ProviderInput(pc addrs.AbsProviderConfig) map[str
ctx.ProviderLock.Lock()
defer ctx.ProviderLock.Unlock()

if !pc.Module.Equal(ctx.Path()) {
if !pc.Module.Equal(ctx.Path().Module()) {
// This indicates incorrect use of InitProvider: it should be used
// only from the module that the provider configuration belongs to.
panic(fmt.Sprintf("%s initialized by wrong module %s", pc, ctx.Path()))
Expand All @@ -222,7 +222,7 @@ func (ctx *BuiltinEvalContext) ProviderInput(pc addrs.AbsProviderConfig) map[str

func (ctx *BuiltinEvalContext) SetProviderInput(pc addrs.AbsProviderConfig, c map[string]cty.Value) {
absProvider := pc
if !absProvider.Module.Equal(ctx.Path()) {
if !absProvider.Module.Equal(ctx.Path().Module()) {
// This indicates incorrect use of InitProvider: it should be used
// only from the module that the provider configuration belongs to.
panic(fmt.Sprintf("%s initialized by wrong module %s", absProvider, ctx.Path()))
Expand Down
8 changes: 4 additions & 4 deletions terraform/eval_context_builtin_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -25,11 +25,11 @@ func TestBuiltinEvalContextProviderInput(t *testing.T) {
ctx2.ProviderLock = &lock

providerAddr1 := addrs.AbsProviderConfig{
Module: addrs.RootModuleInstance,
Module: addrs.RootModule,
Provider: addrs.NewLegacyProvider("foo"),
}
providerAddr2 := addrs.AbsProviderConfig{
Module: addrs.RootModuleInstance.Child("child", addrs.NoKey),
Module: addrs.RootModule.Child("child"),
Provider: addrs.NewLegacyProvider("foo"),
}

Expand Down Expand Up @@ -65,11 +65,11 @@ func TestBuildingEvalContextInitProvider(t *testing.T) {
}

providerAddrDefault := addrs.AbsProviderConfig{
Module: addrs.RootModuleInstance,
Module: addrs.RootModule,
Provider: addrs.NewLegacyProvider("test"),
}
providerAddrAlias := addrs.AbsProviderConfig{
Module: addrs.RootModuleInstance,
Module: addrs.RootModule,
Provider: addrs.NewLegacyProvider("test"),
Alias: "foo",
}
Expand Down
Loading

0 comments on commit 98cfb51

Please sign in to comment.