github.com/hashicorp/packer@v1.14.3/hcl2template/function/Consul.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 // ConsulFunc constructs a function that retrieves KV secrets from HC vault 14 var ConsulFunc = function.New(&function.Spec{ 15 Params: []function.Parameter{ 16 { 17 Name: "key", 18 Type: cty.String, 19 }, 20 }, 21 Type: function.StaticReturnType(cty.String), 22 Impl: func(args []cty.Value, retType cty.Type) (cty.Value, error) { 23 key := args[0].AsString() 24 val, err := commontpl.Consul(key) 25 26 return cty.StringVal(val), err 27 }, 28 })