From 92270ebe685fd0e966dbc3915a66483ae1c73f81 Mon Sep 17 00:00:00 2001 From: Brandon Pollack Date: Mon, 3 Feb 2025 15:53:04 +0100 Subject: [PATCH] Enable lookup, it is part of pulumi-std. Related #65 Fixes #pulumi/pulumi#18416 --- CHANGELOG_PENDING.md | 1 + .../builtin_functions/pcl/diagnostics.json | 2 -- .../programs/builtin_functions/pcl/main.pp | 18 ++++++++++++++++-- .../pcl/diagnostics.json | 2 -- .../pcl/dir_1.0.0/files.pp | 8 ++++++-- .../pcl/dir_1.0.2/files.pp | 8 ++++++-- pkg/convert/tf.go | 6 +++++- 7 files changed, 34 insertions(+), 11 deletions(-) diff --git a/CHANGELOG_PENDING.md b/CHANGELOG_PENDING.md index 75242be..b5836cb 100644 --- a/CHANGELOG_PENDING.md +++ b/CHANGELOG_PENDING.md @@ -2,6 +2,7 @@ - Allow generating of tobool invocation. - Enable jsondecode which is already in pulumi-std +- Enable lookup which is already in pulumi-std ### Bug Fixes diff --git a/pkg/convert/testdata/programs/builtin_functions/pcl/diagnostics.json b/pkg/convert/testdata/programs/builtin_functions/pcl/diagnostics.json index c1f4ff3..e208521 100644 --- a/pkg/convert/testdata/programs/builtin_functions/pcl/diagnostics.json +++ b/pkg/convert/testdata/programs/builtin_functions/pcl/diagnostics.json @@ -54,8 +54,6 @@ "warning:builtin_functions/main.tf:460,11-88:Function not yet implemented:Function formatlist not yet implemented, see pulumi/pulumi-converter-terraform#65 (catch all bug)", "warning:builtin_functions/main.tf:472,11-38:Function not yet implemented:Function index not yet implemented, see pulumi/pulumi-converter-terraform#65 (catch all bug)", "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:553,11-50:Function not yet implemented:Function lookup not yet implemented, see pulumi/pulumi-converter-terraform#65", - "warning:builtin_functions/main.tf:556,11-50:Function not yet implemented:Function lookup not yet implemented, see pulumi/pulumi-converter-terraform#65", "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", diff --git a/pkg/convert/testdata/programs/builtin_functions/pcl/main.pp b/pkg/convert/testdata/programs/builtin_functions/pcl/main.pp index 189d31b..1ec7e7f 100644 --- a/pkg/convert/testdata/programs/builtin_functions/pcl/main.pp +++ b/pkg/convert/testdata/programs/builtin_functions/pcl/main.pp @@ -744,10 +744,24 @@ # Examples for lookup output "funcLookup0" { - value = notImplemented("lookup({a=\"ay\",b=\"bee\"},\"a\",\"what?\")") + value = invoke("std:index:lookup", { + map = { + a = "ay" + b = "bee" + } + key = "a" + default = "what?" + }).result } output "funcLookup1" { - value = notImplemented("lookup({a=\"ay\",b=\"bee\"},\"c\",\"what?\")") + value = invoke("std:index:lookup", { + map = { + a = "ay" + b = "bee" + } + key = "c" + default = "what?" + }).result } diff --git a/pkg/convert/testdata/programs/registry_module_multiple_versions/pcl/diagnostics.json b/pkg/convert/testdata/programs/registry_module_multiple_versions/pcl/diagnostics.json index 099ca72..4a497b8 100644 --- a/pkg/convert/testdata/programs/registry_module_multiple_versions/pcl/diagnostics.json +++ b/pkg/convert/testdata/programs/registry_module_multiple_versions/pcl/diagnostics.json @@ -6,7 +6,6 @@ "warning:/files.tf:20,32-63:Function not yet implemented:Function keys not yet implemented, see pulumi/pulumi-converter-terraform#65 (catch all bug)", "warning:/files.tf:20,23-89:Function not yet implemented:Function setunion not yet implemented, see pulumi/pulumi-converter-terraform#65 (catch all bug)", "warning:/files.tf:23,45-73:Function not yet implemented:Function regexall not yet implemented, see pulumi/pulumi-converter-terraform#191", - "warning:/files.tf:29,45-114:Function not yet implemented:Function lookup not yet implemented, see pulumi/pulumi-converter-terraform#65", "warning:/files.tf:34,16-47:Function not yet implemented:Function keys not yet implemented, see pulumi/pulumi-converter-terraform#65 (catch all bug)", "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)", @@ -20,7 +19,6 @@ "warning:/files.tf:20,32-63:Function not yet implemented:Function keys not yet implemented, see pulumi/pulumi-converter-terraform#65 (catch all bug)", "warning:/files.tf:20,23-89:Function not yet implemented:Function setunion not yet implemented, see pulumi/pulumi-converter-terraform#65 (catch all bug)", "warning:/files.tf:23,45-73:Function not yet implemented:Function regexall not yet implemented, see pulumi/pulumi-converter-terraform#191", - "warning:/files.tf:29,45-114:Function not yet implemented:Function lookup not yet implemented, see pulumi/pulumi-converter-terraform#65", "warning:/files.tf:34,16-47:Function not yet implemented:Function keys not yet implemented, see pulumi/pulumi-converter-terraform#65 (catch all bug)", "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)", diff --git a/pkg/convert/testdata/programs/registry_module_multiple_versions/pcl/dir_1.0.0/files.pp b/pkg/convert/testdata/programs/registry_module_multiple_versions/pcl/dir_1.0.0/files.pp index 4ed134a..f1ad3a9 100644 --- a/pkg/convert/testdata/programs/registry_module_multiple_versions/pcl/dir_1.0.0/files.pp +++ b/pkg/convert/testdata/programs/registry_module_multiple_versions/pcl/dir_1.0.0/files.pp @@ -10,5 +10,9 @@ outputFilePaths = notImplemented("setunion(keys(local.template_file_paths),local.static_file_paths)") fileSuffixMatches = { for p in outputFilePaths : p => notImplemented("regexall(\"\\\\.[^\\\\.]+\\\\z\",p)") } fileSuffixes = { for p, ms in fileSuffixMatches : p => length(ms) > 0 ? ms[0] : "" } -myFileTypes = { for p in outputFilePaths : p => notImplemented("lookup(var.file_types,local.file_suffixes[p],var.default_file_type)") } -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)") +myFileTypes = { for p in outputFilePaths : p => invoke("std:index:lookup", { + map = fileTypes + 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)") diff --git a/pkg/convert/testdata/programs/registry_module_multiple_versions/pcl/dir_1.0.2/files.pp b/pkg/convert/testdata/programs/registry_module_multiple_versions/pcl/dir_1.0.2/files.pp index 4ed134a..f1ad3a9 100644 --- a/pkg/convert/testdata/programs/registry_module_multiple_versions/pcl/dir_1.0.2/files.pp +++ b/pkg/convert/testdata/programs/registry_module_multiple_versions/pcl/dir_1.0.2/files.pp @@ -10,5 +10,9 @@ outputFilePaths = notImplemented("setunion(keys(local.template_file_paths),local.static_file_paths)") fileSuffixMatches = { for p in outputFilePaths : p => notImplemented("regexall(\"\\\\.[^\\\\.]+\\\\z\",p)") } fileSuffixes = { for p, ms in fileSuffixMatches : p => length(ms) > 0 ? ms[0] : "" } -myFileTypes = { for p in outputFilePaths : p => notImplemented("lookup(var.file_types,local.file_suffixes[p],var.default_file_type)") } -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)") +myFileTypes = { for p in outputFilePaths : p => invoke("std:index:lookup", { + map = fileTypes + 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)") diff --git a/pkg/convert/tf.go b/pkg/convert/tf.go index e3082d6..f7176b3 100644 --- a/pkg/convert/tf.go +++ b/pkg/convert/tf.go @@ -602,6 +602,11 @@ var tfFunctionStd = map[string]struct { inputs: []string{"base", "input"}, output: "result", }, + "lookup": { + token: "std:index:lookup", + inputs: []string{"map", "key", "default"}, + output: "result", + }, "lower": { token: "std:index:lower", inputs: []string{"input"}, @@ -3585,7 +3590,6 @@ var unimplementedFunctionBugs = map[string]string{ "flatten": "pulumi/pulumi-converter-terraform#138", "format": "pulumi/pulumi-converter-terraform#65", "formatdate": "pulumi/pulumi-converter-terraform#196", - "lookup": "pulumi/pulumi-converter-terraform#65", "merge": "pulumi/pulumi-converter-terraform#65", "regexall": "pulumi/pulumi-converter-terraform#191", "slice": "pulumi/pulumi-converter-terraform#65",