github.com/hashicorp/packer@v1.14.3/hcl2template/function/vault.go (about) 1 // Copyright (c) HashiCorp, Inc. 2 // SPDX-License-Identifier: BUSL-1.1 3 4 package function 5 6 import ( 7 "github.com/zclconf/go-cty/cty" 8 "github.com/zclconf/go-cty/cty/function" 9 10 commontpl "github.com/hashicorp/packer-plugin-sdk/template" 11 ) 12 13 // VaultFunc constructs a function that retrieves KV secrets from HC vault 14 var VaultFunc = function.New(&function.Spec{ 15 Params: []function.Parameter{ 16 { 17 Name: "path", 18 Type: cty.String, 19 }, 20 { 21 Name: "key", 22 Type: cty.String, 23 }, 24 }, 25 Type: function.StaticReturnType(cty.String), 26 Impl: func(args []cty.Value, retType cty.Type) (cty.Value, error) { 27 path := args[0].AsString() 28 key := args[1].AsString() 29 30 val, err := commontpl.Vault(path, key) 31 32 return cty.StringVal(val), err 33 }, 34 })