generated from hashicorp/terraform-provider-scaffolding-framework
/
echo_function.go
48 lines (38 loc) · 1.13 KB
/
echo_function.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
package provider
import (
"context"
"github.com/hashicorp/terraform-plugin-framework/function"
)
var (
_ function.Function = EchoFunction{}
)
func NewEchoFunction() function.Function {
return EchoFunction{}
}
type EchoFunction struct{}
func (r EchoFunction) Metadata(_ context.Context, req function.MetadataRequest, resp *function.MetadataResponse) {
resp.Name = "echo"
}
func (r EchoFunction) Definition(_ context.Context, _ function.DefinitionRequest, resp *function.DefinitionResponse) {
resp.Definition = function.Definition{
Summary: "Echo function",
MarkdownDescription: "Echoes given argument as result",
Parameters: []function.Parameter{
function.StringParameter{
Name: "input",
MarkdownDescription: "String to echo",
},
},
Return: function.StringReturn{},
}
}
func (r EchoFunction) Run(ctx context.Context, req function.RunRequest, resp *function.RunResponse) {
var data string
err := req.Arguments.Get(ctx, &data)
resp.Error = function.ConcatFuncErrors(err)
if resp.Error != nil {
return
}
err = resp.Result.Set(ctx, data)
resp.Error = function.ConcatFuncErrors(err)
}