4 "github.com/hashicorp/terraform/dag"
7 // NodeValidatableResource represents a resource that is used for validation
9 type NodeValidatableResource struct {
10 *NodeAbstractCountResource
14 func (n *NodeValidatableResource) EvalTree() EvalNode {
15 // Ensure we're validating
16 c := n.NodeAbstractCountResource
21 // GraphNodeDynamicExpandable
22 func (n *NodeValidatableResource) DynamicExpand(ctx EvalContext) (*Graph, error) {
23 // Grab the state which we read
24 state, lock := ctx.State()
28 // Expand the resource count which must be available by now from EvalTree
30 if n.Config.RawCount.Value() != unknownValue() {
32 count, err = n.Config.Count()
38 // The concrete resource factory we'll use
39 concreteResource := func(a *NodeAbstractResource) dag.Vertex {
40 // Add the config and state since we don't do that via transforms
43 return &NodeValidatableResourceInstance{
44 NodeAbstractResource: a,
48 // Start creating the steps
49 steps := []GraphTransformer{
51 &ResourceCountTransformer{
52 Concrete: concreteResource,
54 Addr: n.ResourceAddr(),
58 &AttachStateTransformer{State: state},
61 &TargetsTransformer{ParsedTargets: n.Targets},
63 // Connect references so ordering is correct
64 &ReferenceTransformer{},
66 // Make sure there is a single root
71 b := &BasicGraphBuilder{
74 Name: "NodeValidatableResource",
77 return b.Build(ctx.Path())
80 // This represents a _single_ resource instance to validate.
81 type NodeValidatableResourceInstance struct {
86 func (n *NodeValidatableResourceInstance) EvalTree() EvalNode {
87 addr := n.NodeAbstractResource.Addr
89 // Build the resource for eval
90 resource := &Resource{
93 CountIndex: addr.Index,
95 if resource.CountIndex < 0 {
96 resource.CountIndex = 0
99 // Declare a bunch of variables that are used for state during
100 // evaluation. Most of this are written to by-address below.
101 var config *ResourceConfig
102 var provider ResourceProvider
104 seq := &EvalSequence{
106 &EvalValidateResourceSelfRef{
108 Config: &n.Config.RawConfig,
111 Name: n.ProvidedBy()[0],
115 Config: n.Config.RawConfig.Copy(),
119 &EvalValidateResource{
122 ResourceName: n.Config.Name,
123 ResourceType: n.Config.Type,
124 ResourceMode: n.Config.Mode,
129 // Validate all the provisioners
130 for _, p := range n.Config.Provisioners {
131 var provisioner ResourceProvisioner
132 var connConfig *ResourceConfig
137 Output: &provisioner,
140 Config: p.RawConfig.Copy(),
145 Config: p.ConnInfo.Copy(),
149 &EvalValidateProvisioner{
150 Provisioner: &provisioner,
152 ConnConfig: &connConfig,