From 06c25f85af000e3770ffe7ce1b03fb77ec24e490 Mon Sep 17 00:00:00 2001 From: Sagi Laufer Date: Wed, 25 Oct 2023 09:41:30 +0300 Subject: [PATCH 1/2] make the test rely solely on its own data --- tests/integration/025_notifications/main.tf | 13 +++++++++---- 1 file changed, 9 insertions(+), 4 deletions(-) diff --git a/tests/integration/025_notifications/main.tf b/tests/integration/025_notifications/main.tf index 5c8186b1..be0871ac 100644 --- a/tests/integration/025_notifications/main.tf +++ b/tests/integration/025_notifications/main.tf @@ -18,9 +18,14 @@ resource "env0_notification" "test_notification_2" { value = "https://someurl2.com" } -data "env0_notifications" "all_notifications" {} +data "env0_notifications" "all_notifications" { + depends_on = [env0_notification.test_notification_1, env0_notification.test_notification_2] +} + +data "env0_notification" "test_notification_1" { + name = data.env0_notifications.all_notifications.names[index(data.env0_notifications.all_notifications.names, env0_notification.test_notification_1.name)] +} -data "env0_notification" "notification" { - for_each = toset(data.env0_notifications.all_notifications.names) - name = each.value +data "env0_notification" "test_notification_2" { + name = data.env0_notifications.all_notifications.names[index(data.env0_notifications.all_notifications.names, env0_notification.test_notification_2.name)] } From 0c08f76aa77d2f10d0a9144aa5caf8222804f19b Mon Sep 17 00:00:00 2001 From: Sagi Laufer Date: Wed, 25 Oct 2023 10:59:58 +0300 Subject: [PATCH 2/2] make the notifications data use the resource name, output from all notifications for testing its functionality --- .../025_notifications/expected_outputs.json | 4 ++- tests/integration/025_notifications/main.tf | 25 ++++++++++++++++--- 2 files changed, 24 insertions(+), 5 deletions(-) diff --git a/tests/integration/025_notifications/expected_outputs.json b/tests/integration/025_notifications/expected_outputs.json index 0967ef42..eaaaa465 100644 --- a/tests/integration/025_notifications/expected_outputs.json +++ b/tests/integration/025_notifications/expected_outputs.json @@ -1 +1,3 @@ -{} +{ + "notification_1_from_all_notifications": "integration-test-025-notification-1-" +} diff --git a/tests/integration/025_notifications/main.tf b/tests/integration/025_notifications/main.tf index be0871ac..172cb852 100644 --- a/tests/integration/025_notifications/main.tf +++ b/tests/integration/025_notifications/main.tf @@ -6,14 +6,18 @@ resource "random_string" "random" { min_lower = 20 } +locals { + notification_name_prefix = "integration-test-025-notification" +} + resource "env0_notification" "test_notification_1" { - name = "notification123-${random_string.random.result}-1" + name = "${local.notification_name_prefix}-1-${random_string.random.result}" type = "Slack" value = "https://someurl1.com" } resource "env0_notification" "test_notification_2" { - name = "notification123-${random_string.random.result}-2" + name = "${local.notification_name_prefix}-2-${random_string.random.result}" type = "Teams" value = "https://someurl2.com" } @@ -23,9 +27,22 @@ data "env0_notifications" "all_notifications" { } data "env0_notification" "test_notification_1" { - name = data.env0_notifications.all_notifications.names[index(data.env0_notifications.all_notifications.names, env0_notification.test_notification_1.name)] + depends_on = [env0_notification.test_notification_1] + name = "${local.notification_name_prefix}-1-${random_string.random.result}" } data "env0_notification" "test_notification_2" { - name = data.env0_notifications.all_notifications.names[index(data.env0_notifications.all_notifications.names, env0_notification.test_notification_2.name)] + depends_on = [env0_notification.test_notification_2] + name = "${local.notification_name_prefix}-2-${random_string.random.result}" +} + +output "notification_1_from_all_notifications" { + value = replace( + data.env0_notifications.all_notifications.names[ + index(data.env0_notifications.all_notifications.names, + env0_notification.test_notification_1.name) + ] + , random_string.random.result + , "" + ) }