Skip to content

Commit

Permalink
Implement the regex and regexall function
Browse files Browse the repository at this point in the history
This should be implemented in the newly released `pulumi-std` 2.2.0, so
we can start generating invoke calls for it.

Blocked by pulumi/pulumi-std#90

Related #65
Fixes #191
Fixes pulumi/pulumi#18520
  • Loading branch information
brandonpollack23 committed Feb 12, 2025
1 parent cac6a10 commit 23ec910
Show file tree
Hide file tree
Showing 7 changed files with 49 additions and 21 deletions.
1 change: 1 addition & 0 deletions CHANGELOG_PENDING.md
Original file line number Diff line number Diff line change
Expand Up @@ -15,5 +15,6 @@
- Implement `contains` through the `pulumi-std` invoke of the same name
- Implement `keys` through the `pulumi-std` invoke of the same name
- Implement `setintersection` through the `pulumi-std` invoke of the same name
- Implement `regex(all)` through the `pulumi-std` invokes of the same name

### Bug Fixes
Original file line number Diff line number Diff line change
Expand Up @@ -39,13 +39,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 @@ -1144,29 +1144,50 @@

# Examples for regex
output "funcRegex0" {
value = notImplemented("regex(\"[a-z]+\",\"53453453.345345aaabbbccc23454\")")
value = invoke("std:index:regex", {
regex = "[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", {
regex = "(\\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", {
regex = "^(?:(?P<scheme>[^:/?#]+):)?(?://(?P<authority>[^/?#]*))?"
string = "https://terraform.io/docs/"
}).result
}
output "funcRegex3" {
value = notImplemented("regex(\"[a-z]+\",\"53453453.34534523454\")")
value = invoke("std:index:regex", {
regex = "[a-z]+"
string = "53453453.34534523454"
}).result
}



# Examples for regexall
output "funcRegexall0" {
value = notImplemented("regexall(\"[a-z]+\",\"1234abcd5678efgh9\")")
value = invoke("std:index:regex", {
regex = "[a-z]+"
string = "1234abcd5678efgh9"
}).result
}
output "funcRegexall1" {
value = length(notImplemented("regexall(\"[a-z]+\",\"1234abcd5678efgh9\")"))
value = length(invoke("std:index:regex", {
regex = "[a-z]+"
string = "1234abcd5678efgh9"
}).result)
}
output "funcRegexall2" {
value = length(notImplemented("regexall(\"[a-z]+\",\"123456789\")")) > 0
value = length(invoke("std:index:regex", {
regex = "[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:regex", {
regex = "\\.[^\\.]+\\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:regex", {
regex = "\\.[^\\.]+\\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 @@ -698,6 +698,16 @@ var tfFunctionStd = map[string]struct {
inputs: []string{"limit", "start", "step"},
output: "result",
},
"regex": {
token: "std:index:regex",
inputs: []string{"regex", "string"},
output: "result",
},
"regexall": {
token: "std:index:regex",
inputs: []string{"regex", "string"},
output: "result",
},
"replace": {
token: "std:index:replace",
inputs: []string{"text", "search", "replace"},
Expand Down Expand Up @@ -3655,7 +3665,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",
"slice": "pulumi/pulumi-converter-terraform#65",
"templatefile": "pulumi/pulumi-converter-terraform#192",
"toset": "pulumi/pulumi-converter-terraform#137",
Expand Down

0 comments on commit 23ec910

Please sign in to comment.