2020-08-11 04:18:15 -04:00
|
|
|
package function
|
|
|
|
|
|
|
|
import (
|
|
|
|
"github.com/zclconf/go-cty/cty"
|
|
|
|
"github.com/zclconf/go-cty/cty/function"
|
|
|
|
|
2020-11-12 17:44:02 -05:00
|
|
|
commontpl "github.com/hashicorp/packer/packer-plugin-sdk/template"
|
2020-08-11 04:18:15 -04:00
|
|
|
)
|
|
|
|
|
|
|
|
// VaultFunc constructs a function that retrieves KV secrets from HC vault
|
|
|
|
var VaultFunc = function.New(&function.Spec{
|
|
|
|
Params: []function.Parameter{
|
|
|
|
{
|
|
|
|
Name: "path",
|
|
|
|
Type: cty.String,
|
|
|
|
},
|
|
|
|
{
|
|
|
|
Name: "key",
|
|
|
|
Type: cty.String,
|
|
|
|
},
|
|
|
|
},
|
|
|
|
Type: function.StaticReturnType(cty.String),
|
|
|
|
Impl: func(args []cty.Value, retType cty.Type) (cty.Value, error) {
|
|
|
|
path := args[0].AsString()
|
|
|
|
key := args[1].AsString()
|
|
|
|
|
2020-08-12 17:34:13 -04:00
|
|
|
val, err := commontpl.Vault(path, key)
|
2020-08-11 04:18:15 -04:00
|
|
|
|
2020-08-12 17:34:13 -04:00
|
|
|
return cty.StringVal(val), err
|
2020-08-11 04:18:15 -04:00
|
|
|
},
|
|
|
|
})
|