github.com/hashicorp/packer@v1.14.3/hcl2template/function/strcontains.go (about) 1 package function 2 3 import ( 4 "strings" 5 6 "github.com/zclconf/go-cty/cty" 7 "github.com/zclconf/go-cty/cty/function" 8 ) 9 10 var StrContains = function.New(&function.Spec{ 11 Params: []function.Parameter{ 12 { 13 Name: "str", 14 Type: cty.String, 15 }, 16 { 17 Name: "substr", 18 Type: cty.String, 19 }, 20 }, 21 Type: function.StaticReturnType(cty.Bool), 22 Impl: func(args []cty.Value, retType cty.Type) (cty.Value, error) { 23 str := args[0].AsString() 24 substr := args[1].AsString() 25 26 if strings.Contains(str, substr) { 27 return cty.True, nil 28 } 29 30 return cty.False, nil 31 }, 32 })