func (n *graphNodeProxyProvider) Target() GraphNodeProvider {
	switch t := n.target.(type) {
	case *graphNodeProxyProvider:
		return t.Target()
	default:
		return n.target
	}
}
find the concrete provider instance
package terraform
import (
	"fmt"
	"log"
	"github.com/hashicorp/hcl/v2"
	"github.com/hashicorp/terraform/addrs"
	"github.com/hashicorp/terraform/configs"
	"github.com/hashicorp/terraform/dag"
	"github.com/hashicorp/terraform/tfdiags"
)
func TransformProviders(providers []string, concrete ConcreteProviderNodeFunc, config *configs.Config) GraphTransformer {
	return GraphTransformMulti(
		&ProviderConfigTransformer{
			Config:    config,
			Providers: providers,
			Concrete:  concrete,
		},
		&MissingProviderTransformer{
			Providers: providers,
			Concrete:  concrete,
		},
		&ProviderTransformer{
			Config: config,
		},
		&PruneProviderTransformer{},
		&ParentProviderTransformer{},
	)
}
type GraphNodeProvider interface {
	GraphNodeSubPath
	ProviderAddr() addrs.AbsProviderConfig
	Name() string
}
type GraphNodeCloseProvider interface {
	GraphNodeSubPath
	CloseProviderAddr() addrs.AbsProviderConfig
}
type GraphNodeProviderConsumer interface {
	ProvidedBy() (addr addrs.AbsProviderConfig, exact bool)
	SetProvider(addrs.AbsProviderConfig)
}
type ProviderTransformer struct {
	Config *configs.Config
}
func (t *ProviderTransformer) Transform(g *Graph) error {
	var diags tfdiags.Diagnostics
	type ProviderRequest struct {
		Addr  addrs.AbsProviderConfig
		Exact bool  
	}
	requested := map[dag.Vertex]map[string]ProviderRequest{}
	needConfigured := map[string]addrs.AbsProviderConfig{}
	for _, v := range g.Vertices() {
		if _, ok := v.(GraphNodeNoProvider); ok {
			continue
		}
		if pv, ok := v.(GraphNodeProviderConsumer); ok {
			requested[v] = make(map[string]ProviderRequest)
			p, exact := pv.ProvidedBy()
			if exact {
				log.Printf("[TRACE] ProviderTransformer: %s is provided by %s exactly", dag.VertexName(v), p)
			} else {
				log.Printf("[TRACE] ProviderTransformer: %s is provided by %s or inherited equivalent", dag.VertexName(v), p)
			}
			requested[v][p.String()] = ProviderRequest{
				Addr:  p,
				Exact: exact,
			}
			needConfigured[p.String()] = p
		}
	}
	m := providerVertexMap(g)
	for v, reqs := range requested {
		for key, req := range reqs {
			p := req.Addr
			target := m[key]
			_, ok := v.(GraphNodeSubPath)
			if !ok && target == nil {
				diags = diags.Append(fmt.Errorf("%s: provider %s couldn't be found", dag.VertexName(v), p))
				continue
			}
			if target != nil {
				log.Printf("[TRACE] ProviderTransformer: exact match for %s serving %s", p, dag.VertexName(v))
			}
			if target == nil && !req.Exact {
				for pp, ok := p.Inherited(); ok; pp, ok = pp.Inherited() {
					key := pp.String()
					target = m[key]
					if target != nil {
						log.Printf("[TRACE] ProviderTransformer: %s uses inherited configuration %s", dag.VertexName(v), pp)
						break
					}
					log.Printf("[TRACE] ProviderTransformer: looking for %s to serve %s", pp, dag.VertexName(v))
				}
			}
			if _, exists := needConfigured[key]; target == nil && !exists {
				stubAddr := p.ProviderConfig.Absolute(addrs.RootModuleInstance)
				stub := &NodeEvalableProvider{
					&NodeAbstractProvider{
						Addr: stubAddr,
					},
				}
				m[stubAddr.String()] = stub
				log.Printf("[TRACE] ProviderTransformer: creating init-only node for %s", stubAddr)
				target = stub
				g.Add(target)
			}
			if target == nil {
				diags = diags.Append(tfdiags.Sourceless(
					tfdiags.Error,
					"Provider configuration not present",
					fmt.Sprintf(
						"To work with %s its original provider configuration at %s is required, but it has been removed. This occurs when a provider configuration is removed while objects created by that provider still exist in the state. Re-add the provider configuration to destroy %s, after which you can remove the provider configuration again.",
						dag.VertexName(v), p, dag.VertexName(v),
					),
				))
				break
			}
			if p, ok := target.(*graphNodeProxyProvider); ok {
				g.Remove(p)
				target = p.Target()
				key = target.(GraphNodeProvider).ProviderAddr().String()
			}
			log.Printf("[DEBUG] ProviderTransformer: %q (%T) needs %s", dag.VertexName(v), v, dag.VertexName(target))
			if pv, ok := v.(GraphNodeProviderConsumer); ok {
				pv.SetProvider(target.ProviderAddr())
			}
			g.Connect(dag.BasicEdge(v, target))
		}
	}
	return diags.Err()
}
type CloseProviderTransformer struct{}
func (t *CloseProviderTransformer) Transform(g *Graph) error {
	pm := providerVertexMap(g)
	cpm := make(map[string]*graphNodeCloseProvider)
	var err error
	for _, v := range pm {
		p := v.(GraphNodeProvider)
		key := p.ProviderAddr().String()
		closer := cpm[key]
		if closer == nil {
			closer = &graphNodeCloseProvider{Addr: p.ProviderAddr()}
			g.Add(closer)
			cpm[key] = closer
		}
		g.Connect(dag.BasicEdge(closer, p))
		for _, s := range g.UpEdges(p).List() {
			if _, ok := s.(GraphNodeProviderConsumer); ok {
				g.Connect(dag.BasicEdge(closer, s))
			}
		}
	}
	return err
}
type MissingProviderTransformer struct {
	Providers []string
	Concrete ConcreteProviderNodeFunc
}
func (t *MissingProviderTransformer) Transform(g *Graph) error {
	if t.Concrete == nil {
		t.Concrete = func(a *NodeAbstractProvider) dag.Vertex {
			return a
		}
	}
	var err error
	m := providerVertexMap(g)
	for _, v := range g.Vertices() {
		if _, ok := v.(GraphNodeNoProvider); ok {
			continue
		}
		pv, ok := v.(GraphNodeProviderConsumer)
		if !ok {
			continue
		}
		p, _ := pv.ProvidedBy()
		if p.ProviderConfig.Alias != "" {
			log.Println("[TRACE] MissingProviderTransformer: skipping implication of aliased config", p)
			continue
		}
		defaultAddr := addrs.RootModuleInstance.ProviderConfigDefault(p.ProviderConfig.Type.LegacyString())
		key := defaultAddr.String()
		provider := m[key]
		if provider != nil {
			continue
		}
		log.Printf("[DEBUG] adding implicit provider configuration %s, implied first by %s", defaultAddr, dag.VertexName(v))
		provider = t.Concrete(&NodeAbstractProvider{
			Addr: defaultAddr,
		}).(GraphNodeProvider)
		g.Add(provider)
		m[key] = provider
	}
	return err
}
type ParentProviderTransformer struct{}
func (t *ParentProviderTransformer) Transform(g *Graph) error {
	pm := providerVertexMap(g)
	for _, v := range g.Vertices() {
		pn, ok := v.(GraphNodeProvider)
		if !ok {
			continue
		}
		if len(pn.Path()) <= 1 {
			continue
		}
		addr := pn.ProviderAddr()
		parentAddr, ok := addr.Inherited()
		if ok {
			parent := pm[parentAddr.String()]
			if parent != nil {
				g.Connect(dag.BasicEdge(v, parent))
			}
		}
	}
	return nil
}
type PruneProviderTransformer struct{}
func (t *PruneProviderTransformer) Transform(g *Graph) error {
	for _, v := range g.Vertices() {
		_, ok := v.(GraphNodeProvider)
		if !ok {
			continue
		}
		if _, ok := v.(*graphNodeProxyProvider); ok {
			log.Printf("[DEBUG] pruning proxy %s", dag.VertexName(v))
			g.Remove(v)
		}
		if g.UpEdges(v).Len() == 0 {
			log.Printf("[DEBUG] pruning unused %s", dag.VertexName(v))
			g.Remove(v)
		}
	}
	return nil
}
func providerVertexMap(g *Graph) map[string]GraphNodeProvider {
	m := make(map[string]GraphNodeProvider)
	for _, v := range g.Vertices() {
		if pv, ok := v.(GraphNodeProvider); ok {
			addr := pv.ProviderAddr()
			m[addr.String()] = pv
		}
	}
	return m
}
func closeProviderVertexMap(g *Graph) map[string]GraphNodeCloseProvider {
	m := make(map[string]GraphNodeCloseProvider)
	for _, v := range g.Vertices() {
		if pv, ok := v.(GraphNodeCloseProvider); ok {
			addr := pv.CloseProviderAddr()
			m[addr.String()] = pv
		}
	}
	return m
}
type graphNodeCloseProvider struct {
	Addr addrs.AbsProviderConfig
}
var (
	_ GraphNodeCloseProvider = (*graphNodeCloseProvider)(nil)
)
func (n *graphNodeCloseProvider) Name() string {
	return n.Addr.String() + " (close)"
}
func (n *graphNodeCloseProvider) Path() addrs.ModuleInstance {
	return n.Addr.Module
}
func (n *graphNodeCloseProvider) EvalTree() EvalNode {
	return CloseProviderEvalTree(n.Addr)
}
func (n *graphNodeCloseProvider) DependableName() []string {
	return []string{n.Name()}
}
func (n *graphNodeCloseProvider) CloseProviderAddr() addrs.AbsProviderConfig {
	return n.Addr
}
func (n *graphNodeCloseProvider) DotNode(name string, opts *dag.DotOpts) *dag.DotNode {
	if !opts.Verbose {
		return nil
	}
	return &dag.DotNode{
		Name: name,
		Attrs: map[string]string{
			"label": n.Name(),
			"shape": "diamond",
		},
	}
}
func (n *graphNodeCloseProvider) RemoveIfNotTargeted() bool {
	return true
}
type graphNodeProxyProvider struct {
	addr   addrs.AbsProviderConfig
	target GraphNodeProvider
}
var (
	_ GraphNodeProvider = (*graphNodeProxyProvider)(nil)
)
func (n *graphNodeProxyProvider) ProviderAddr() addrs.AbsProviderConfig {
	return n.addr
}
func (n *graphNodeProxyProvider) Path() addrs.ModuleInstance {
	return n.addr.Module
}
func (n *graphNodeProxyProvider) Name() string {
	return n.addr.String() + " (proxy)"
}