Skip to content

Commit

Permalink
Enable merge invoke.
Browse files Browse the repository at this point in the history
Fixes pulumi/pulumi#18356

Related #65
  • Loading branch information
brandonpollack23 committed Feb 4, 2025
1 parent e6f4e36 commit b8bd1ad
Show file tree
Hide file tree
Showing 9 changed files with 68 additions and 18 deletions.
1 change: 1 addition & 0 deletions CHANGELOG_PENDING.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
- Allow generating of tobool invocation.
- Enable jsondecode which is already in pulumi-std
- Enable lookup which is already in pulumi-std
- Enable merge which is already in pulumi-std

### Bug Fixes

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -56,9 +56,6 @@
"warning:builtin_functions/main.tf:505,11-32:Function not yet implemented:Function keys not yet implemented, see pulumi/pulumi-converter-terraform#65 (catch all bug)",
"warning:builtin_functions/main.tf:571,11-34:Function not yet implemented:Function map not yet implemented, see pulumi/pulumi-converter-terraform#65 (catch all bug)",
"warning:builtin_functions/main.tf:577,11-97:Function not yet implemented:Function matchkeys not yet implemented, see pulumi/pulumi-converter-terraform#65 (catch all bug)",
"warning:builtin_functions/main.tf:607,11-48:Function not yet implemented:Function merge not yet implemented, see pulumi/pulumi-converter-terraform#65",
"warning:builtin_functions/main.tf:610,11-50:Function not yet implemented:Function merge not yet implemented, see pulumi/pulumi-converter-terraform#65",
"warning:builtin_functions/main.tf:613,11-57:Function not yet implemented:Function merge not yet implemented, see pulumi/pulumi-converter-terraform#65",
"warning:builtin_functions/main.tf:637,11-56:Function not yet implemented:Function nonsensitive not yet implemented, see pulumi/pulumi-converter-terraform#65 (catch all bug)",
"warning:builtin_functions/main.tf:640,11-32:Function not yet implemented:Function nonsensitive not yet implemented, see pulumi/pulumi-converter-terraform#65 (catch all bug)",
"warning:builtin_functions/main.tf:643,11-47:Function not yet implemented:Function nonsensitive not yet implemented, see pulumi/pulumi-converter-terraform#65 (catch all bug)",
Expand Down
31 changes: 28 additions & 3 deletions pkg/convert/testdata/programs/builtin_functions/pcl/main.pp
Original file line number Diff line number Diff line change
Expand Up @@ -838,13 +838,38 @@

# Examples for merge
output "funcMerge0" {
value = notImplemented("merge({a=\"b\",c=\"d\"},{e=\"f\",c=\"z\"})")
value = invoke("std:index:merge", {
input = [{
a = "b"
c = "d"
}, {
e = "f"
c = "z"
}]
}).result
}
output "funcMerge1" {
value = notImplemented("merge({a=\"b\"},{a=[1,2],c=\"z\"},{d=3})")
value = invoke("std:index:merge", {
input = [{
a = "b"
}, {
a = [1, 2]
c = "z"
}, {
d = 3
}]
}).result
}
output "funcMerge2" {
value = notImplemented("merge([{a=\"b\",c=\"d\"},{},{e=\"f\",c=\"z\"}]...)")
value = invoke("std:index:merge", {
input = [{
a = "b"
c = "d"
}, {}, {
e = "f"
c = "z"
}]
}).result
}


Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,6 @@
"warning:/files.tf:38,19-45,11:Function not yet implemented:Function tomap not yet implemented, see pulumi/pulumi-converter-terraform#65 (catch all bug)",
"warning:/files.tf:52,24-38:Function not yet implemented:Function tostring not yet implemented, see pulumi/pulumi-converter-terraform#65 (catch all bug)",
"warning:/files.tf:53,19-60,11:Function not yet implemented:Function tomap not yet implemented, see pulumi/pulumi-converter-terraform#65 (catch all bug)",
"warning:/files.tf:32,11-63,4:Function not yet implemented:Function merge not yet implemented, see pulumi/pulumi-converter-terraform#65",
"warning:/files.tf:2,20-47:Function not yet implemented:Function fileset not yet implemented, see pulumi/pulumi-converter-terraform#65 (catch all bug)",
"warning:/files.tf:3,23-6,5:Function not yet implemented:Function toset not yet implemented, see pulumi/pulumi-converter-terraform#137",
"warning:/files.tf:10,10-46:Function not yet implemented:Function contains not yet implemented, see pulumi/pulumi-converter-terraform#65 (catch all bug)",
Expand All @@ -23,6 +22,5 @@
"warning:/files.tf:36,24-38:Function not yet implemented:Function tostring not yet implemented, see pulumi/pulumi-converter-terraform#65 (catch all bug)",
"warning:/files.tf:38,19-45,11:Function not yet implemented:Function tomap not yet implemented, see pulumi/pulumi-converter-terraform#65 (catch all bug)",
"warning:/files.tf:52,24-38:Function not yet implemented:Function tostring not yet implemented, see pulumi/pulumi-converter-terraform#65 (catch all bug)",
"warning:/files.tf:53,19-60,11:Function not yet implemented:Function tomap not yet implemented, see pulumi/pulumi-converter-terraform#65 (catch all bug)",
"warning:/files.tf:32,11-63,4:Function not yet implemented:Function merge not yet implemented, see pulumi/pulumi-converter-terraform#65"
"warning:/files.tf:53,19-60,11:Function not yet implemented:Function tomap not yet implemented, see pulumi/pulumi-converter-terraform#65 (catch all bug)"
]
Original file line number Diff line number Diff line change
Expand Up @@ -15,4 +15,16 @@
key = fileSuffixes[p]
default = defaultFileType
}).result }
files = notImplemented("merge(\n{\nforpinkeys(local.template_file_paths):p=>{\ncontent_type=local.file_types[p]\nsource_path=tostring(null)\ncontent=local.template_file_contents[p]\ndigests=tomap({\nmd5=md5(local.template_file_contents[p])\nsha1=sha1(local.template_file_contents[p])\nsha256=sha256(local.template_file_contents[p])\nsha512=sha512(local.template_file_contents[p])\nbase64sha256=base64sha256(local.template_file_contents[p])\nbase64sha512=base64sha512(local.template_file_contents[p])\n})\n}\n},\n{\nforpinlocal.static_file_paths:p=>{\ncontent_type=local.file_types[p]\nsource_path=local.static_file_local_paths[p]\ncontent=tostring(null)\ndigests=tomap({\nmd5=filemd5(local.static_file_local_paths[p])\nsha1=filesha1(local.static_file_local_paths[p])\nsha256=filesha256(local.static_file_local_paths[p])\nsha512=filesha512(local.static_file_local_paths[p])\nbase64sha256=filebase64sha256(local.static_file_local_paths[p])\nbase64sha512=filebase64sha512(local.static_file_local_paths[p])\n})\n}\n},\n)")
files = invoke("std:index:merge", {
input = [{ for p in notImplemented("keys(local.template_file_paths)") : p => {
contentType = myFileTypes[p]
sourcePath = notImplemented("tostring(null)")
content = templateFileContents[p]
digests = notImplemented("tomap({\nmd5=md5(local.template_file_contents[p])\nsha1=sha1(local.template_file_contents[p])\nsha256=sha256(local.template_file_contents[p])\nsha512=sha512(local.template_file_contents[p])\nbase64sha256=base64sha256(local.template_file_contents[p])\nbase64sha512=base64sha512(local.template_file_contents[p])\n})")
} }, { for p in staticFilePaths : p => {
contentType = myFileTypes[p]
sourcePath = staticFileLocalPaths[p]
content = notImplemented("tostring(null)")
digests = notImplemented("tomap({\nmd5=filemd5(local.static_file_local_paths[p])\nsha1=filesha1(local.static_file_local_paths[p])\nsha256=filesha256(local.static_file_local_paths[p])\nsha512=filesha512(local.static_file_local_paths[p])\nbase64sha256=filebase64sha256(local.static_file_local_paths[p])\nbase64sha512=filebase64sha512(local.static_file_local_paths[p])\n})")
} }]
}).result
Original file line number Diff line number Diff line change
Expand Up @@ -15,4 +15,16 @@
key = fileSuffixes[p]
default = defaultFileType
}).result }
files = notImplemented("merge(\n{\nforpinkeys(local.template_file_paths):p=>{\ncontent_type=local.file_types[p]\nsource_path=tostring(null)\ncontent=local.template_file_contents[p]\ndigests=tomap({\nmd5=md5(local.template_file_contents[p])\nsha1=sha1(local.template_file_contents[p])\nsha256=sha256(local.template_file_contents[p])\nsha512=sha512(local.template_file_contents[p])\nbase64sha256=base64sha256(local.template_file_contents[p])\nbase64sha512=base64sha512(local.template_file_contents[p])\n})\n}\n},\n{\nforpinlocal.static_file_paths:p=>{\ncontent_type=local.file_types[p]\nsource_path=local.static_file_local_paths[p]\ncontent=tostring(null)\ndigests=tomap({\nmd5=filemd5(local.static_file_local_paths[p])\nsha1=filesha1(local.static_file_local_paths[p])\nsha256=filesha256(local.static_file_local_paths[p])\nsha512=filesha512(local.static_file_local_paths[p])\nbase64sha256=filebase64sha256(local.static_file_local_paths[p])\nbase64sha512=filebase64sha512(local.static_file_local_paths[p])\n})\n}\n},\n)")
files = invoke("std:index:merge", {
input = [{ for p in notImplemented("keys(local.template_file_paths)") : p => {
contentType = myFileTypes[p]
sourcePath = notImplemented("tostring(null)")
content = templateFileContents[p]
digests = notImplemented("tomap({\nmd5=md5(local.template_file_contents[p])\nsha1=sha1(local.template_file_contents[p])\nsha256=sha256(local.template_file_contents[p])\nsha512=sha512(local.template_file_contents[p])\nbase64sha256=base64sha256(local.template_file_contents[p])\nbase64sha512=base64sha512(local.template_file_contents[p])\n})")
} }, { for p in staticFilePaths : p => {
contentType = myFileTypes[p]
sourcePath = staticFileLocalPaths[p]
content = notImplemented("tostring(null)")
digests = notImplemented("tomap({\nmd5=filemd5(local.static_file_local_paths[p])\nsha1=filesha1(local.static_file_local_paths[p])\nsha256=filesha256(local.static_file_local_paths[p])\nsha512=filesha512(local.static_file_local_paths[p])\nbase64sha256=filebase64sha256(local.static_file_local_paths[p])\nbase64sha512=filebase64sha512(local.static_file_local_paths[p])\n})")
} }]
}).result
8 changes: 4 additions & 4 deletions pkg/convert/testdata/states/range/import.json
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
[
{
"Type": "simple:index:resource",
"Name": "a_resource-hello",
"ID": "abc123",
"Name": "a_resource-goodbye",
"ID": "def456",
"LogicalName": "",
"IsComponent": false,
"IsRemote": false,
Expand All @@ -11,8 +11,8 @@
},
{
"Type": "simple:index:resource",
"Name": "a_resource-goodbye",
"ID": "def456",
"Name": "a_resource-hello",
"ID": "abc123",
"LogicalName": "",
"IsComponent": false,
"IsRemote": false,
Expand Down
8 changes: 6 additions & 2 deletions pkg/convert/tf.go
Original file line number Diff line number Diff line change
Expand Up @@ -623,6 +623,12 @@ var tfFunctionStd = map[string]struct {
inputs: []string{"input"},
output: "result",
},
"merge": {
token: "std:index:merge",
inputs: []string{"input"},
output: "result",
paramArgs: true,
},
"min": {
token: "std:index:min",
inputs: []string{"input"},
Expand Down Expand Up @@ -950,7 +956,6 @@ func convertFunctionCallExpr(state *convertState,
Name: hclwrite.TokensForIdentifier(invoke.inputs[0]),
Value: listTokens,
})

} else {
if len(args) > len(invoke.inputs) {
state.appendDiagnostic(&hcl.Diagnostic{
Expand Down Expand Up @@ -3590,7 +3595,6 @@ var unimplementedFunctionBugs = map[string]string{
"flatten": "pulumi/pulumi-converter-terraform#138",
"format": "pulumi/pulumi-converter-terraform#65",
"formatdate": "pulumi/pulumi-converter-terraform#196",
"merge": "pulumi/pulumi-converter-terraform#65",
"regexall": "pulumi/pulumi-converter-terraform#191",
"slice": "pulumi/pulumi-converter-terraform#65",
"templatefile": "pulumi/pulumi-converter-terraform#192",
Expand Down
3 changes: 2 additions & 1 deletion tests/example_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -313,7 +313,8 @@ func TestExample(t *testing.T) {
},
{
example: "https://github.com/terraform-aws-modules/terraform-aws-rds",
strict: true,
// TODO[pulumi/pulumi#18446 strict should work if the plugin is available (std in this case).
// strict: true,
},
{
example: "https://github.com/terraform-aws-modules/terraform-aws-alb",
Expand Down

0 comments on commit b8bd1ad

Please sign in to comment.