github.com/muratcelep/terraform@v1.1.0-beta2-not-internal-4/not-internal/terraform/node_provider_abstract.go (about)

     1  package terraform
     2  
     3  import (
     4  	"github.com/muratcelep/terraform/not-internal/addrs"
     5  	"github.com/muratcelep/terraform/not-internal/configs"
     6  	"github.com/muratcelep/terraform/not-internal/configs/configschema"
     7  
     8  	"github.com/muratcelep/terraform/not-internal/dag"
     9  )
    10  
    11  // ConcreteProviderNodeFunc is a callback type used to convert an
    12  // abstract provider to a concrete one of some type.
    13  type ConcreteProviderNodeFunc func(*NodeAbstractProvider) dag.Vertex
    14  
    15  // NodeAbstractProvider represents a provider that has no associated operations.
    16  // It registers all the common interfaces across operations for providers.
    17  type NodeAbstractProvider struct {
    18  	Addr addrs.AbsProviderConfig
    19  
    20  	// The fields below will be automatically set using the Attach
    21  	// interfaces if you're running those transforms, but also be explicitly
    22  	// set if you already have that information.
    23  
    24  	Config *configs.Provider
    25  	Schema *configschema.Block
    26  }
    27  
    28  var (
    29  	_ GraphNodeModulePath                 = (*NodeAbstractProvider)(nil)
    30  	_ GraphNodeReferencer                 = (*NodeAbstractProvider)(nil)
    31  	_ GraphNodeProvider                   = (*NodeAbstractProvider)(nil)
    32  	_ GraphNodeAttachProvider             = (*NodeAbstractProvider)(nil)
    33  	_ GraphNodeAttachProviderConfigSchema = (*NodeAbstractProvider)(nil)
    34  	_ dag.GraphNodeDotter                 = (*NodeAbstractProvider)(nil)
    35  )
    36  
    37  func (n *NodeAbstractProvider) Name() string {
    38  	return n.Addr.String()
    39  }
    40  
    41  // GraphNodeModuleInstance
    42  func (n *NodeAbstractProvider) Path() addrs.ModuleInstance {
    43  	// Providers cannot be contained inside an expanded module, so this shim
    44  	// converts our module path to the correct ModuleInstance.
    45  	return n.Addr.Module.UnkeyedInstanceShim()
    46  }
    47  
    48  // GraphNodeModulePath
    49  func (n *NodeAbstractProvider) ModulePath() addrs.Module {
    50  	return n.Addr.Module
    51  }
    52  
    53  // GraphNodeReferencer
    54  func (n *NodeAbstractProvider) References() []*addrs.Reference {
    55  	if n.Config == nil || n.Schema == nil {
    56  		return nil
    57  	}
    58  
    59  	return ReferencesFromConfig(n.Config.Config, n.Schema)
    60  }
    61  
    62  // GraphNodeProvider
    63  func (n *NodeAbstractProvider) ProviderAddr() addrs.AbsProviderConfig {
    64  	return n.Addr
    65  }
    66  
    67  // GraphNodeProvider
    68  func (n *NodeAbstractProvider) ProviderConfig() *configs.Provider {
    69  	if n.Config == nil {
    70  		return nil
    71  	}
    72  
    73  	return n.Config
    74  }
    75  
    76  // GraphNodeAttachProvider
    77  func (n *NodeAbstractProvider) AttachProvider(c *configs.Provider) {
    78  	n.Config = c
    79  }
    80  
    81  // GraphNodeAttachProviderConfigSchema impl.
    82  func (n *NodeAbstractProvider) AttachProviderConfigSchema(schema *configschema.Block) {
    83  	n.Schema = schema
    84  }
    85  
    86  // GraphNodeDotter impl.
    87  func (n *NodeAbstractProvider) DotNode(name string, opts *dag.DotOpts) *dag.DotNode {
    88  	return &dag.DotNode{
    89  		Name: name,
    90  		Attrs: map[string]string{
    91  			"label": n.Name(),
    92  			"shape": "diamond",
    93  		},
    94  	}
    95  }