Skip to content

Commit

Permalink
Add test for various expressions (#683)
Browse files Browse the repository at this point in the history
  • Loading branch information
Frassle committed Dec 12, 2022
1 parent a0c90b7 commit 4bcd47b
Show file tree
Hide file tree
Showing 2 changed files with 126 additions and 0 deletions.
70 changes: 70 additions & 0 deletions pkg/tf2pulumi/convert/testdata/expressions/main.tf
@@ -0,0 +1,70 @@
output "null_out" {
value = null
}

output "number_out" {
value = 0
}

output "bool_out" {
value = true
}

output "string_out" {
value = "hello world"
}

output "tuple_out" {
value = [1, 2, 3]
}

output "str_object_out" {
value = {
hello: "hallo"
goodbye: "ha det"
}
}

locals {
a_key = "hello"
a_value = -1
}

output "complex_object_out" {
value = {
a_tuple: ["a", "b", "c"]
an_object: {
literal_key: 1
another_literal_key = 2
"yet_another_literal_key": local.a_value
# This doesn't translate correctly
# (local.a_key) = 4
}
ambiguous_for: {
"for" = 1
}
}
}

output "quoted_template" {
value = "The key is ${local.a_key}"
}

output "heredoc" {
value = <<END
This is also a template.
So we can output the key again ${local.a_key}
END
}

output "for_tuple" {
value = [for key, value in ["a", "b"] : "${key}:${value}:${local.a_value}" if key != 0]
}

output "for_tuple_value_only" {
value = [for value in ["a", "b"] : "${value}:${local.a_value}"]
}

output "for_object" {
value = {for key, value in ["a", "b"] : key => "${value}:${local.a_value}" if key != 0}
}
56 changes: 56 additions & 0 deletions pkg/tf2pulumi/convert/testdata/expressions/pcl/main.pp
@@ -0,0 +1,56 @@
output nullOut {
value = null
}
output numberOut {
value = 0
}
output boolOut {
value = true
}
output stringOut {
value = "hello world"
}
output tupleOut {
value = [1, 2, 3]
}
output strObjectOut {
value = {
hello: "hallo"
goodbye: "ha det"
}
}
aKey = "hello"
aValue = -1
output complexObjectOut {
value = {
a_tuple: ["a", "b", "c"]
an_object: {
literal_key: 1
another_literal_key = 2
"yet_another_literal_key": aValue
# This doesn't translate correctly
# (local.a_key) = 4
}
ambiguous_for: {
"for" = 1
}
}
}
output quotedTemplate {
value = "The key is ${aKey}"
}
output heredoc {
value = <<END
This is also a template.
So we can output the key again ${aKey}
END
}
output forTuple {
value = [for key, value in ["a", "b"] : "${key}:${value}:${aValue}" if key != 0]
}
output forTupleValueOnly {
value = [for value in ["a", "b"] : "${value}:${aValue}"]
}
output forObject {
value = {for key, value in ["a", "b"] : key => "${value}:${aValue}" if key != 0}
}

0 comments on commit 4bcd47b

Please sign in to comment.