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
42 a.ResolvedProvider = n.ResolvedProvider
44 return &NodeValidatableResourceInstance{
45 NodeAbstractResource: a,
49 // Start creating the steps
50 steps := []GraphTransformer{
52 &ResourceCountTransformer{
53 Concrete: concreteResource,
55 Addr: n.ResourceAddr(),
59 &AttachStateTransformer{State: state},
62 &TargetsTransformer{ParsedTargets: n.Targets},
64 // Connect references so ordering is correct
65 &ReferenceTransformer{},
67 // Make sure there is a single root
72 b := &BasicGraphBuilder{
75 Name: "NodeValidatableResource",
78 return b.Build(ctx.Path())
81 // This represents a _single_ resource instance to validate.
82 type NodeValidatableResourceInstance struct {
87 func (n *NodeValidatableResourceInstance) EvalTree() EvalNode {
88 addr := n.NodeAbstractResource.Addr
90 // Build the resource for eval
91 resource := &Resource{
94 CountIndex: addr.Index,
96 if resource.CountIndex < 0 {
97 resource.CountIndex = 0
100 // Declare a bunch of variables that are used for state during
101 // evaluation. Most of this are written to by-address below.
102 var config *ResourceConfig
103 var provider ResourceProvider
105 seq := &EvalSequence{
107 &EvalValidateResourceSelfRef{
109 Config: &n.Config.RawConfig,
112 Name: n.ResolvedProvider,
116 Config: n.Config.RawConfig.Copy(),
120 &EvalValidateResource{
123 ResourceName: n.Config.Name,
124 ResourceType: n.Config.Type,
125 ResourceMode: n.Config.Mode,
130 // Validate all the provisioners
131 for _, p := range n.Config.Provisioners {
132 var provisioner ResourceProvisioner
133 var connConfig *ResourceConfig
138 Output: &provisioner,
141 Config: p.RawConfig.Copy(),
146 Config: p.ConnInfo.Copy(),
150 &EvalValidateProvisioner{
151 Provisioner: &provisioner,
153 ConnConfig: &connConfig,