8
8
9
9
"github.com/jumppad-labs/hclconfig/convert"
10
10
"github.com/jumppad-labs/hclconfig/errors"
11
+ "github.com/jumppad-labs/hclconfig/resources"
11
12
"github.com/jumppad-labs/hclconfig/types"
12
13
"github.com/silas/dag"
13
14
"github.com/zclconf/go-cty/cty"
@@ -21,13 +22,13 @@ func doYaLikeDAGs(c *Config) (*dag.AcyclicGraph, error) {
21
22
graph := & dag.AcyclicGraph {}
22
23
23
24
// add a root node for the graph
24
- root , _ := types . DefaultTypes ().CreateResource (types .TypeRoot , "root" )
25
+ root , _ := resources . DefaultResources ().CreateResource (resources .TypeRoot , "root" )
25
26
graph .Add (root )
26
27
27
28
// Loop over all resources and add to graph
28
29
for _ , resource := range c .Resources {
29
30
// ignore variables
30
- if resource .Metadata ().Type != types .TypeVariable {
31
+ if resource .Metadata ().Type != resources .TypeVariable {
31
32
graph .Add (resource )
32
33
}
33
34
}
@@ -37,7 +38,7 @@ func doYaLikeDAGs(c *Config) (*dag.AcyclicGraph, error) {
37
38
hasDeps := false
38
39
39
40
// do nothing with variables
40
- if resource .Metadata ().Type == types .TypeVariable {
41
+ if resource .Metadata ().Type == resources .TypeVariable {
41
42
continue
42
43
}
43
44
@@ -62,7 +63,7 @@ func doYaLikeDAGs(c *Config) (*dag.AcyclicGraph, error) {
62
63
63
64
for _ , d := range resource .GetDependsOn () {
64
65
var err error
65
- fqdn , err := types .ParseFQRN (d )
66
+ fqdn , err := resources .ParseFQRN (d )
66
67
if err != nil {
67
68
pe := errors.ParserError {}
68
69
pe .Line = resource .Metadata ().Line
@@ -75,7 +76,7 @@ func doYaLikeDAGs(c *Config) (*dag.AcyclicGraph, error) {
75
76
}
76
77
77
78
// when the dependency is a module, depend on all resources in the module
78
- if fqdn .Type == types .TypeModule {
79
+ if fqdn .Type == resources .TypeModule {
79
80
// assume that all dependencies references have been written with no
80
81
// knowledge of their parent module. Therefore if the parent module is
81
82
// "module1" and the reference is "module.module2.resource.container.mine.id"
@@ -100,7 +101,7 @@ func doYaLikeDAGs(c *Config) (*dag.AcyclicGraph, error) {
100
101
}
101
102
102
103
// when the dependency is a resource, depend on the resource
103
- if fqdn .Type != types .TypeModule {
104
+ if fqdn .Type != resources .TypeModule {
104
105
// assume that all dependencies references have been written with no
105
106
// knowledge of their parent module. Therefore if the parent module is
106
107
// "module1" and the reference is "module.module2.resource.container.mine.id"
@@ -173,7 +174,7 @@ func createCallback(c *Config, wf WalkCallback) func(v dag.Vertex) (diags dag.Di
173
174
}
174
175
175
176
// if this is the root module or is disabled skip or is a variable
176
- if (r .Metadata ().Type == types .TypeRoot ) || r .GetDisabled () || r .Metadata ().Type == types .TypeVariable {
177
+ if (r .Metadata ().Type == resources .TypeRoot ) || r .GetDisabled () || r .Metadata ().Type == resources .TypeVariable {
177
178
return nil
178
179
}
179
180
@@ -191,7 +192,7 @@ func createCallback(c *Config, wf WalkCallback) func(v dag.Vertex) (diags dag.Di
191
192
// all linked values should now have been processed as the graph
192
193
// will have handled them first
193
194
for _ , v := range r .Metadata ().Links {
194
- fqrn , err := types .ParseFQRN (v )
195
+ fqrn , err := resources .ParseFQRN (v )
195
196
if err != nil {
196
197
pe := errors.ParserError {}
197
198
pe .Filename = r .Metadata ().File
@@ -221,11 +222,11 @@ func createCallback(c *Config, wf WalkCallback) func(v dag.Vertex) (diags dag.Di
221
222
// once we have found a resource convert it to a cty type and then
222
223
// set it on the context
223
224
switch l .Metadata ().Type {
224
- case types .TypeLocal :
225
- loc := l .(* types .Local )
225
+ case resources .TypeLocal :
226
+ loc := l .(* resources .Local )
226
227
ctyRes = loc .CtyValue
227
- case types .TypeOutput :
228
- out := l .(* types .Output )
228
+ case resources .TypeOutput :
229
+ out := l .(* resources .Output )
229
230
ctyRes = out .CtyValue
230
231
default :
231
232
ctyRes , err = convert .GoToCtyValue (l )
@@ -278,7 +279,7 @@ func createCallback(c *Config, wf WalkCallback) func(v dag.Vertex) (diags dag.Di
278
279
// if the type is a module the potentially we only just found out that we should be
279
280
// disabled
280
281
// as an additional check, set all module resources to disabled if the module is disabled
281
- if r .GetDisabled () && r .Metadata ().Type == types .TypeModule {
282
+ if r .GetDisabled () && r .Metadata ().Type == resources .TypeModule {
282
283
// find all dependent resources
283
284
dr , err := c .FindModuleResources (r .Metadata ().ID , true )
284
285
if err != nil {
@@ -304,7 +305,7 @@ func createCallback(c *Config, wf WalkCallback) func(v dag.Vertex) (diags dag.Di
304
305
//
305
306
// if disabled was set through interpolation, the value has only been set here
306
307
// we need to handle an additional check
307
- if ! r .GetDisabled () && r .Metadata ().Type != types .TypeModule {
308
+ if ! r .GetDisabled () && r .Metadata ().Type != resources .TypeModule {
308
309
309
310
// call the callbacks
310
311
if wf != nil {
@@ -324,8 +325,8 @@ func createCallback(c *Config, wf WalkCallback) func(v dag.Vertex) (diags dag.Di
324
325
325
326
// if the type is a module we need to add the variables to the
326
327
// context
327
- if r .Metadata ().Type == types .TypeModule {
328
- mod := r .(* types .Module )
328
+ if r .Metadata ().Type == resources .TypeModule {
329
+ mod := r .(* resources .Module )
329
330
330
331
var mapVars map [string ]cty.Value
331
332
if att , ok := mod .Variables .(* hcl.Attribute ); ok {
@@ -340,16 +341,16 @@ func createCallback(c *Config, wf WalkCallback) func(v dag.Vertex) (diags dag.Di
340
341
341
342
// if this is an output or local we need to convert the value into
342
343
// a go type
343
- if r .Metadata ().Type == types .TypeOutput {
344
- o := r .(* types .Output )
344
+ if r .Metadata ().Type == resources .TypeOutput {
345
+ o := r .(* resources .Output )
345
346
346
347
if ! o .CtyValue .IsNull () {
347
348
o .Value = castVar (o .CtyValue )
348
349
}
349
350
}
350
351
351
- if r .Metadata ().Type == types .TypeLocal {
352
- o := r .(* types .Local )
352
+ if r .Metadata ().Type == resources .TypeLocal {
353
+ o := r .(* resources .Local )
353
354
354
355
if ! o .CtyValue .IsNull () {
355
356
o .Value = castVar (o .CtyValue )
0 commit comments