From a0c90b746f6ad35e52c1ed32db06e1f3eb92d6f9 Mon Sep 17 00:00:00 2001 From: Fraser Waters Date: Mon, 12 Dec 2022 12:33:03 +0000 Subject: [PATCH] Add a test for for_each (#681) --- .../convert/testdata/for_each/main.tf | 45 +++++++++++++++++++ .../convert/testdata/for_each/pcl/main.pp | 44 ++++++++++++++++++ 2 files changed, 89 insertions(+) create mode 100644 pkg/tf2pulumi/convert/testdata/for_each/main.tf create mode 100644 pkg/tf2pulumi/convert/testdata/for_each/pcl/main.pp diff --git a/pkg/tf2pulumi/convert/testdata/for_each/main.tf b/pkg/tf2pulumi/convert/testdata/for_each/main.tf new file mode 100644 index 000000000..da2130674 --- /dev/null +++ b/pkg/tf2pulumi/convert/testdata/for_each/main.tf @@ -0,0 +1,45 @@ +resource "simple_resource" "a_resource_with_foreach_map" { + for_each = { + cruel: "world" + good: "class" + } + input_one = "Hello ${each.key} ${each.value}" + input_two = 0 +} + +output "some_output_a" { + value = simple_resource.a_resource_with_foreach_map["cruel"].result +} + +data "simple_data_source" "a_data_source_with_foreach_map" { + for_each = { + cruel: "world" + good: "class" + } + input_one = "Hello ${each.key} ${each.value}" + input_two = true +} + +output "some_output_b" { + value = data.simple_data_source.a_data_source_with_foreach_map["cruel"].result +} + +resource "simple_resource" "a_resource_with_foreach_array" { + for_each = ["cruel", "good"] + input_one = "Hello ${each.value} world" + input_two = true +} + +output "some_output_c" { + value = simple_resource.a_resource_with_foreach_array["good"].result +} + +data "simple_data_source" "a_data_source_with_foreach_array" { + for_each = ["cruel", "good"] + input_one = "Hello ${each.value} world" + input_two = true +} + +output "some_output_d" { + value = data.simple_data_source.a_data_source_with_foreach_array["good"].result +} \ No newline at end of file diff --git a/pkg/tf2pulumi/convert/testdata/for_each/pcl/main.pp b/pkg/tf2pulumi/convert/testdata/for_each/pcl/main.pp new file mode 100644 index 000000000..dea6982f3 --- /dev/null +++ b/pkg/tf2pulumi/convert/testdata/for_each/pcl/main.pp @@ -0,0 +1,44 @@ +resource aResourceWithForeachMap "simple:index:resource" { +options { + range = { + cruel: "world" + good: "class" + } + +} + inputOne = "Hello ${range.key} ${range.value}" + inputTwo = 0 +} +output someOutputA { + value = aResourceWithForeachMap["cruel"].result +} +aDataSourceWithForeachMap =[for __key, __value in { + cruel: "world" + good: "class" + } +: invoke("simple:index:data_source", { + inputOne = "Hello ${__key} ${__value}", + inputTwo = true +})] +output someOutputB { + value = aDataSourceWithForeachMap["cruel"].result +} +resource aResourceWithForeachArray "simple:index:resource" { +options { + range = ["cruel", "good"] + +} + inputOne = "Hello ${range.value} world" + inputTwo = true +} +output someOutputC { + value = aResourceWithForeachArray["good"].result +} +aDataSourceWithForeachArray =[for __key, __value in ["cruel", "good"] +: invoke("simple:index:data_source", { + inputOne = "Hello ${__value} world", + inputTwo = true +})] +output someOutputD { + value = aDataSourceWithForeachArray["good"].result +} \ No newline at end of file