Skip to content

Commit ee79e65

Browse files
authored
chore: implement ExportOutputs locally
2 parents e1bab70 + 3c8e22c commit ee79e65

File tree

2 files changed

+22
-1
lines changed

2 files changed

+22
-1
lines changed

hclext/outputs.go

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
package hclext
2+
3+
import (
4+
"github.com/aquasecurity/trivy/pkg/iac/terraform"
5+
"github.com/zclconf/go-cty/cty"
6+
)
7+
8+
func ExportOutputs(modules terraform.Modules) cty.Value {
9+
data := make(map[string]cty.Value)
10+
for _, block := range modules.GetBlocks().OfType("output") {
11+
attr := block.GetAttribute("value")
12+
if attr.IsNil() {
13+
continue
14+
}
15+
data[block.Label()] = attr.Value()
16+
}
17+
return cty.ObjectVal(data)
18+
}

preview.go

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@ import (
1111
"github.com/hashicorp/hcl/v2"
1212
"github.com/zclconf/go-cty/cty"
1313

14+
"github.com/coder/preview/hclext"
1415
"github.com/coder/preview/types"
1516
)
1617

@@ -116,7 +117,7 @@ func Preview(ctx context.Context, input Input, dir fs.FS) (output *Output, diagn
116117
}
117118
}
118119

119-
modules, outputs, err := p.EvaluateAll(ctx)
120+
modules, _, err := p.EvaluateAll(ctx)
120121
if err != nil {
121122
return nil, hcl.Diagnostics{
122123
{
@@ -126,6 +127,8 @@ func Preview(ctx context.Context, input Input, dir fs.FS) (output *Output, diagn
126127
},
127128
}
128129
}
130+
131+
outputs := hclext.ExportOutputs(modules)
129132

130133
diags := make(hcl.Diagnostics, 0)
131134
rp, rpDiags := parameters(modules)

0 commit comments

Comments
 (0)