@@ -27,29 +27,44 @@ func rawRichParameterNames(workdir string) ([]string, error) {
27
27
28
28
var coderParameterNames []string
29
29
for _ , entry := range entries {
30
- if ! strings .HasSuffix (entry .Name (), ".tf" ) {
30
+ if ! strings .HasSuffix (entry .Name (), ".tf" ) && ! strings . HasSuffix ( entry . Name (), ".tf.json" ) {
31
31
continue
32
32
}
33
33
34
- hclFilepath := path .Join (workdir , entry .Name ())
35
- parser := hclparse .NewParser ()
36
- parsedHCL , diags := parser .ParseHCLFile (hclFilepath )
34
+ var (
35
+ parsedTF * hcl.File
36
+ diags hcl.Diagnostics
37
+ tfFilepath = path .Join (workdir , entry .Name ())
38
+ parser = hclparse .NewParser ()
39
+ )
40
+
41
+ // Support .tf.json files.
42
+ // Warning: since JSON parsing in Go automatically sorts maps
43
+ // alphabetically, we can't preserve the original order of parameters
44
+ // like in HCL.
45
+ if strings .HasSuffix (entry .Name (), ".tf.json" ) {
46
+ parsedTF , diags = parser .ParseJSONFile (tfFilepath )
47
+ } else {
48
+ parsedTF , diags = parser .ParseHCLFile (tfFilepath )
49
+ }
50
+
37
51
if diags .HasErrors () {
38
52
return nil , hcl.Diagnostics {
39
53
{
40
54
Severity : hcl .DiagError ,
41
55
Summary : "Failed to parse HCL file" ,
42
- Detail : fmt .Sprintf ("parser.ParseHCLFile can't parse %q file" , hclFilepath ),
56
+ Detail : fmt .Sprintf ("parser.ParseHCLFile can't parse %q file" , tfFilepath ),
43
57
},
44
58
}
45
59
}
46
60
47
- content , _ , _ := parsedHCL .Body .PartialContent (terraformWithCoderParametersSchema )
61
+ content , _ , _ := parsedTF .Body .PartialContent (terraformWithCoderParametersSchema )
48
62
for _ , block := range content .Blocks {
49
63
if block .Type == "data" && block .Labels [0 ] == "coder_parameter" && len (block .Labels ) == 2 {
50
64
coderParameterNames = append (coderParameterNames , block .Labels [1 ])
51
65
}
52
66
}
53
67
}
68
+
54
69
return coderParameterNames , nil
55
70
}
0 commit comments