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

Automatically test ALL the Terraform builtins #680

Merged
merged 1 commit into from Dec 12, 2022
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.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
5 changes: 5 additions & 0 deletions Makefile
Expand Up @@ -21,3 +21,8 @@ test::
# be useful to run to review the differences with git diff.
test_accept::
PULUMI_ACCEPT=1 go test -v -count=1 -cover -timeout 2h -parallel ${TESTPARALLELISM} ./...

generate_builtins_test::
if [ ! -d ./scripts/venv ]; then python -m venv ./scripts/venv; fi
. ./scripts/venv/*/activate && python -m pip install -r ./scripts/requirements.txt
. ./scripts/venv/*/activate && python ./scripts/generate_builtins.py
101 changes: 98 additions & 3 deletions pkg/tf2pulumi/convert/testdata/builtins/main.tf
@@ -1,3 +1,98 @@
output "funcLength" {
value = length([1, 2])
}
# DO NOT EDIT BY HAND
# This file is auto generated by ./scripts/generate_builtins.py

locals {
# A load of the examples in the docs use `path.module` which _should_ resolve to the file system path of
# the current module, but tf2pulumi doesn't support that so we replace it with local.path_module.
path_module = "some/path"
}

# Examples for element
output "funcElement0" {
value = element(["a", "b", "c"], 1)
}

output "funcElement1" {
value = element(["a", "b", "c"], 3)
}

output "funcElement2" {
value = element(["a", "b", "c"], length(["a", "b", "c"])-1)
}


# Examples for file
output "funcFile" {
value = file("${local.path_module}/hello.txt")
}


# Examples for filebase64
output "funcFilebase64" {
value = filebase64("${local.path_module}/hello.txt")
}


# Examples for filebase64sha256
output "funcFilebase64sha256" {
value = filebase64sha256("hello.txt")
}


# Examples for jsonencode
output "funcJsonencode" {
value = jsonencode({"hello"="world"})
}


# Examples for length
output "funcLength0" {
value = length([])
}

output "funcLength1" {
value = length(["a", "b"])
}

output "funcLength2" {
value = length({"a" = "b"})
}

output "funcLength3" {
value = length("hello")
}

output "funcLength4" {
value = length("👾🕹️")
}


# Examples for lookup
output "funcLookup0" {
value = lookup({a="ay", b="bee"}, "a", "what?")
}

output "funcLookup1" {
value = lookup({a="ay", b="bee"}, "c", "what?")
}


# Examples for sha1
output "funcSha1" {
value = sha1("hello world")
}


# Examples for split
output "funcSplit0" {
value = split(",", "foo,bar,baz")
}

output "funcSplit1" {
value = split(",", "foo")
}

output "funcSplit2" {
value = split(",", "")
}

69 changes: 66 additions & 3 deletions pkg/tf2pulumi/convert/testdata/builtins/pcl/main.pp
@@ -1,3 +1,66 @@
output funcLength {
value = length([1, 2])
}
# A load of the examples in the docs use `path.module` which _should_ resolve to the file system path of
# the current module, but tf2pulumi doesn't support that so we replace it with local.path_module.
pathModule = "some/path"
# Examples for element
output funcElement0 {
value = element(["a", "b", "c"], 1)
}
output funcElement1 {
value = element(["a", "b", "c"], 3)
}
output funcElement2 {
value = element(["a", "b", "c"], length(["a", "b", "c"])-1)
}
# Examples for file
output funcFile {
value = readFile("${pathModule}/hello.txt")
}
# Examples for filebase64
output funcFilebase64 {
value = filebase64("${pathModule}/hello.txt")
}
# Examples for filebase64sha256
output funcFilebase64sha256 {
value = filebase64sha256("hello.txt")
}
# Examples for jsonencode
output funcJsonencode {
value = toJSON({"hello"="world"})
}
# Examples for length
output funcLength0 {
value = length([])
}
output funcLength1 {
value = length(["a", "b"])
}
output funcLength2 {
value = length({"a" = "b"})
}
output funcLength3 {
value = length("hello")
}
output funcLength4 {
value = length("👾🕹️")
}
# Examples for lookup
output funcLookup0 {
value = lookup({a="ay", b="bee"}, "a", "what?")
}
output funcLookup1 {
value = lookup({a="ay", b="bee"}, "c", "what?")
}
# Examples for sha1
output funcSha1 {
value = sha1("hello world")
}
# Examples for split
output funcSplit0 {
value = split(",", "foo,bar,baz")
}
output funcSplit1 {
value = split(",", "foo")
}
output funcSplit2 {
value = split(",", "")
}
1 change: 1 addition & 0 deletions scripts/.gitignore
@@ -0,0 +1 @@
venv