Skip to content

Commit 8449fae

Browse files
authored
Introduce ephemeral marks (#358)
* Bump aqua installer and registry * Introduce ephemeral marks
1 parent f713e5c commit 8449fae

File tree

10 files changed

+221
-125
lines changed

10 files changed

+221
-125
lines changed

Makefile

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
prepare:
2-
curl -sSfL https://raw.githubusercontent.com/aquaproj/aqua-installer/v2.1.1/aqua-installer | bash
2+
curl -sSfL https://raw.githubusercontent.com/aquaproj/aqua-installer/v3.0.1/aqua-installer | bash
33
@echo ''
44
@echo 'Add $${AQUA_ROOT_DIR}/bin to the environment variable PATH.'
55
@echo 'export PATH="$${AQUA_ROOT_DIR:-$${XDG_DATA_HOME:-$$HOME/.local/share}/aquaproj-aqua}/bin:$$PATH"'

aqua.yaml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88
# - all
99
registries:
1010
- type: standard
11-
ref: v3.159.0 # renovate: depName=aquaproj/aqua-registry
11+
ref: v4.290.0 # renovate: depName=aquaproj/aqua-registry
1212
packages:
1313
- name: protocolbuffers/protobuf/[email protected]
1414
- name: protocolbuffers/protobuf-go/[email protected]

plugin/internal/fromproto/fromproto.go

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -217,9 +217,14 @@ func Value(value []byte, ty cty.Type, valueMarks []*proto.ValueMark) (cty.Value,
217217
pvm[idx] = cty.PathValueMarks{
218218
Path: AttributePath(mark.Path),
219219
}
220+
vm := []interface{}{}
220221
if mark.Sensitive {
221-
pvm[idx].Marks = cty.NewValueMarks(marks.Sensitive)
222+
vm = append(vm, marks.Sensitive)
222223
}
224+
if mark.Ephemeral {
225+
vm = append(vm, marks.Ephemeral)
226+
}
227+
pvm[idx].Marks = cty.NewValueMarks(vm...)
223228
}
224229

225230
return val.MarkWithPaths(pvm), nil

plugin/internal/plugin2host/client.go

Lines changed: 12 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@ import (
1818
"github.com/terraform-linters/tflint-plugin-sdk/plugin/internal/proto"
1919
"github.com/terraform-linters/tflint-plugin-sdk/plugin/internal/toproto"
2020
"github.com/terraform-linters/tflint-plugin-sdk/terraform/addrs"
21+
"github.com/terraform-linters/tflint-plugin-sdk/terraform/lang/marks"
2122
"github.com/terraform-linters/tflint-plugin-sdk/tflint"
2223
"github.com/zclconf/go-cty/cty"
2324
"github.com/zclconf/go-cty/cty/gocty"
@@ -314,7 +315,11 @@ func (c *GRPCClient) EvaluateExpr(expr hcl.Expression, target interface{}, opts
314315

315316
if err != nil {
316317
// If it cannot be represented as a Go value, exit without invoking the callback rather than returning an error.
317-
if errors.Is(err, tflint.ErrUnknownValue) || errors.Is(err, tflint.ErrNullValue) || errors.Is(err, tflint.ErrSensitive) || errors.Is(err, tflint.ErrUnevaluable) {
318+
if errors.Is(err, tflint.ErrUnknownValue) ||
319+
errors.Is(err, tflint.ErrNullValue) ||
320+
errors.Is(err, tflint.ErrSensitive) ||
321+
errors.Is(err, tflint.ErrEphemeral) ||
322+
errors.Is(err, tflint.ErrUnevaluable) {
318323
return nil
319324
}
320325
return err
@@ -391,7 +396,7 @@ func (c *GRPCClient) evaluateExpr(expr hcl.Expression, target interface{}, opts
391396
return gocty.FromCtyValue(val, target)
392397
}
393398

394-
// Returns an error if the value cannot be decoded to a Go value (e.g. unknown, null, sensitive).
399+
// Returns an error if the value cannot be decoded to a Go value (e.g. unknown, null, marked).
395400
// This allows the caller to handle the value by the errors package.
396401
err = cty.Walk(val, func(path cty.Path, v cty.Value) (bool, error) {
397402
if !v.IsKnown() {
@@ -402,10 +407,14 @@ func (c *GRPCClient) evaluateExpr(expr hcl.Expression, target interface{}, opts
402407
logger.Debug(fmt.Sprintf("null value found in %s", expr.Range()))
403408
return false, tflint.ErrNullValue
404409
}
405-
if v.IsMarked() {
410+
if v.HasMark(marks.Sensitive) {
406411
logger.Debug(fmt.Sprintf("sensitive value found in %s", expr.Range()))
407412
return false, tflint.ErrSensitive
408413
}
414+
if v.HasMark(marks.Ephemeral) {
415+
logger.Debug(fmt.Sprintf("ephemeral value found in %s", expr.Range()))
416+
return false, tflint.ErrEphemeral
417+
}
409418
return true, nil
410419
})
411420
if err != nil {

plugin/internal/plugin2host/plugin2host_test.go

Lines changed: 62 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2015,6 +2015,42 @@ func TestEvaluateExpr(t *testing.T) {
20152015
GetFileImpl: fileExists,
20162016
ErrCheck: neverHappend,
20172017
},
2018+
{
2019+
Name: "ephemeral",
2020+
Expr: hclExpr(`var.foo`),
2021+
TargetType: reflect.TypeOf(""),
2022+
ServerImpl: func(expr hcl.Expression, opts tflint.EvaluateExprOption) (cty.Value, error) {
2023+
return evalExpr(expr, &hcl.EvalContext{
2024+
Variables: map[string]cty.Value{
2025+
"var": cty.MapVal(map[string]cty.Value{
2026+
"foo": cty.StringVal("bar").Mark(marks.Ephemeral),
2027+
}),
2028+
},
2029+
})
2030+
},
2031+
Want: "",
2032+
GetFileImpl: fileExists,
2033+
ErrCheck: func(err error) bool {
2034+
return !errors.Is(err, tflint.ErrEphemeral)
2035+
},
2036+
},
2037+
{
2038+
Name: "ephemeral as cty.Value",
2039+
Expr: hclExpr(`var.foo`),
2040+
TargetType: reflect.TypeOf(cty.Value{}),
2041+
ServerImpl: func(expr hcl.Expression, opts tflint.EvaluateExprOption) (cty.Value, error) {
2042+
return evalExpr(expr, &hcl.EvalContext{
2043+
Variables: map[string]cty.Value{
2044+
"var": cty.MapVal(map[string]cty.Value{
2045+
"foo": cty.StringVal("bar").Mark(marks.Ephemeral),
2046+
}),
2047+
},
2048+
})
2049+
},
2050+
Want: cty.StringVal("bar").Mark(marks.Ephemeral),
2051+
GetFileImpl: fileExists,
2052+
ErrCheck: neverHappend,
2053+
},
20182054
}
20192055

20202056
for _, test := range tests {
@@ -2334,6 +2370,32 @@ func TestEvaluateExpr_callback(t *testing.T) {
23342370
return err == nil || err.Error() != `value is cty.StringVal("foo").Mark(marks.Sensitive)`
23352371
},
23362372
},
2373+
{
2374+
name: "callback with ephemeral value as Go value",
2375+
expr: hclExpr(`var.foo`),
2376+
target: func(val string) error {
2377+
return fmt.Errorf("value is %s", val)
2378+
},
2379+
serverImpl: func(expr hcl.Expression, opts tflint.EvaluateExprOption) (cty.Value, error) {
2380+
return cty.StringVal("foo").Mark(marks.Ephemeral), nil
2381+
},
2382+
getFileImpl: fileExists,
2383+
errCheck: neverHappend,
2384+
},
2385+
{
2386+
name: "callback with ephemeral value as cty.Value",
2387+
expr: hclExpr(`var.foo`),
2388+
target: func(val cty.Value) error {
2389+
return fmt.Errorf("value is %s", val.GoString())
2390+
},
2391+
serverImpl: func(expr hcl.Expression, opts tflint.EvaluateExprOption) (cty.Value, error) {
2392+
return cty.StringVal("foo").Mark(marks.Ephemeral), nil
2393+
},
2394+
getFileImpl: fileExists,
2395+
errCheck: func(err error) bool {
2396+
return err == nil || err.Error() != `value is cty.StringVal("foo").Mark(marks.Ephemeral)`
2397+
},
2398+
},
23372399
}
23382400

23392401
for _, test := range tests {

0 commit comments

Comments
 (0)