Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Use regex and regexall from pulumi-std #290

Merged
merged 1 commit into from
Feb 13, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion CHANGELOG_PENDING.md
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,8 @@
- Implement `contains` through the `pulumi-std` invoke of the same name
- Implement `chunklist` through the `pulumi-std` invoke of the same name
- Implement `slice` through the `pulumi-std` invoke of the same name
- Implement `regex(all)` through the `pulumi-std` invokes of the same name

### Bug Fixes

- Fix the order of arguments to `substr`
- Fix the order of arguments to `substr`
Original file line number Diff line number Diff line change
Expand Up @@ -37,13 +37,6 @@
"warning:builtin_functions/main.tf:670,15-41:Function not yet implemented:Function toset not yet implemented, see pulumi/pulumi-converter-terraform#137",
"warning:builtin_functions/main.tf:670,11-42:Function not yet implemented:Function one not yet implemented, see pulumi/pulumi-converter-terraform#65 (catch all bug)",
"warning:builtin_functions/main.tf:706,11-26:Function not yet implemented:Function plantimestamp not yet implemented, see pulumi/pulumi-converter-terraform#65 (catch all bug)",
"warning:builtin_functions/main.tf:742,11-59:Function not yet implemented:Function regex not yet implemented, see pulumi/pulumi-converter-terraform#65 (catch all bug)",
"warning:builtin_functions/main.tf:745,11-66:Function not yet implemented:Function regex not yet implemented, see pulumi/pulumi-converter-terraform#65 (catch all bug)",
"warning:builtin_functions/main.tf:748,11-106:Function not yet implemented:Function regex not yet implemented, see pulumi/pulumi-converter-terraform#65 (catch all bug)",
"warning:builtin_functions/main.tf:751,11-50:Function not yet implemented:Function regex not yet implemented, see pulumi/pulumi-converter-terraform#65 (catch all bug)",
"warning:builtin_functions/main.tf:757,11-50:Function not yet implemented:Function regexall not yet implemented, see pulumi/pulumi-converter-terraform#191",
"warning:builtin_functions/main.tf:760,18-57:Function not yet implemented:Function regexall not yet implemented, see pulumi/pulumi-converter-terraform#191",
"warning:builtin_functions/main.tf:763,18-49:Function not yet implemented:Function regexall not yet implemented, see pulumi/pulumi-converter-terraform#191",
"warning:builtin_functions/main.tf:778,11-29:Function not yet implemented:Function reverse not yet implemented, see pulumi/pulumi-converter-terraform#65 (catch all bug)",
"warning:builtin_functions/main.tf:808,11-67:Function not yet implemented:Function setproduct not yet implemented, see pulumi/pulumi-converter-terraform#65 (catch all bug)",
"warning:builtin_functions/main.tf:811,11-35:Function not yet implemented:Function setproduct not yet implemented, see pulumi/pulumi-converter-terraform#65 (catch all bug)",
Expand Down
35 changes: 28 additions & 7 deletions pkg/convert/testdata/programs/builtin_functions/pcl/main.pp
Original file line number Diff line number Diff line change
Expand Up @@ -1150,29 +1150,50 @@

# Examples for regex
output "funcRegex0" {
value = notImplemented("regex(\"[a-z]+\",\"53453453.345345aaabbbccc23454\")")
value = invoke("std:index:regex", {
pattern = "[a-z]+"
string = "53453453.345345aaabbbccc23454"
}).result
}
output "funcRegex1" {
value = notImplemented("regex(\"(\\\\d\\\\d\\\\d\\\\d)-(\\\\d\\\\d)-(\\\\d\\\\d)\",\"2019-02-01\")")
value = invoke("std:index:regex", {
pattern = "(\\d\\d\\d\\d)-(\\d\\d)-(\\d\\d)"
string = "2019-02-01"
}).result
}
output "funcRegex2" {
value = notImplemented("regex(\"^(?:(?P<scheme>[^:/?#]+):)?(?://(?P<authority>[^/?#]*))?\",\"https://terraform.io/docs/\")")
value = invoke("std:index:regex", {
pattern = "^(?:(?P<scheme>[^:/?#]+):)?(?://(?P<authority>[^/?#]*))?"
string = "https://terraform.io/docs/"
}).result
}
output "funcRegex3" {
value = notImplemented("regex(\"[a-z]+\",\"53453453.34534523454\")")
value = invoke("std:index:regex", {
pattern = "[a-z]+"
string = "53453453.34534523454"
}).result
}



# Examples for regexall
output "funcRegexall0" {
value = notImplemented("regexall(\"[a-z]+\",\"1234abcd5678efgh9\")")
value = invoke("std:index:regexall", {
pattern = "[a-z]+"
string = "1234abcd5678efgh9"
}).result
}
output "funcRegexall1" {
value = length(notImplemented("regexall(\"[a-z]+\",\"1234abcd5678efgh9\")"))
value = length(invoke("std:index:regexall", {
pattern = "[a-z]+"
string = "1234abcd5678efgh9"
}).result)
}
output "funcRegexall2" {
value = length(notImplemented("regexall(\"[a-z]+\",\"123456789\")")) > 0
value = length(invoke("std:index:regexall", {
pattern = "[a-z]+"
string = "123456789"
}).result) > 0
}


Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@
"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:14,51-107:Function not yet implemented:Function templatefile not yet implemented, see pulumi/pulumi-converter-terraform#192",
"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: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)",
Expand All @@ -12,7 +11,6 @@
"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:14,51-107:Function not yet implemented:Function templatefile not yet implemented, see pulumi/pulumi-converter-terraform#192",
"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: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)",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,11 @@
templateFileContents = { for p, sp in templateFilePaths : p => notImplemented("templatefile(\"$${var.base_dir}/$${sp}\",var.template_vars)") }
staticFileLocalPaths = { for p in staticFilePaths : p => "${baseDir}/${p}" }
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] : "" }
fileSuffixMatches = { for p in outputFilePaths : p => invoke("std:index:regexall", {
pattern = "\\.[^\\.]+\\z"
string = p
}).result }
fileSuffixes = { for p, ms in fileSuffixMatches : p => length(ms) > 0 ? ms[0] : "" }
myFileTypes = { for p in outputFilePaths : p => invoke("std:index:lookup", {
map = fileTypes
key = fileSuffixes[p]
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,11 @@
templateFileContents = { for p, sp in templateFilePaths : p => notImplemented("templatefile(\"$${var.base_dir}/$${sp}\",var.template_vars)") }
staticFileLocalPaths = { for p in staticFilePaths : p => "${baseDir}/${p}" }
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] : "" }
fileSuffixMatches = { for p in outputFilePaths : p => invoke("std:index:regexall", {
pattern = "\\.[^\\.]+\\z"
string = p
}).result }
fileSuffixes = { for p, ms in fileSuffixMatches : p => length(ms) > 0 ? ms[0] : "" }
myFileTypes = { for p in outputFilePaths : p => invoke("std:index:lookup", {
map = fileTypes
key = fileSuffixes[p]
Expand Down
11 changes: 10 additions & 1 deletion pkg/convert/tf.go
Original file line number Diff line number Diff line change
Expand Up @@ -703,6 +703,16 @@ var tfFunctionStd = map[string]struct {
inputs: []string{"limit", "start", "step"},
output: "result",
},
"regex": {
token: "std:index:regex",
inputs: []string{"pattern", "string"},
output: "result",
},
"regexall": {
token: "std:index:regexall",
inputs: []string{"pattern", "string"},
output: "result",
},
"replace": {
token: "std:index:replace",
inputs: []string{"text", "search", "replace"},
Expand Down Expand Up @@ -3666,7 +3676,6 @@ func componentProgramBinderFromAfero(fs afero.Fs) pcl.ComponentProgramBinder {

var unimplementedFunctionBugs = map[string]string{
"formatdate": "pulumi/pulumi-converter-terraform#196",
"regexall": "pulumi/pulumi-converter-terraform#191",
"templatefile": "pulumi/pulumi-converter-terraform#192",
"toset": "pulumi/pulumi-converter-terraform#137",
"try": "pulumi/pulumi-converter-terraform#16",
Expand Down
Loading