@ -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" , a bsA ddr, ctx . Path ( ) ) )
panic ( fmt . Sprintf ( "%s initialized by wrong module %s" , a ddr, ctx . Path ( ) ) )
}
// If we already initialized, it is an error
if p := ctx . Provider ( a bsA ddr) ; p != nil {
if p := ctx . Provider ( a ddr) ; 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 := a bsA ddr. String ( )
key := a ddr. 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 ( ) , a bsA ddr)
log . Printf ( "[TRACE] BuiltinEvalContext: Initialized %q provider for %s" , addr . LegacyString ( ) , a ddr)
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" , a bsA ddr, ctx . Path ( ) ) )
panic ( fmt . Sprintf ( "%s configured by wrong module %s" , a ddr, ctx . Path ( ) ) )
}
p := ctx . Provider ( a bsA ddr)
p := ctx . Provider ( a ddr)
if p == nil {
diags = diags . Append ( fmt . Errorf ( "%s not initialized" , addr ) )
return diags
}
providerSchema := ctx . ProviderSchema ( a bsA ddr)
providerSchema := ctx . ProviderSchema ( a ddr)
if providerSchema == nil {
diags = diags . Append ( fmt . Errorf ( "schema for %s is not available" , a bsA ddr) )
diags = diags . Append ( fmt . Errorf ( "schema for %s is not available" , a ddr) )
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 ( ) {
}