mirror of
https://github.com/hashicorp/packer.git
synced 2026-04-15 22:20:33 -04:00
The strcontains function check if a sub string is a indeed a subset of a given string. hcl2template: add strcontains function The strcontains function check if a sub string is a indeed a subset of a given string.
32 lines
564 B
Go
32 lines
564 B
Go
package function
|
|
|
|
import (
|
|
"strings"
|
|
|
|
"github.com/zclconf/go-cty/cty"
|
|
"github.com/zclconf/go-cty/cty/function"
|
|
)
|
|
|
|
var StrContains = function.New(&function.Spec{
|
|
Params: []function.Parameter{
|
|
{
|
|
Name: "str",
|
|
Type: cty.String,
|
|
},
|
|
{
|
|
Name: "substr",
|
|
Type: cty.String,
|
|
},
|
|
},
|
|
Type: function.StaticReturnType(cty.Bool),
|
|
Impl: func(args []cty.Value, retType cty.Type) (cty.Value, error) {
|
|
str := args[0].AsString()
|
|
substr := args[1].AsString()
|
|
|
|
if strings.Contains(str, substr) {
|
|
return cty.True, nil
|
|
}
|
|
|
|
return cty.False, nil
|
|
},
|
|
})
|