6 "github.com/hashicorp/terraform/config"
9 // NodeRefreshableResource represents a resource that is "applyable":
10 // it is ready to be applied and is represented by a diff.
11 type NodeRefreshableResource struct {
16 func (n *NodeRefreshableResource) DestroyAddr() *ResourceAddress {
21 func (n *NodeRefreshableResource) EvalTree() EvalNode {
22 // Eval info is different depending on what kind of resource this is
23 switch mode := n.Addr.Mode; mode {
24 case config.ManagedResourceMode:
25 return n.evalTreeManagedResource()
27 case config.DataResourceMode:
28 // Get the data source node. If we don't have a configuration
29 // then it is an orphan so we destroy it (remove it from the state).
30 var dn GraphNodeEvalable
32 dn = &NodeRefreshableDataResourceInstance{
33 NodeAbstractResource: n.NodeAbstractResource,
36 dn = &NodeDestroyableDataResource{
37 NodeAbstractResource: n.NodeAbstractResource,
43 panic(fmt.Errorf("unsupported resource mode %s", mode))
47 func (n *NodeRefreshableResource) evalTreeManagedResource() EvalNode {
48 addr := n.NodeAbstractResource.Addr
50 // stateId is the ID to put into the state
51 stateId := addr.stateId()
53 // Build the instance info. More of this will be populated during eval
54 info := &InstanceInfo{
59 // Declare a bunch of variables that are used for state during
60 // evaluation. Most of this are written to by-address below.
61 var provider ResourceProvider
62 var state *InstanceState
64 // This happened during initial development. All known cases were
65 // fixed and tested but as a sanity check let's assert here.
66 if n.ResourceState == nil {
68 "No resource state attached for addr: %s\n\n"+
69 "This is a bug. Please report this to Terraform with your configuration\n"+
70 "and state attached. Please be careful to scrub any sensitive information.",
72 return &EvalReturnError{Error: &err}
78 Name: n.ProvidedBy()[0],
93 ResourceType: n.ResourceState.Type,
94 Provider: n.ResourceState.Provider,
95 Dependencies: n.ResourceState.Dependencies,