diff --git a/terraform/context_import_test.go b/terraform/context_import_test.go index 1f9bc21d2..1475ccfa4 100644 --- a/terraform/context_import_test.go +++ b/terraform/context_import_test.go @@ -597,7 +597,7 @@ func TestContextImport_moduleDiff(t *testing.T) { Mode: addrs.ManagedResourceMode, Type: "aws_instance", Name: "bar", - }.Instance(addrs.NoKey).Absolute(addrs.Module{"bar"}.UnkeyedInstanceShim()), + }.Instance(addrs.NoKey).Absolute(addrs.RootModuleInstance.Child("bar", addrs.NoKey)), &states.ResourceInstanceObjectSrc{ AttrsFlat: map[string]string{ "id": "bar", @@ -658,7 +658,7 @@ func TestContextImport_moduleExisting(t *testing.T) { Mode: addrs.ManagedResourceMode, Type: "aws_instance", Name: "bar", - }.Instance(addrs.NoKey).Absolute(addrs.Module{"foo"}.UnkeyedInstanceShim()), + }.Instance(addrs.NoKey).Absolute(addrs.RootModuleInstance.Child("foo", addrs.NoKey)), &states.ResourceInstanceObjectSrc{ AttrsFlat: map[string]string{ "id": "bar", diff --git a/terraform/eval_context_builtin.go b/terraform/eval_context_builtin.go index c5cae2194..746b00fe1 100644 --- a/terraform/eval_context_builtin.go +++ b/terraform/eval_context_builtin.go @@ -65,8 +65,6 @@ type BuiltinEvalContext struct { ChangesValue *plans.ChangesSync StateValue *states.SyncState InstanceExpanderValue *instances.Expander - - once sync.Once } // BuiltinEvalContext implements EvalContext @@ -106,16 +104,14 @@ 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().Module()) { + if !addr.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())) + panic(fmt.Sprintf("%s initialized by wrong module %s", addr, ctx.Path())) } // If we already initialized, it is an error - if p := ctx.Provider(absAddr); p != nil { + if p := ctx.Provider(addr); p != nil { return nil, fmt.Errorf("%s is already initialized", addr) } @@ -124,22 +120,20 @@ func (ctx *BuiltinEvalContext) InitProvider(addr addrs.AbsProviderConfig) (provi ctx.ProviderLock.Lock() defer ctx.ProviderLock.Unlock() - key := absAddr.String() + key := addr.String() p, err := ctx.Components.ResourceProvider(addr.Provider) if err != nil { return nil, err } - log.Printf("[TRACE] BuiltinEvalContext: Initialized %q provider for %s", addr.LegacyString(), absAddr) + log.Printf("[TRACE] BuiltinEvalContext: Initialized %q provider for %s", addr.LegacyString(), addr) ctx.ProviderCache[key] = p return p, nil } func (ctx *BuiltinEvalContext) Provider(addr addrs.AbsProviderConfig) providers.Interface { - ctx.once.Do(ctx.init) - ctx.ProviderLock.Lock() defer ctx.ProviderLock.Unlock() @@ -147,12 +141,10 @@ func (ctx *BuiltinEvalContext) Provider(addr addrs.AbsProviderConfig) providers. } func (ctx *BuiltinEvalContext) ProviderSchema(addr addrs.AbsProviderConfig) *ProviderSchema { - ctx.once.Do(ctx.init) return ctx.Schemas.ProviderSchema(addr.Provider) } func (ctx *BuiltinEvalContext) CloseProvider(addr addrs.AbsProviderConfig) error { - ctx.once.Do(ctx.init) 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. @@ -174,22 +166,21 @@ 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().Module()) { + if !addr.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())) + panic(fmt.Sprintf("%s configured by wrong module %s", addr, ctx.Path())) } - p := ctx.Provider(absAddr) + p := ctx.Provider(addr) if p == nil { diags = diags.Append(fmt.Errorf("%s not initialized", addr)) return diags } - providerSchema := ctx.ProviderSchema(absAddr) + providerSchema := ctx.ProviderSchema(addr) if providerSchema == nil { - diags = diags.Append(fmt.Errorf("schema for %s is not available", absAddr)) + diags = diags.Append(fmt.Errorf("schema for %s is not available", addr)) return diags } @@ -241,8 +232,6 @@ func (ctx *BuiltinEvalContext) SetProviderInput(pc addrs.AbsProviderConfig, c ma } func (ctx *BuiltinEvalContext) InitProvisioner(n string) (provisioners.Interface, error) { - ctx.once.Do(ctx.init) - // If we already initialized, it is an error if p := ctx.Provisioner(n); p != nil { return nil, fmt.Errorf("Provisioner '%s' already initialized", n) @@ -264,8 +253,6 @@ func (ctx *BuiltinEvalContext) InitProvisioner(n string) (provisioners.Interface } func (ctx *BuiltinEvalContext) Provisioner(n string) provisioners.Interface { - ctx.once.Do(ctx.init) - ctx.ProvisionerLock.Lock() defer ctx.ProvisionerLock.Unlock() @@ -273,14 +260,10 @@ func (ctx *BuiltinEvalContext) Provisioner(n string) provisioners.Interface { } func (ctx *BuiltinEvalContext) ProvisionerSchema(n string) *configschema.Block { - ctx.once.Do(ctx.init) - return ctx.Schemas.ProvisionerConfig(n) } func (ctx *BuiltinEvalContext) CloseProvisioner(n string) error { - ctx.once.Do(ctx.init) - ctx.ProvisionerLock.Lock() defer ctx.ProvisionerLock.Unlock() @@ -361,6 +344,3 @@ func (ctx *BuiltinEvalContext) State() *states.SyncState { func (ctx *BuiltinEvalContext) InstanceExpander() *instances.Expander { return ctx.InstanceExpanderValue } - -func (ctx *BuiltinEvalContext) init() { -} diff --git a/terraform/node_provider_abstract.go b/terraform/node_provider_abstract.go index 871caefc5..5c30364ee 100644 --- a/terraform/node_provider_abstract.go +++ b/terraform/node_provider_abstract.go @@ -41,6 +41,8 @@ func (n *NodeAbstractProvider) Name() string { // GraphNodeModuleInstance func (n *NodeAbstractProvider) Path() addrs.ModuleInstance { + // Providers cannot be contained inside an expanded module, so this shim + // converts our module path to the correct ModuleInstance. return n.Addr.Module.UnkeyedInstanceShim() } diff --git a/terraform/node_provider_disabled.go b/terraform/node_provider_disabled.go index fc66f2e60..6f7a6d27e 100644 --- a/terraform/node_provider_disabled.go +++ b/terraform/node_provider_disabled.go @@ -14,7 +14,7 @@ type NodeDisabledProvider struct { } var ( - _ GraphNodeModuleInstance = (*NodeDisabledProvider)(nil) + _ GraphNodeModulePath = (*NodeDisabledProvider)(nil) _ RemovableIfNotTargeted = (*NodeDisabledProvider)(nil) _ GraphNodeReferencer = (*NodeDisabledProvider)(nil) _ GraphNodeProvider = (*NodeDisabledProvider)(nil) diff --git a/terraform/transform_attach_config_provider.go b/terraform/transform_attach_config_provider.go index e1cf66362..d2e3d69de 100644 --- a/terraform/transform_attach_config_provider.go +++ b/terraform/transform_attach_config_provider.go @@ -8,9 +8,6 @@ import ( // GraphNodeAttachProvider is an interface that must be implemented by nodes // that want provider configurations attached. type GraphNodeAttachProvider interface { - // Must be implemented to determine the path for the configuration - GraphNodeModuleInstance - // ProviderName with no module prefix. Example: "aws". ProviderAddr() addrs.AbsProviderConfig