Skip to content

Commit

Permalink
command/jsonfunction: marshal templatestring
Browse files Browse the repository at this point in the history
  • Loading branch information
kmoe committed May 22, 2024
1 parent b39072c commit c137779
Showing 1 changed file with 27 additions and 0 deletions.
27 changes: 27 additions & 0 deletions internal/command/jsonfunction/function.go
Original file line number Diff line number Diff line change
Expand Up @@ -86,6 +86,8 @@ func Marshal(f map[string]function.Function) ([]byte, tfdiags.Diagnostics) {
signatures.Signatures[name] = marshalCan(v)
} else if name == "try" || name == "core::try" {
signatures.Signatures[name] = marshalTry(v)
} else if name == "templatestring" || name == "core::templatestring" {
signatures.Signatures[name] = marshalTemplatestring(v)
} else {
signature, err := marshalFunction(v)
if err != nil {
Expand Down Expand Up @@ -194,3 +196,28 @@ func marshalCan(can function.Function) *FunctionSignature {
},
}
}

// marshalTemplatestring returns a static function signature for the
// templatestring function.
// We need this exception because the function implementation uses capsule
// types that we can't marshal.
func marshalTemplatestring(templatestring function.Function) *FunctionSignature {
return &FunctionSignature{
Description: templatestring.Description(),
ReturnType: cty.String,
Parameters: []*parameter{
{
Name: templatestring.Params()[0].Name,
Description: templatestring.Params()[0].Description,
IsNullable: templatestring.Params()[0].AllowNull,
Type: cty.DynamicPseudoType,
},
{
Name: templatestring.Params()[1].Name,
Description: templatestring.Params()[1].Description,
IsNullable: templatestring.Params()[1].AllowNull,
Type: cty.DynamicPseudoType,
},
},
}
}

0 comments on commit c137779

Please sign in to comment.