pulumi/pkg/codegen/hcl2/functions.go
Pat Gavlin 2f22c1c59c
HCL2 updates (#4309)
Pulumi HCL2 IR:
- Add support for invokes
- Add support for resource options, incl. ranged resources
- Allow the apply rewriter to ignore promise-typed values
- Add tests for the binder
- Add support functions for TF: entries and range

NodeJS codegen:
- Simplify for expression codegen
- Add support for invoke codegen
- Add support for entries and range functions
- Add tests

Python codegen:
- Implement codegen for most expression types
- Add support for invoke codegen
- Add tests
2020-04-06 19:43:16 -07:00

85 lines
2.5 KiB
Go

// Copyright 2016-2020, Pulumi Corporation.
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
package hcl2
import (
"github.com/hashicorp/hcl/v2"
"github.com/pulumi/pulumi/pkg/codegen/hcl2/model"
)
func getEntriesSignature(args []model.Expression) (model.StaticFunctionSignature, hcl.Diagnostics) {
var diagnostics hcl.Diagnostics
keyType, valueType := model.Type(model.DynamicType), model.Type(model.DynamicType)
signature := model.StaticFunctionSignature{
Parameters: []model.Parameter{{
Name: "collection",
Type: model.DynamicType,
}},
}
if len(args) == 1 {
keyT, valueT, diags := model.GetCollectionTypes(args[0].Type(), args[0].SyntaxNode().Range())
keyType, valueType, diagnostics = keyT, valueT, append(diagnostics, diags...)
}
signature.ReturnType = model.NewListType(model.NewTupleType(keyType, valueType))
return signature, diagnostics
}
var pulumiBuiltins = map[string]*model.Function{
"entries": model.NewFunction(model.GenericFunctionSignature(getEntriesSignature)),
"fileAsset": model.NewFunction(model.StaticFunctionSignature{
Parameters: []model.Parameter{{
Name: "path",
Type: model.StringType,
}},
ReturnType: AssetType,
}),
"mimeType": model.NewFunction(model.StaticFunctionSignature{
Parameters: []model.Parameter{{
Name: "path",
Type: model.StringType,
}},
ReturnType: model.StringType,
}),
"range": model.NewFunction(model.StaticFunctionSignature{
Parameters: []model.Parameter{
{
Name: "fromOrTo",
Type: model.NumberType,
},
{
Name: "to",
Type: model.NewOptionalType(model.NumberType),
},
},
ReturnType: model.NewListType(model.IntType),
}),
"readDir": model.NewFunction(model.StaticFunctionSignature{
Parameters: []model.Parameter{{
Name: "path",
Type: model.StringType,
}},
ReturnType: model.NewListType(model.StringType),
}),
"toJSON": model.NewFunction(model.StaticFunctionSignature{
Parameters: []model.Parameter{{
Name: "value",
Type: model.DynamicType,
}},
ReturnType: model.StringType,
}),
}