diff --git a/acc-coverage.png b/acc-coverage.png index a3d2d85..e30e208 100644 Binary files a/acc-coverage.png and b/acc-coverage.png differ diff --git a/acc-coverage.svg b/acc-coverage.svg index cd78e66..f99aa40 100644 --- a/acc-coverage.svg +++ b/acc-coverage.svg @@ -7,7 +7,7 @@ > - + - + env_ensure_data_source.go @@ -33,12 +33,12 @@ - + env_ensure_function.go @@ -46,12 +46,12 @@ - + helpers.go @@ -59,12 +59,12 @@ - + homedir_expand_data_source.go @@ -72,12 +72,12 @@ - + homedir_expand_function.go @@ -85,12 +85,12 @@ - + homedir_get_data_source.go @@ -98,12 +98,12 @@ - + homedir_get_function.go @@ -111,12 +111,12 @@ - + int_leftpad_data_source.go @@ -124,12 +124,25 @@ - + int_leftpad_function.go + + + + + + + +provider.go @@ -137,12 +150,12 @@ - + runtime_cpuarch_data_source.go @@ -150,12 +163,12 @@ - + runtime_cpuarch_function.go @@ -163,12 +176,12 @@ - + runtime_goroot_data_source.go @@ -176,12 +189,12 @@ - + runtime_goroot_function.go @@ -189,12 +202,12 @@ - + runtime_numcpus_data_source.go @@ -202,12 +215,12 @@ - + runtime_numcpus_function.go @@ -215,12 +228,12 @@ - + runtime_os_data_source.go @@ -228,12 +241,12 @@ - + runtime_os_function.go @@ -241,12 +254,12 @@ - + str_camel_data_source.go @@ -254,12 +267,12 @@ - + str_camel_function.go @@ -267,12 +280,12 @@ - + str_constant_data_source.go @@ -280,12 +293,12 @@ - + str_constant_function.go @@ -293,12 +306,12 @@ - + str_iterative_replace_data_source.go @@ -306,12 +319,12 @@ - + str_kebab_data_source.go @@ -319,12 +332,12 @@ - + str_kebab_function.go @@ -332,12 +345,12 @@ - + str_leftpad_data_source.go @@ -345,12 +358,25 @@ - + + +str_leftpad_function.go + + + + + + str_pascal_data_source.go @@ -358,12 +384,12 @@ - + str_pascal_function.go @@ -371,12 +397,12 @@ - + str_snake_data_source.go @@ -384,12 +410,12 @@ - + str_snake_function.go @@ -397,12 +423,12 @@ - + truncate_label_data_source.go @@ -410,12 +436,12 @@ - + url_parse_data_source.go diff --git a/corefuncprovider/int_leftpad_function.go b/corefuncprovider/int_leftpad_function.go new file mode 100644 index 0000000..6afc61a --- /dev/null +++ b/corefuncprovider/int_leftpad_function.go @@ -0,0 +1,110 @@ +// Copyright 2023-2024, Northwood Labs +// Copyright 2023-2024, Ryan Parman +// +// 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 corefuncprovider // lint:no_dupe + +import ( + "context" + "fmt" + "strings" + + "github.com/hashicorp/terraform-plugin-framework/function" + "github.com/hashicorp/terraform-plugin-log/tflog" + "github.com/lithammer/dedent" + "github.com/northwood-labs/terraform-provider-corefunc/corefunc" +) + +// Ensure the implementation satisfies the expected interfaces. +var _ function.Function = &intLeftpadFunction{} + +type ( + // intLeftpadFunction is the function implementation. + intLeftpadFunction struct{} +) + +// IntLeftpadFunction is a method that exposes its paired Go function as a +// Terraform Function. +// https://developer.hashicorp.com/terraform/plugin/framework/functions/implementation +func IntLeftpadFunction() function.Function { // lint:allow_return_interface + return &intLeftpadFunction{} +} + +func (f *intLeftpadFunction) Metadata( + ctx context.Context, + req function.MetadataRequest, + resp *function.MetadataResponse, +) { + tflog.Debug(ctx, "Starting IntLeftpad Function Metadata method.") + + resp.Name = "int_leftpad" + + tflog.Debug(ctx, fmt.Sprintf("resp.Name = %s", resp.Name)) + + tflog.Debug(ctx, "Ending IntLeftpad Function Metadata method.") +} + +// Definition defines the parameters and return type for the function. +func (f *intLeftpadFunction) Definition( + ctx context.Context, + req function.DefinitionRequest, + resp *function.DefinitionResponse, +) { + tflog.Debug(ctx, "Starting IntLeftpad Function Definition method.") + + resp.Definition = function.Definition{ + Summary: "Converts an integer to a string, and then pads it with zeroes on the left.", + MarkdownDescription: strings.TrimSpace(dedent.Dedent(` + Converts an integer to a string, and then pads it with zeroes on the left. + + -> If the integer is NOT in base10 (decimal), it will be converted to base10 (decimal) _before_ being padded. + + Maps to the ` + linkPackage("IntLeftPad") + ` Go method, which can be used in ` + Terratest + `. + `)), + Parameters: []function.Parameter{ + function.Int64Parameter{ + Name: "num", + MarkdownDescription: "The integer to pad with zeroes.", + }, + function.Int64Parameter{ + Name: "pad_width", + MarkdownDescription: "The max number of zeroes to pad the integer with.", + }, + }, + Return: function.StringReturn{}, + } + + tflog.Debug(ctx, "Ending IntLeftpad Function Definition method.") +} + +func (f *intLeftpadFunction) Run(ctx context.Context, req function.RunRequest, resp *function.RunResponse) { + tflog.Debug(ctx, "Starting IntLeftpad Function Run method.") + + var ( + num int64 + padWidth int64 + ) + + err := req.Arguments.Get(ctx, &num, &padWidth) + + resp.Error = function.ConcatFuncErrors(err) + if resp.Error != nil { + return + } + + value := corefunc.IntLeftPad(num, int(padWidth)) + resp.Error = function.ConcatFuncErrors(resp.Result.Set(ctx, value)) + + tflog.Debug(ctx, "Ending IntLeftpad Function Run method.") +} diff --git a/corefuncprovider/int_leftpad_function_fixture.tftpl b/corefuncprovider/int_leftpad_function_fixture.tftpl new file mode 100644 index 0000000..1ded5c5 --- /dev/null +++ b/corefuncprovider/int_leftpad_function_fixture.tftpl @@ -0,0 +1,4 @@ +output "leftpad" { + value = provider::corefunc::int_leftpad({{ .Input }}, {{ .PadWidth }}) +} +#=> {{ .Expected }} diff --git a/corefuncprovider/int_leftpad_function_test.go b/corefuncprovider/int_leftpad_function_test.go new file mode 100644 index 0000000..439f257 --- /dev/null +++ b/corefuncprovider/int_leftpad_function_test.go @@ -0,0 +1,77 @@ +// Copyright 2023-2024, Northwood Labs +// Copyright 2023-2024, Ryan Parman +// +// 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 corefuncprovider // lint:no_dupe + +import ( + "bytes" + "fmt" + "log" + "os" + "strings" + "testing" + "text/template" + + "github.com/northwood-labs/terraform-provider-corefunc/testfixtures" + + "github.com/hashicorp/go-version" + "github.com/hashicorp/terraform-plugin-testing/helper/resource" + "github.com/hashicorp/terraform-plugin-testing/tfversion" +) + +func TestAccIntLeftpadFunction(t *testing.T) { + t.Parallel() + + funcName := traceFuncName() + + for name, tc := range testfixtures.IntLeftPadTestTable { // lint:no_dupe + fmt.Printf( + "=== RUN %s/%s\n", + strings.TrimSpace(funcName), + strings.TrimSpace(name), + ) + + buf := &bytes.Buffer{} + tmpl := template.Must( + template.ParseFiles("int_leftpad_function_fixture.tftpl"), + ) + + err := tmpl.Execute(buf, tc) + if err != nil { + log.Fatalln(err) + } + + if os.Getenv("PROVIDER_DEBUG") != "" { + fmt.Fprintln(os.Stderr, buf.String()) + } + + resource.UnitTest(t, resource.TestCase{ + TerraformVersionChecks: []tfversion.TerraformVersionCheck{ + tfversion.SkipBelow( + version.Must(version.NewVersion("1.7.999")), + ), + }, + ProtoV6ProviderFactories: testAccProtoV6ProviderFactories, + Steps: []resource.TestStep{ + { + Config: providerConfig + buf.String(), + Check: resource.ComposeTestCheckFunc( + resource.TestCheckOutput("leftpad", tc.Expected), + ), + }, + }, + }) + } +} diff --git a/corefuncprovider/provider.go b/corefuncprovider/provider.go index 4d3af99..d2e0ec3 100644 --- a/corefuncprovider/provider.go +++ b/corefuncprovider/provider.go @@ -129,6 +129,7 @@ func (p *coreFuncProvider) Functions(ctx context.Context) []func() function.Func EnvEnsureFunction, HomedirExpandFunction, HomedirGetFunction, + IntLeftpadFunction, RuntimeCpuarchFunction, RuntimeGorootFunction, RuntimeNumcpusFunction, @@ -136,6 +137,7 @@ func (p *coreFuncProvider) Functions(ctx context.Context) []func() function.Func StrCamelFunction, StrConstantFunction, StrKebabFunction, + StrLeftpadFunction, StrPascalFunction, StrSnakeFunction, } diff --git a/corefuncprovider/str_leftpad_function.go b/corefuncprovider/str_leftpad_function.go new file mode 100644 index 0000000..23bc2bf --- /dev/null +++ b/corefuncprovider/str_leftpad_function.go @@ -0,0 +1,119 @@ +// Copyright 2023-2024, Northwood Labs +// Copyright 2023-2024, Ryan Parman +// +// 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 corefuncprovider // lint:no_dupe + +import ( + "context" + "fmt" + "strings" + + "github.com/hashicorp/terraform-plugin-framework/function" + "github.com/hashicorp/terraform-plugin-log/tflog" + "github.com/lithammer/dedent" + "github.com/northwood-labs/terraform-provider-corefunc/corefunc" +) + +// Ensure the implementation satisfies the expected interfaces. +var _ function.Function = &strLeftpadFunction{} + +type ( + // strLeftpadFunction is the function implementation. + strLeftpadFunction struct{} +) + +// StrLeftpadFunction is a method that exposes its paired Go function as a +// Terraform Function. +// https://developer.hashicorp.com/terraform/plugin/framework/functions/implementation +func StrLeftpadFunction() function.Function { // lint:allow_return_interface + return &strLeftpadFunction{} +} + +func (f *strLeftpadFunction) Metadata( + ctx context.Context, + req function.MetadataRequest, + resp *function.MetadataResponse, +) { + tflog.Debug(ctx, "Starting StrLeftpad Function Metadata method.") + + resp.Name = "str_leftpad" + + tflog.Debug(ctx, fmt.Sprintf("resp.Name = %s", resp.Name)) + + tflog.Debug(ctx, "Ending StrLeftpad Function Metadata method.") +} + +// Definition defines the parameters and return type for the function. +func (f *strLeftpadFunction) Definition( + ctx context.Context, + req function.DefinitionRequest, + resp *function.DefinitionResponse, +) { + tflog.Debug(ctx, "Starting StrLeftpad Function Definition method.") + + resp.Definition = function.Definition{ + Summary: "Pads a string with additional characters on the left.", + MarkdownDescription: strings.TrimSpace(dedent.Dedent(` + Pads a string with additional characters on the left. + + Maps to the ` + linkPackage("StrLeftPad") + ` Go method, which can be used in ` + Terratest + `. + `)), + Parameters: []function.Parameter{ + function.StringParameter{ + Name: "str", + MarkdownDescription: "The string to pad with padding characters.", + }, + function.Int64Parameter{ + Name: "pad_width", + MarkdownDescription: "The max number of padding characters to pad the string with.", + }, + }, + VariadicParameter: function.StringParameter{ + Name: "pad_char", + MarkdownDescription: "The padding character to use. Only supports a single byte. If more than one " + + "byte is provided, only the first byte will be used. The default value is a space character.", + }, + Return: function.StringReturn{}, + } + + tflog.Debug(ctx, "Ending StrLeftpad Function Definition method.") +} + +func (f *strLeftpadFunction) Run(ctx context.Context, req function.RunRequest, resp *function.RunResponse) { + tflog.Debug(ctx, "Starting StrLeftpad Function Run method.") + + var ( + str string + value string + padWidth int64 + padChar []string + ) + + resp.Error = function.ConcatFuncErrors(req.Arguments.Get(ctx, &str, &padWidth, &padChar)) + if resp.Error != nil { + return + } + + if len(padChar) > 0 && padChar[0] != "" { + b := []byte(padChar[0]) + value = corefunc.StrLeftPad(str, int(padWidth), b[0]) + } else { + value = corefunc.StrLeftPad(str, int(padWidth)) + } + + resp.Error = function.ConcatFuncErrors(resp.Result.Set(ctx, value)) + + tflog.Debug(ctx, "Ending StrLeftpad Function Run method.") +} diff --git a/corefuncprovider/str_leftpad_function_fixture.tftpl b/corefuncprovider/str_leftpad_function_fixture.tftpl new file mode 100644 index 0000000..3a9dee7 --- /dev/null +++ b/corefuncprovider/str_leftpad_function_fixture.tftpl @@ -0,0 +1,9 @@ +{{ $root := . }} +output "leftpad" { +{{- with .PadChar }} + value = provider::corefunc::str_leftpad("{{ $root.Input }}", {{ $root.PadWidth }}, "{{ . | printf "%c" }}") +{{- else }} + value = provider::corefunc::str_leftpad("{{ $root.Input }}", {{ $root.PadWidth }}) +{{- end }} +} +#=> {{ .Expected }} diff --git a/corefuncprovider/str_leftpad_function_test.go b/corefuncprovider/str_leftpad_function_test.go new file mode 100644 index 0000000..e92d309 --- /dev/null +++ b/corefuncprovider/str_leftpad_function_test.go @@ -0,0 +1,77 @@ +// Copyright 2023-2024, Northwood Labs +// Copyright 2023-2024, Ryan Parman +// +// 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 corefuncprovider // lint:no_dupe + +import ( + "bytes" + "fmt" + "log" + "os" + "strings" + "testing" + "text/template" + + "github.com/northwood-labs/terraform-provider-corefunc/testfixtures" + + "github.com/hashicorp/go-version" + "github.com/hashicorp/terraform-plugin-testing/helper/resource" + "github.com/hashicorp/terraform-plugin-testing/tfversion" +) + +func TestAccStrLeftpadFunction(t *testing.T) { + t.Parallel() + + funcName := traceFuncName() + + for name, tc := range testfixtures.StrLeftPadTestTable { // lint:no_dupe + fmt.Printf( + "=== RUN %s/%s\n", + strings.TrimSpace(funcName), + strings.TrimSpace(name), + ) + + buf := &bytes.Buffer{} + tmpl := template.Must( + template.ParseFiles("str_leftpad_function_fixture.tftpl"), + ) + + err := tmpl.Execute(buf, tc) + if err != nil { + log.Fatalln(err) + } + + if os.Getenv("PROVIDER_DEBUG") != "" { + fmt.Fprintln(os.Stderr, buf.String()) + } + + resource.UnitTest(t, resource.TestCase{ + TerraformVersionChecks: []tfversion.TerraformVersionCheck{ + tfversion.SkipBelow( + version.Must(version.NewVersion("1.7.999")), + ), + }, + ProtoV6ProviderFactories: testAccProtoV6ProviderFactories, + Steps: []resource.TestStep{ + { + Config: providerConfig + buf.String(), + Check: resource.ComposeTestCheckFunc( + resource.TestCheckOutput("leftpad", tc.Expected), + ), + }, + }, + }) + } +} diff --git a/docs/functions/env_ensure.md b/docs/functions/env_ensure.md index 9dd6169..6715119 100644 --- a/docs/functions/env_ensure.md +++ b/docs/functions/env_ensure.md @@ -107,5 +107,7 @@ Invalid value for "name" parameter: environment variable AWS_VAULT does not matc 1. `name` (String) The name of the environment variable to check. + +1. `pattern` (Variadic, String, Nullable) A valid Go ([re2](https://github.com/google/re2/wiki/Syntax)) regular expression pattern. diff --git a/docs/functions/int_leftpad.md b/docs/functions/int_leftpad.md new file mode 100644 index 0000000..54c7fc1 --- /dev/null +++ b/docs/functions/int_leftpad.md @@ -0,0 +1,43 @@ + + +# int_leftpad (function) + +Converts an integer to a string, and then pads it with zeroes on the left. + +-> If the integer is NOT in base10 (decimal), it will be converted to base10 (decimal) _before_ being padded. + +Maps to the [`corefunc.IntLeftPad()`](https://pkg.go.dev/github.com/northwood-labs/terraform-provider-corefunc/corefunc#IntLeftPad) Go method, which can be used in [Terratest](https://terratest.gruntwork.io). + +## Signature + + +```text +int_leftpad(num number, pad_width number) string +``` + +## Example Usage + +```terraform +output "leftpad" { + value = provider::corefunc::int_leftpad(123, 5) +} + +#=> 00123 +``` + +## Arguments + + +1. `num` (Number) The integer to pad with zeroes. +1. `pad_width` (Number) The max number of zeroes to pad the integer with. + + diff --git a/docs/functions/str_leftpad.md b/docs/functions/str_leftpad.md new file mode 100644 index 0000000..5f93c08 --- /dev/null +++ b/docs/functions/str_leftpad.md @@ -0,0 +1,42 @@ + + +# str_leftpad (function) + +Pads a string with additional characters on the left. + +Maps to the [`corefunc.StrLeftPad()`](https://pkg.go.dev/github.com/northwood-labs/terraform-provider-corefunc/corefunc#StrLeftPad) Go method, which can be used in [Terratest](https://terratest.gruntwork.io). + +## Signature + + +```text +str_leftpad(str string, pad_width number, pad_char string...) string +``` + +## Example Usage + +```terraform +output "leftpad" { + value = provider::corefunc::str_leftpad("foo", 5, ".") +} + +#=> ..foo +``` + +## Arguments + + +1. `str` (String) The string to pad with padding characters. +1. `pad_width` (Number) The max number of padding characters to pad the string with. + +1. `pad_char` (Variadic, String) The padding character to use. Only supports a single byte. If more than one byte is provided, only the first byte will be used. The default value is a space character. + + diff --git a/examples/data-sources/corefunc_int_leftpad/versions.tftpl b/examples/data-sources/corefunc_int_leftpad/versions.tf similarity index 100% rename from examples/data-sources/corefunc_int_leftpad/versions.tftpl rename to examples/data-sources/corefunc_int_leftpad/versions.tf diff --git a/examples/data-sources/corefunc_str_leftpad/versions.tftpl b/examples/data-sources/corefunc_str_leftpad/versions.tf similarity index 100% rename from examples/data-sources/corefunc_str_leftpad/versions.tftpl rename to examples/data-sources/corefunc_str_leftpad/versions.tf diff --git a/examples/functions/corefunc_int_leftpad/function.tf b/examples/functions/corefunc_int_leftpad/function.tf new file mode 100644 index 0000000..94dedc0 --- /dev/null +++ b/examples/functions/corefunc_int_leftpad/function.tf @@ -0,0 +1,5 @@ +output "leftpad" { + value = provider::corefunc::int_leftpad(123, 5) +} + +#=> 00123 diff --git a/examples/functions/corefunc_int_leftpad/versions.tf b/examples/functions/corefunc_int_leftpad/versions.tf new file mode 100644 index 0000000..370ac6a --- /dev/null +++ b/examples/functions/corefunc_int_leftpad/versions.tf @@ -0,0 +1,13 @@ +terraform { + required_version = "~> 1.8" + + required_providers { + corefunc = { + source = "northwood-labs/corefunc" + version = "~> 1.4" + } + } +} + +# There are no configuration options +provider "corefunc" {} diff --git a/examples/functions/corefunc_str_leftpad/function.tf b/examples/functions/corefunc_str_leftpad/function.tf new file mode 100644 index 0000000..9036ef0 --- /dev/null +++ b/examples/functions/corefunc_str_leftpad/function.tf @@ -0,0 +1,5 @@ +output "leftpad" { + value = provider::corefunc::str_leftpad("foo", 5, ".") +} + +#=> ..foo diff --git a/examples/functions/corefunc_str_leftpad/versions.tf b/examples/functions/corefunc_str_leftpad/versions.tf new file mode 100644 index 0000000..370ac6a --- /dev/null +++ b/examples/functions/corefunc_str_leftpad/versions.tf @@ -0,0 +1,13 @@ +terraform { + required_version = "~> 1.8" + + required_providers { + corefunc = { + source = "northwood-labs/corefunc" + version = "~> 1.4" + } + } +} + +# There are no configuration options +provider "corefunc" {} diff --git a/generator/corefuncprovider/function.gotmpl b/generator/corefuncprovider/function.gotmpl index 5d5b7a5..61876ce 100644 --- a/generator/corefuncprovider/function.gotmpl +++ b/generator/corefuncprovider/function.gotmpl @@ -65,11 +65,6 @@ func (f *{{ .CamelStrip }}Function) Definition( resp.Definition = function.Definition{ Summary: "@TODO", - Description: strings.TrimSpace(dedent.Dedent(` - Converts a string to ` + "`" + `snake_case` + "`" + `, removing any non-alphanumeric characters. - - Maps to the {{ .PascalStrip }} Go method, which can be used in Terratest. - `)), MarkdownDescription: strings.TrimSpace(dedent.Dedent(` Converts a string to ` + "`" + `snake_case` + "`" + `, removing any non-alphanumeric characters. diff --git a/generator/templates/function.md.gotmpl b/generator/templates/function.md.gotmpl index 6243827..e5c0d39 100644 --- a/generator/templates/function.md.gotmpl +++ b/generator/templates/function.md.gotmpl @@ -17,10 +17,13 @@ description: |- ## Example Usage -{{"{{"}} tffile "examples/functions/{{ .Snake }}/function.tf" {{"}}"}} +{{"{{"}} tffile (printf "examples/functions/corefunc_%s/function.tf" .Name){{"}}"}} ## Arguments {{"{{"}} .FunctionArgumentsMarkdown | trimspace {{"}}"}} +{{"{{"}} if .HasVariadic -{{"}}"}} +{{"{{"}}- .FunctionVariadicArgumentMarkdown | trimspace -{{"}}"}} +{{"{{"}}- end {{"}}"}} diff --git a/templates/functions.md.tmpl b/templates/functions.md.tmpl index 036f5aa..5e85dd3 100644 --- a/templates/functions.md.tmpl +++ b/templates/functions.md.tmpl @@ -15,10 +15,15 @@ description: |- {{ .FunctionSignatureMarkdown }} -{{ if .HasExample -}}## Example Usage +## Example Usage -{{ tffile (printf "examples/functions/%s/function.tf" .Name)}}{{- end }} +{{ tffile (printf "examples/functions/corefunc_%s/function.tf" .Name)}} + +## Arguments {{ .FunctionArgumentsMarkdown | trimspace }} +{{ if .HasVariadic -}} +{{- .FunctionVariadicArgumentMarkdown | trimspace -}} +{{- end }} diff --git a/templates/functions/env_ensure.md.tmpl b/templates/functions/env_ensure.md.tmpl index 02e3a83..4dae37e 100644 --- a/templates/functions/env_ensure.md.tmpl +++ b/templates/functions/env_ensure.md.tmpl @@ -40,5 +40,8 @@ AWS_DEFAULT_REGION="us-east-1" AWS_VAULT="dev" terraform plan ## Arguments {{ .FunctionArgumentsMarkdown | trimspace }} +{{ if .HasVariadic -}} +{{- .FunctionVariadicArgumentMarkdown | trimspace -}} +{{- end }} diff --git a/templates/functions/homedir_expand.md.tmpl b/templates/functions/homedir_expand.md.tmpl deleted file mode 100644 index c92906a..0000000 --- a/templates/functions/homedir_expand.md.tmpl +++ /dev/null @@ -1,26 +0,0 @@ - - -# {{ .Name }} ({{ .Type }}) - -{{ .Description | trimspace }} - -## Signature - -{{ .FunctionSignatureMarkdown }} - -## Example Usage - -{{ tffile "examples/functions/corefunc_homedir_expand/function.tf" }} - -## Arguments - -{{ .FunctionArgumentsMarkdown | trimspace }} - - diff --git a/templates/functions/str_camel.md.tmpl b/templates/functions/str_camel.md.tmpl deleted file mode 100644 index a146a0d..0000000 --- a/templates/functions/str_camel.md.tmpl +++ /dev/null @@ -1,26 +0,0 @@ - - -# {{ .Name }} ({{ .Type }}) - -{{ .Description | trimspace }} - -## Signature - -{{ .FunctionSignatureMarkdown }} - -## Example Usage - -{{ tffile "examples/functions/corefunc_str_camel/function.tf" }} - -## Arguments - -{{ .FunctionArgumentsMarkdown | trimspace }} - - diff --git a/templates/functions/str_constant.md.tmpl b/templates/functions/str_constant.md.tmpl deleted file mode 100644 index 020064e..0000000 --- a/templates/functions/str_constant.md.tmpl +++ /dev/null @@ -1,26 +0,0 @@ - - -# {{ .Name }} ({{ .Type }}) - -{{ .Description | trimspace }} - -## Signature - -{{ .FunctionSignatureMarkdown }} - -## Example Usage - -{{ tffile "examples/functions/corefunc_str_constant/function.tf" }} - -## Arguments - -{{ .FunctionArgumentsMarkdown | trimspace }} - - diff --git a/templates/functions/str_kebab.md.tmpl b/templates/functions/str_kebab.md.tmpl deleted file mode 100644 index 51eb677..0000000 --- a/templates/functions/str_kebab.md.tmpl +++ /dev/null @@ -1,26 +0,0 @@ - - -# {{ .Name }} ({{ .Type }}) - -{{ .Description | trimspace }} - -## Signature - -{{ .FunctionSignatureMarkdown }} - -## Example Usage - -{{ tffile "examples/functions/corefunc_str_kebab/function.tf" }} - -## Arguments - -{{ .FunctionArgumentsMarkdown | trimspace }} - - diff --git a/templates/functions/str_pascal.md.tmpl b/templates/functions/str_pascal.md.tmpl deleted file mode 100644 index 089da85..0000000 --- a/templates/functions/str_pascal.md.tmpl +++ /dev/null @@ -1,26 +0,0 @@ - - -# {{ .Name }} ({{ .Type }}) - -{{ .Description | trimspace }} - -## Signature - -{{ .FunctionSignatureMarkdown }} - -## Example Usage - -{{ tffile "examples/functions/corefunc_str_pascal/function.tf" }} - -## Arguments - -{{ .FunctionArgumentsMarkdown | trimspace }} - - diff --git a/templates/functions/str_snake.md.tmpl b/templates/functions/str_snake.md.tmpl deleted file mode 100644 index c2d205b..0000000 --- a/templates/functions/str_snake.md.tmpl +++ /dev/null @@ -1,26 +0,0 @@ - - -# {{ .Name }} ({{ .Type }}) - -{{ .Description | trimspace }} - -## Signature - -{{ .FunctionSignatureMarkdown }} - -## Example Usage - -{{ tffile "examples/functions/corefunc_str_snake/function.tf" }} - -## Arguments - -{{ .FunctionArgumentsMarkdown | trimspace }} - - diff --git a/terratest/functions/leftpad.tf b/terratest/functions/leftpad.tf new file mode 100644 index 0000000..be411be --- /dev/null +++ b/terratest/functions/leftpad.tf @@ -0,0 +1,9 @@ +output "str_leftpad_fn" { + description = "This is a string leftpad output." + value = provider::corefunc::str_leftpad("abc", 5, ".") +} + +output "int_leftpad_fn" { + description = "This is a numeric leftpad output." + value = provider::corefunc::int_leftpad(123, 5) +} diff --git a/terratest/functions/terraform_test.go b/terratest/functions/terraform_test.go index 8484db4..5f113bd 100644 --- a/terratest/functions/terraform_test.go +++ b/terratest/functions/terraform_test.go @@ -103,8 +103,8 @@ func TestTerraform(t *testing.T) { assert.Equal(t, terraform.Output(t, terraformOptions, "str_kebab_fn"), corefunc.StrKebab(inputStr)) assert.Equal(t, terraform.Output(t, terraformOptions, "str_pascal_fn"), corefunc.StrPascal(inputStr, false)) assert.Equal(t, terraform.Output(t, terraformOptions, "str_snake_fn"), corefunc.StrSnake(inputStr)) - // assert.Equal(t, terraform.Output(t, terraformOptions, "int_leftpad_ds"), corefunc.IntLeftPad(123, 5)) - // assert.Equal(t, terraform.Output(t, terraformOptions, "str_leftpad_ds"), corefunc.StrLeftPad("abc", 5, '.')) + assert.Equal(t, terraform.Output(t, terraformOptions, "int_leftpad_fn"), corefunc.IntLeftPad(123, 5)) + assert.Equal(t, terraform.Output(t, terraformOptions, "str_leftpad_fn"), corefunc.StrLeftPad("abc", 5, '.')) assert.Equal(t, terraform.Output(t, terraformOptions, "env_ensure_fn"), os.Getenv("GOROOT")) // assert.Equal(t, // terraform.Output(t, terraformOptions, "str_truncate_ds"),