Skip to content

Commit

Permalink
Merge pull request #13 from slok/slok/plugin-examples
Browse files Browse the repository at this point in the history
  • Loading branch information
slok committed Aug 11, 2022
2 parents 49e7e12 + 4cc3403 commit e2fe520
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 5 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
### Fixed

- Error messages.
- `yq` processor panic/errors because of race conditions when using concurrency.

## [v0.3.0] - 2022-08-07

Expand Down
10 changes: 5 additions & 5 deletions internal/process/yq.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,15 +19,15 @@ var (
yqlib.GetLogger().SetBackend(discardBackend)
return true
}()

// yq instances.
yqEncoder = yqlib.NewYamlEncoder(2, false, false, true)
yqDecoder = yqlib.NewYamlDecoder()
yqEval = yqlib.NewStringEvaluator()
)

func NewYQProcessor(ctx context.Context, yqExpression string) (Processor, error) {
return ProcessorFunc(func(ctx context.Context, inputData string) (string, error) {
// Create yq instances per execution, we don't share them to avoid problems related with concurrency execution by Terraform.
yqEncoder := yqlib.NewYamlEncoder(2, false, false, true)
yqDecoder := yqlib.NewYamlDecoder()
yqEval := yqlib.NewStringEvaluator()

result, err := yqEval.Evaluate(yqExpression, inputData, yqEncoder, true, yqDecoder)
if err != nil {
return "", fmt.Errorf("yq could not evaluate expression: %w", err)
Expand Down

0 comments on commit e2fe520

Please sign in to comment.