From 03272798e776e107021f5014640e3dadb4158196 Mon Sep 17 00:00:00 2001 From: Tomer Heber Date: Fri, 20 May 2022 08:14:40 -0500 Subject: [PATCH 1/2] Fix: data env0_templates includes deleted templates --- env0/data_templates.go | 4 +++- env0/data_templates_test.go | 9 ++++++++- tests/integration/022_templates/main.tf | 9 ++++----- 3 files changed, 15 insertions(+), 7 deletions(-) diff --git a/env0/data_templates.go b/env0/data_templates.go index add0d444..a6653d22 100644 --- a/env0/data_templates.go +++ b/env0/data_templates.go @@ -36,7 +36,9 @@ func dataTemplatesRead(ctx context.Context, d *schema.ResourceData, meta interfa data := []string{} for _, template := range templates { - data = append(data, template.Name) + if !template.IsDeleted { + data = append(data, template.Name) + } } d.Set("names", data) diff --git a/env0/data_templates_test.go b/env0/data_templates_test.go index f4061a68..243ad978 100644 --- a/env0/data_templates_test.go +++ b/env0/data_templates_test.go @@ -20,6 +20,12 @@ func TestTemplatesDataSource(t *testing.T) { Name: "name1", } + template3 := client.Template{ + Id: "id2", + Name: "name2", + IsDeleted: true, + } + resourceType := "env0_templates" resourceName := "test_templates" accessor := dataSourceAccessor(resourceType, resourceName) @@ -32,6 +38,7 @@ func TestTemplatesDataSource(t *testing.T) { Check: resource.ComposeAggregateTestCheckFunc( resource.TestCheckResourceAttr(accessor, "names.0", template1.Name), resource.TestCheckResourceAttr(accessor, "names.1", template2.Name), + resource.TestCheckNoResourceAttr(accessor, "names.2"), ), }, }, @@ -47,7 +54,7 @@ func TestTemplatesDataSource(t *testing.T) { t.Run("Success", func(t *testing.T) { runUnitTest(t, getTestCase(), - mockTemplates([]client.Template{template1, template2}), + mockTemplates([]client.Template{template1, template2, template3}), ) }) diff --git a/tests/integration/022_templates/main.tf b/tests/integration/022_templates/main.tf index 92621753..4af7afbd 100644 --- a/tests/integration/022_templates/main.tf +++ b/tests/integration/022_templates/main.tf @@ -38,8 +38,7 @@ resource "env0_template" "github_template2" { data "env0_templates" "all_templates" {} -# This is removed temporarily until https://github.com/env0/terraform-provider-env0/issues/350 is fixed -#data "env0_template" "templates" { -# for_each = toset(data.env0_templates.all_templates.names) -# name = each.value -#} +data "env0_template" "templates" { + for_each = toset(data.env0_templates.all_templates.names) + name = each.value +} From 0cd459a350900f4c38054424f06a04175feaee82 Mon Sep 17 00:00:00 2001 From: Tomer Heber Date: Tue, 24 May 2022 10:28:36 -0500 Subject: [PATCH 2/2] add random names to integration test 012 --- tests/integration/012_environment/main.tf | 18 +++++++++++++----- 1 file changed, 13 insertions(+), 5 deletions(-) diff --git a/tests/integration/012_environment/main.tf b/tests/integration/012_environment/main.tf index 266fa005..588f3b90 100644 --- a/tests/integration/012_environment/main.tf +++ b/tests/integration/012_environment/main.tf @@ -1,10 +1,18 @@ +provider "random" {} + +resource "random_string" "random" { + length = 8 + special = false + min_lower = 8 +} + resource "env0_project" "test_project" { - name = "Test-Project-for-environment" + name = "Test-Project-for-environment-${random_string.random.result}" force_destroy = true } resource "env0_template" "template" { - name = "Template for environment resource" + name = "Template for environment resource-${random_string.random.result}" type = "terraform" repository = "https://github.com/env0/templates" path = "misc/null-resource" @@ -13,7 +21,7 @@ resource "env0_template" "template" { resource "env0_environment" "example" { force_destroy = true - name = "environment" + name = "environment-${random_string.random.result}" project_id = env0_project.test_project.id template_id = env0_template.template.id wait_for = "FULLY_DEPLOYED" @@ -31,7 +39,7 @@ data "env0_configuration_variable" "env_config_variable" { } resource "env0_template" "terragrunt_template" { - name = "Terragrunt template for environment resource" + name = "Terragrunt template for environment resource-${random_string.random.result}" type = "terragrunt" repository = "https://github.com/env0/templates" path = "misc/null-resource" @@ -41,7 +49,7 @@ resource "env0_template" "terragrunt_template" { resource "env0_environment" "terragrunt_environment" { force_destroy = true - name = "environment" + name = "environment-${random_string.random.result}" project_id = env0_project.test_project.id template_id = env0_template.terragrunt_template.id approve_plan_automatically = true