Skip to content

Commit cef0cc0

Browse files
committed
get this working for people not on my machine
1 parent bc637ff commit cef0cc0

File tree

7 files changed

+128
-4
lines changed

7 files changed

+128
-4
lines changed

Diff for: go.mod

+1-1
Original file line numberDiff line numberDiff line change
@@ -108,4 +108,4 @@ require (
108108
k8s.io/utils v0.0.0-20241104100929-3ea5e8cea738 // indirect
109109
)
110110

111-
replace github.com/aquasecurity/trivy => github.com/Emyrk/trivy v0.0.0-20250130184222-11c279ff4cd9
111+
replace github.com/aquasecurity/trivy => github.com/Emyrk/trivy v0.0.0-20250211144405-6377059f7705

Diff for: go.sum

+2-2
Original file line numberDiff line numberDiff line change
@@ -625,8 +625,8 @@ github.com/Azure/go-ansiterm v0.0.0-20230124172434-306776ec8161 h1:L/gRVlceqvL25
625625
github.com/Azure/go-ansiterm v0.0.0-20230124172434-306776ec8161/go.mod h1:xomTg63KZ2rFqZQzSB4Vz2SUXa1BpHTVz9L5PTmPC4E=
626626
github.com/BurntSushi/toml v0.3.1/go.mod h1:xHWCNGjB5oqiDr8zfno3MHue2Ht5sIBksp03qcyfWMU=
627627
github.com/BurntSushi/xgb v0.0.0-20160522181843-27f122750802/go.mod h1:IVnqGOEym/WlBOVXweHU+Q+/VP0lqqI8lqeDx9IjBqo=
628-
github.com/Emyrk/trivy v0.0.0-20250130184222-11c279ff4cd9 h1:v4RZ1ayXjps3spGYXDWub0U7XmgUEaCAgqX+wEnZ19Y=
629-
github.com/Emyrk/trivy v0.0.0-20250130184222-11c279ff4cd9/go.mod h1:dJIzxTfeSrUGtDBtbg2AiMbAnbVjo97lsLC9eyAawZI=
628+
github.com/Emyrk/trivy v0.0.0-20250211144405-6377059f7705 h1:+xVBMqeiopGTM+MbCydHG2K1IJm/Vf0LJYuIm8Rky18=
629+
github.com/Emyrk/trivy v0.0.0-20250211144405-6377059f7705/go.mod h1:h/k++UOEKWxKbATF5462j0OpzrnYwkqHI0HAcLB5uuY=
630630
github.com/GoogleCloudPlatform/opentelemetry-operations-go/detectors/gcp v1.25.0 h1:3c8yed4lgqTt+oTQ+JNMDo+F4xprBf+O/il4ZC0nRLw=
631631
github.com/GoogleCloudPlatform/opentelemetry-operations-go/detectors/gcp v1.25.0/go.mod h1:obipzmGjfSjam60XLwGfqUkJsfiheAl+TUjG+4yzyPM=
632632
github.com/GoogleCloudPlatform/opentelemetry-operations-go/exporter/metric v0.48.1 h1:UQ0AhxogsIRZDkElkblfnwjc3IaltCm2HUMvezQaL7s=

Diff for: log.go

+15
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
package preview
2+
3+
import (
4+
"os"
5+
6+
tlog "github.com/aquasecurity/trivy/pkg/log"
7+
)
8+
9+
func init() {
10+
ll := tlog.New(tlog.NewHandler(os.Stderr, &tlog.Options{
11+
Level: tlog.LevelDebug,
12+
}))
13+
var _ = ll
14+
//tlog.SetDefault(ll)
15+
}

Diff for: parameter.go

+2-1
Original file line numberDiff line numberDiff line change
@@ -102,7 +102,8 @@ func richParameterValue(block *terraform.Block) cty.Value {
102102
}
103103

104104
// TODO: Figure out what to do with these diagnostics
105-
return markWithDiagnostic(cty.UnknownVal(cty.NilType), diags)
105+
var _ = diags
106+
return cty.UnknownVal(cty.NilType)
106107
}
107108

108109
return paramValue

Diff for: plan.go

+52
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,22 @@ func PlanJSONHook(dfs fs.FS, input Input) (func(ctx *tfcontext.Context, blocks t
3535

3636
var _ = plan
3737
return func(ctx *tfcontext.Context, blocks terraform.Blocks, inputVars map[string]cty.Value) {
38+
for _, block := range blocks {
39+
if block.InModule() {
40+
41+
x := block.ModuleKey()
42+
y := block.ModuleBlock().FullName()
43+
var _, _ = x, y
44+
fmt.Println(block.ModuleKey())
45+
continue
46+
}
47+
48+
err = loadResourcesToContext(block.Context().Parent(), plan.PriorState.Values.RootModule.Resources)
49+
if err != nil {
50+
panic(fmt.Sprintf("unable to load resources to context: %v", err))
51+
}
52+
}
53+
3854
// 'data' blocks are loaded into prior state
3955
//plan.PriorState.Values.RootModule.Resources
4056
for _, resource := range plan.PriorState.Values.RootModule.Resources {
@@ -63,6 +79,42 @@ func PlanJSONHook(dfs fs.FS, input Input) (func(ctx *tfcontext.Context, blocks t
6379
}, nil
6480
}
6581

82+
func planResources(plan *tfjson.Plan, block *terraform.Block) error {
83+
if !block.InModule() {
84+
return loadResourcesToContext(block.Context().Parent(), plan.PriorState.Values.RootModule.Resources)
85+
}
86+
87+
var path []string
88+
mod := block.ModuleBlock()
89+
90+
for {
91+
path = append([]string{mod.FullName()}, path...)
92+
break
93+
}
94+
return nil
95+
}
96+
97+
func loadResourcesToContext(ctx *tfcontext.Context, resources []*tfjson.StateResource) error {
98+
for _, resource := range resources {
99+
if resource.Mode != "data" {
100+
continue
101+
}
102+
103+
if strings.HasPrefix(resource.Type, "coder_") {
104+
// Ignore coder blocks
105+
continue
106+
}
107+
108+
val, err := toCtyValue(resource.AttributeValues)
109+
if err != nil {
110+
return fmt.Errorf("unable to determine value of resource %q: %w", resource.Address, err)
111+
}
112+
113+
ctx.Set(val, string(resource.Mode), resource.Type, resource.Name)
114+
}
115+
return nil
116+
}
117+
66118
func toCtyValue(a any) (cty.Value, error) {
67119
if a == nil {
68120
return cty.NilVal, nil

Diff for: preview_test.go

+11
Original file line numberDiff line numberDiff line change
@@ -173,6 +173,17 @@ func Test_Extract(t *testing.T) {
173173
expUnknowns: []string{},
174174
params: map[string]func(t *testing.T, parameter types.Parameter){},
175175
},
176+
{
177+
name: "many modules",
178+
dir: "manymodules",
179+
expTags: map[string]string{},
180+
input: preview.Input{
181+
ParameterValues: map[string]types.ParameterValue{},
182+
PlanJSONPath: "before.json",
183+
},
184+
expUnknowns: []string{},
185+
params: map[string]func(t *testing.T, parameter types.Parameter){},
186+
},
176187
} {
177188
t.Run(tc.name, func(t *testing.T) {
178189
t.Parallel()

Diff for: testdata/manymodules/one/onea/onea.tf

+45
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,45 @@
1+
terraform {
2+
required_providers {
3+
coder = {
4+
source = "coder/coder"
5+
}
6+
}
7+
}
8+
9+
locals {
10+
foo = "one-a"
11+
}
12+
13+
data "coder_parameter" "one-a-question" {
14+
name = "One A Question"
15+
description = "From module 1, sub A"
16+
type = "string"
17+
default = local.foo
18+
19+
option {
20+
name = "Default"
21+
value = local.foo
22+
}
23+
24+
option {
25+
name = "Terraform"
26+
value = jsondecode(data.http.packer.response_body).current_version
27+
}
28+
}
29+
30+
output "export" {
31+
value = local.foo
32+
}
33+
34+
output "packer" {
35+
value = jsondecode(data.http.packer.response_body).current_version
36+
}
37+
38+
data "http" "packer" {
39+
url = "https://checkpoint-api.hashicorp.com/v1/check/packer"
40+
41+
# Optional request headers
42+
request_headers = {
43+
Accept = "application/json"
44+
}
45+
}

0 commit comments

Comments
 (0)