@ -188,11 +188,6 @@ func (t *Tree) Load(s *Storage) error {
// Set our tree up
t . children = children
// if we're the root module, we can now set the provider inheritance
if len ( t . path ) == 0 {
t . inheritProviderConfigs ( nil )
}
return nil
}
@ -348,93 +343,6 @@ func (t *Tree) getChildren(s *Storage) (map[string]*Tree, error) {
return children , nil
}
// inheritProviderConfig resolves all provider config inheritance after the
// tree is loaded.
//
// If there is a provider block without a config, look in the parent's Module
// block for a provider, and fetch that provider's configuration. If that
// doesn't exist, assume a default empty config. Implicit providers can still
// inherit their config all the way up from the root, so walk up the tree and
// copy the first matching provider into the module.
func ( t * Tree ) inheritProviderConfigs ( stack [ ] * Tree ) {
// the recursive calls only append, so we don't need to worry about copying
// this slice.
stack = append ( stack , t )
for _ , c := range t . children {
c . inheritProviderConfigs ( stack )
}
if len ( stack ) == 1 {
return
}
providers := make ( map [ string ] * config . ProviderConfig )
missingProviders := make ( map [ string ] bool )
for _ , p := range t . config . ProviderConfigs {
providers [ p . FullName ( ) ] = p
}
for _ , r := range t . config . Resources {
p := r . ProviderFullName ( )
if _ , ok := providers [ p ] ; ! ( ok || strings . Contains ( p , "." ) ) {
missingProviders [ p ] = true
}
}
// get our parent's module config block
parent := stack [ len ( stack ) - 2 ]
var parentModule * config . Module
for _ , m := range parent . config . Modules {
if m . Name == t . name {
parentModule = m
break
}
}
if parentModule == nil {
panic ( "can't be a module without a parent module config" )
}
// now look for providers that need a config
for p , pc := range providers {
if len ( pc . RawConfig . RawMap ( ) ) > 0 {
log . Printf ( "[TRACE] provider %q has a config, continuing" , p )
continue
}
// this provider has no config yet, check for one being passed in
parentProviderName , ok := parentModule . Providers [ p ]
if ! ok {
continue
}
var parentProvider * config . ProviderConfig
// there's a config for us in the parent module
for _ , pp := range parent . config . ProviderConfigs {
if pp . FullName ( ) == parentProviderName {
parentProvider = pp
break
}
}
if parentProvider == nil {
// no config found, assume defaults
continue
}
// Copy it in, but set an interpolation Scope.
// An interpolation Scope always need to have "root"
pc . Path = append ( [ ] string { RootName } , parent . path ... )
pc . RawConfig = parentProvider . RawConfig
log . Printf ( "[TRACE] provider %q inheriting config from %q" ,
strings . Join ( append ( t . Path ( ) , pc . FullName ( ) ) , "." ) ,
strings . Join ( append ( parent . Path ( ) , parentProvider . FullName ( ) ) , "." ) ,
)
}
}
// Path is the full path to this tree.
func ( t * Tree ) Path ( ) [ ] string {
return t . path