mirror of
https://github.com/opentffoundation/opentf.git
synced 2025-12-19 17:59:05 -05:00
Hack in key_provider by string reference
Signed-off-by: Christian Mesh <christianmesh1@gmail.com>
This commit is contained in:
committed by
Andrei Ciobanu
parent
1be062b4bf
commit
786d902cae
@@ -9,8 +9,10 @@ import (
|
|||||||
"context"
|
"context"
|
||||||
"errors"
|
"errors"
|
||||||
"fmt"
|
"fmt"
|
||||||
|
"strings"
|
||||||
|
|
||||||
"github.com/hashicorp/hcl/v2"
|
"github.com/hashicorp/hcl/v2"
|
||||||
|
"github.com/hashicorp/hcl/v2/hclsyntax"
|
||||||
"github.com/opentofu/opentofu/internal/addrs"
|
"github.com/opentofu/opentofu/internal/addrs"
|
||||||
"github.com/opentofu/opentofu/internal/configs"
|
"github.com/opentofu/opentofu/internal/configs"
|
||||||
"github.com/opentofu/opentofu/internal/encryption/config"
|
"github.com/opentofu/opentofu/internal/encryption/config"
|
||||||
@@ -43,7 +45,8 @@ func setupMethod(ctx context.Context, enc *config.EncryptionConfig, cfg config.M
|
|||||||
}}
|
}}
|
||||||
}
|
}
|
||||||
|
|
||||||
methodCtx := method.EvalContext{func(expr hcl.Expression) (cty.Value, hcl.Diagnostics) {
|
var methodCtx method.EvalContext
|
||||||
|
methodCtx = method.EvalContext{func(expr hcl.Expression) (cty.Value, hcl.Diagnostics) {
|
||||||
var diags hcl.Diagnostics
|
var diags hcl.Diagnostics
|
||||||
|
|
||||||
deps := expr.Variables()
|
deps := expr.Variables()
|
||||||
@@ -76,7 +79,21 @@ func setupMethod(ctx context.Context, enc *config.EncryptionConfig, cfg config.M
|
|||||||
return cty.NilVal, diags
|
return cty.NilVal, diags
|
||||||
}
|
}
|
||||||
|
|
||||||
// TODO inspect to see if KP string!
|
if val.Type() == cty.String {
|
||||||
|
// Try to be clever to see if it's a kp string that is actually a reference
|
||||||
|
// We might want a bool to opt-in to this functionality for JSON compat on specific fields
|
||||||
|
|
||||||
|
str := val.AsString()
|
||||||
|
if strings.HasPrefix(str, "key_provider.") {
|
||||||
|
traversal, travDiags := hclsyntax.ParseTraversalAbs([]byte(str), "", hcl.Pos{})
|
||||||
|
if !travDiags.HasErrors() {
|
||||||
|
// Call into the expr resolver again
|
||||||
|
val, valDiags = methodCtx.ValueForExpression(&hclsyntax.ScopeTraversalExpr{Traversal: traversal, SrcRange: expr.Range()})
|
||||||
|
diags = diags.Extend(valDiags)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
return val, diags
|
return val, diags
|
||||||
}}
|
}}
|
||||||
|
|||||||
Reference in New Issue
Block a user