github.com/hashicorp/terraform-plugin-sdk@v1.17.2/terraform/node_local.go (about)

     1  package terraform
     2  
     3  import (
     4  	"github.com/hashicorp/terraform-plugin-sdk/internal/addrs"
     5  	"github.com/hashicorp/terraform-plugin-sdk/internal/configs"
     6  	"github.com/hashicorp/terraform-plugin-sdk/internal/dag"
     7  	"github.com/hashicorp/terraform-plugin-sdk/internal/lang"
     8  )
     9  
    10  // NodeLocal represents a named local value in a particular module.
    11  //
    12  // Local value nodes only have one operation, common to all walk types:
    13  // evaluate the result and place it in state.
    14  type NodeLocal struct {
    15  	Addr   addrs.AbsLocalValue
    16  	Config *configs.Local
    17  }
    18  
    19  var (
    20  	_ GraphNodeSubPath       = (*NodeLocal)(nil)
    21  	_ RemovableIfNotTargeted = (*NodeLocal)(nil)
    22  	_ GraphNodeReferenceable = (*NodeLocal)(nil)
    23  	_ GraphNodeReferencer    = (*NodeLocal)(nil)
    24  	_ GraphNodeEvalable      = (*NodeLocal)(nil)
    25  	_ dag.GraphNodeDotter    = (*NodeLocal)(nil)
    26  )
    27  
    28  func (n *NodeLocal) Name() string {
    29  	return n.Addr.String()
    30  }
    31  
    32  // GraphNodeSubPath
    33  func (n *NodeLocal) Path() addrs.ModuleInstance {
    34  	return n.Addr.Module
    35  }
    36  
    37  // RemovableIfNotTargeted
    38  func (n *NodeLocal) RemoveIfNotTargeted() bool {
    39  	return true
    40  }
    41  
    42  // GraphNodeReferenceable
    43  func (n *NodeLocal) ReferenceableAddrs() []addrs.Referenceable {
    44  	return []addrs.Referenceable{n.Addr.LocalValue}
    45  }
    46  
    47  // GraphNodeReferencer
    48  func (n *NodeLocal) References() []*addrs.Reference {
    49  	refs, _ := lang.ReferencesInExpr(n.Config.Expr)
    50  	return appendResourceDestroyReferences(refs)
    51  }
    52  
    53  // GraphNodeEvalable
    54  func (n *NodeLocal) EvalTree() EvalNode {
    55  	return &EvalLocal{
    56  		Addr: n.Addr.LocalValue,
    57  		Expr: n.Config.Expr,
    58  	}
    59  }
    60  
    61  // dag.GraphNodeDotter impl.
    62  func (n *NodeLocal) DotNode(name string, opts *dag.DotOpts) *dag.DotNode {
    63  	return &dag.DotNode{
    64  		Name: name,
    65  		Attrs: map[string]string{
    66  			"label": n.Name(),
    67  			"shape": "note",
    68  		},
    69  	}
    70  }