Skip to content

Commit d69dad0

Browse files
authored
Fix provider::terraform::* function names (#2046)
Follow up of hashicorp/terraform#34830
1 parent b7bc5fe commit d69dad0

File tree

6 files changed

+20
-20
lines changed

6 files changed

+20
-20
lines changed

integrationtest/inspection/functions/main.tf

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,5 +11,5 @@ resource "aws_instance" "provider" {
1111
}
1212

1313
resource "aws_instance" "builtin_provider" {
14-
instance_type = provider::terraform::tfvarsencode({ a = 1 })
14+
instance_type = provider::terraform::encode_tfvars({ a = 1 })
1515
}

integrationtest/inspection/functions/result.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -55,7 +55,7 @@
5555
},
5656
"end": {
5757
"line": 14,
58-
"column": 63
58+
"column": 64
5959
}
6060
},
6161
"callers": []

terraform/evaluator_test.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -158,7 +158,7 @@ variable "string_var" {
158158
},
159159
{
160160
name: "built-in provider-defined functions",
161-
expr: expr(`provider::terraform::tfvarsdecode("a = 1")`),
161+
expr: expr(`provider::terraform::decode_tfvars("a = 1")`),
162162
ty: cty.Object(map[string]cty.Type{"a": cty.Number}),
163163
want: `cty.ObjectVal(map[string]cty.Value{"a":cty.NumberIntVal(1)})`,
164164
errCheck: neverHappend,

terraform/lang/funcs/terraform/functions.go

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ import (
1515
"github.com/zclconf/go-cty/cty/function"
1616
)
1717

18-
var TFVarsEncodeFunc = function.New(&function.Spec{
18+
var EncodeTfvarsFunc = function.New(&function.Spec{
1919
Params: []function.Parameter{
2020
{
2121
Name: "value",
@@ -88,7 +88,7 @@ var TFVarsEncodeFunc = function.New(&function.Spec{
8888
},
8989
})
9090

91-
var TFVarsDecodeFunc = function.New(&function.Spec{
91+
var DecodeTfvarsFunc = function.New(&function.Spec{
9292
Params: []function.Parameter{
9393
{
9494
Name: "src",
@@ -131,7 +131,7 @@ var TFVarsDecodeFunc = function.New(&function.Spec{
131131
// stuff HCL diagnostics into plain string error messages. This produces
132132
// a non-ideal result but is still better than hiding the HCL-provided
133133
// diagnosis altogether.
134-
f, hclDiags := hclsyntax.ParseConfig(src, "<tfvarsdecode argument>", hcl.InitialPos)
134+
f, hclDiags := hclsyntax.ParseConfig(src, "<decode_tfvars argument>", hcl.InitialPos)
135135
if hclDiags.HasErrors() {
136136
return cty.NilVal, fmt.Errorf("invalid tfvars syntax: %s", hclDiags.Error())
137137
}
@@ -155,7 +155,7 @@ var TFVarsDecodeFunc = function.New(&function.Spec{
155155
},
156156
})
157157

158-
var ExprEncodeFunc = function.New(&function.Spec{
158+
var EncodeExprFunc = function.New(&function.Spec{
159159
Params: []function.Parameter{
160160
{
161161
Name: "value",

terraform/lang/funcs/terraform/functions_test.go

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ import (
1111
"github.com/zclconf/go-cty/cty"
1212
)
1313

14-
func TestTFVarsEncode(t *testing.T) {
14+
func TestEncodeTfvars(t *testing.T) {
1515
tests := []struct {
1616
Input cty.Value
1717
Want cty.Value
@@ -128,7 +128,7 @@ two = 2
128128

129129
for _, test := range tests {
130130
t.Run(test.Input.GoString(), func(t *testing.T) {
131-
got, err := TFVarsEncodeFunc.Call([]cty.Value{test.Input})
131+
got, err := EncodeTfvarsFunc.Call([]cty.Value{test.Input})
132132
if test.WantErr != "" {
133133
if err == nil {
134134
t.Fatalf("unexpected success for %#v; want error\ngot: %#v", test.Input, got)
@@ -148,7 +148,7 @@ two = 2
148148
}
149149
}
150150

151-
func TestTFVarsDecode(t *testing.T) {
151+
func TestDecodeTfvars(t *testing.T) {
152152
tests := []struct {
153153
Input cty.Value
154154
Want cty.Value
@@ -179,25 +179,25 @@ number = 2`),
179179
// This is actually not a very good diagnosis for this error,
180180
// since we're expecting HCL arguments rather than HCL blocks,
181181
// but that's something we'd need to address in HCL.
182-
WantErr: `invalid tfvars syntax: <tfvarsdecode argument>:1,17-17: Invalid block definition; Either a quoted string block label or an opening brace ("{") is expected here.`,
182+
WantErr: `invalid tfvars syntax: <decode_tfvars argument>:1,17-17: Invalid block definition; Either a quoted string block label or an opening brace ("{") is expected here.`,
183183
},
184184
{
185185
Input: cty.StringVal(`foo = not valid syntax`),
186-
WantErr: `invalid tfvars syntax: <tfvarsdecode argument>:1,11-16: Missing newline after argument; An argument definition must end with a newline.`,
186+
WantErr: `invalid tfvars syntax: <decode_tfvars argument>:1,11-16: Missing newline after argument; An argument definition must end with a newline.`,
187187
},
188188
{
189189
Input: cty.StringVal(`foo = var.whatever`),
190-
WantErr: `invalid expression for variable "foo": <tfvarsdecode argument>:1,7-10: Variables not allowed; Variables may not be used here.`,
190+
WantErr: `invalid expression for variable "foo": <decode_tfvars argument>:1,7-10: Variables not allowed; Variables may not be used here.`,
191191
},
192192
{
193193
Input: cty.StringVal(`foo = whatever()`),
194-
WantErr: `invalid expression for variable "foo": <tfvarsdecode argument>:1,7-17: Function calls not allowed; Functions may not be called here.`,
194+
WantErr: `invalid expression for variable "foo": <decode_tfvars argument>:1,7-17: Function calls not allowed; Functions may not be called here.`,
195195
},
196196
}
197197

198198
for _, test := range tests {
199199
t.Run(test.Input.GoString(), func(t *testing.T) {
200-
got, err := TFVarsDecodeFunc.Call([]cty.Value{test.Input})
200+
got, err := DecodeTfvarsFunc.Call([]cty.Value{test.Input})
201201
if test.WantErr != "" {
202202
if err == nil {
203203
t.Fatalf("unexpected success for %#v; want error\ngot: %#v", test.Input, got)
@@ -217,7 +217,7 @@ number = 2`),
217217
}
218218
}
219219

220-
func TestExprEncode(t *testing.T) {
220+
func TestEncodeExpr(t *testing.T) {
221221
tests := []struct {
222222
Input cty.Value
223223
Want cty.Value
@@ -361,7 +361,7 @@ func TestExprEncode(t *testing.T) {
361361

362362
for _, test := range tests {
363363
t.Run(test.Input.GoString(), func(t *testing.T) {
364-
got, err := ExprEncodeFunc.Call([]cty.Value{test.Input})
364+
got, err := EncodeExprFunc.Call([]cty.Value{test.Input})
365365
if test.WantErr != "" {
366366
if err == nil {
367367
t.Fatalf("unexpected success for %#v; want error\ngot: %#v", test.Input, got)

terraform/lang/functions.go

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -178,9 +178,9 @@ func (s *Scope) Functions() map[string]function.Function {
178178

179179
// Built-in Terraform provider-defined functions are typically obtained dynamically,
180180
// but given that they are built-ins, they are provided just like regular functions.
181-
s.funcs["provider::terraform::tfvarsencode"] = terraform.TFVarsEncodeFunc
182-
s.funcs["provider::terraform::tfvarsdecode"] = terraform.TFVarsDecodeFunc
183-
s.funcs["provider::terraform::exprencode"] = terraform.ExprEncodeFunc
181+
s.funcs["provider::terraform::encode_tfvars"] = terraform.EncodeTfvarsFunc
182+
s.funcs["provider::terraform::decode_tfvars"] = terraform.DecodeTfvarsFunc
183+
s.funcs["provider::terraform::encode_expr"] = terraform.EncodeExprFunc
184184
}
185185
s.funcsLock.Unlock()
186186

0 commit comments

Comments
 (0)