From fd5212714b2a3eccf5f78a4de6b1107e323b57d0 Mon Sep 17 00:00:00 2001 From: Tomer Heber Date: Fri, 6 Sep 2024 12:03:18 -0500 Subject: [PATCH 1/2] Fix: fail when trying to create an in_active environment --- env0/resource_environment.go | 6 +++++- env0/resource_environment_test.go | 20 ++++++++++++++++++++ 2 files changed, 25 insertions(+), 1 deletion(-) diff --git a/env0/resource_environment.go b/env0/resource_environment.go index 458a2f42..1a98aef1 100644 --- a/env0/resource_environment.go +++ b/env0/resource_environment.go @@ -272,7 +272,7 @@ func resourceEnvironment() *schema.Resource { }, "is_inactive": { Type: schema.TypeBool, - Description: "If 'true', it marks the environment as inactive. It can be re-activated by setting it to 'false' or removing this field.", + Description: "If 'true', it marks the environment as inactive. It can be re-activated by setting it to 'false' or removing this field. Note: it's not allowed to create an inactive environment", Default: false, Optional: true, }, @@ -600,6 +600,10 @@ func validateTemplateProjectAssignment(d *schema.ResourceData, apiClient client. func resourceEnvironmentCreate(ctx context.Context, d *schema.ResourceData, meta interface{}) diag.Diagnostics { apiClient := meta.(client.ApiClientInterface) + if d.Get("is_inactive").(bool) { + return diag.Errorf("cannot create an inactive environment (remove 'is_inactive' or set it to 'false')") + } + environmentPayload, createEnvPayloadErr := getCreatePayload(d, apiClient) if createEnvPayloadErr != nil { return createEnvPayloadErr diff --git a/env0/resource_environment_test.go b/env0/resource_environment_test.go index 2d7650f5..ef32feac 100644 --- a/env0/resource_environment_test.go +++ b/env0/resource_environment_test.go @@ -2201,6 +2201,26 @@ func TestUnitEnvironmentResource(t *testing.T) { }) + t.Run("fail when trying to create an inactive environment", func(t *testing.T) { + testCase := resource.TestCase{ + Steps: []resource.TestStep{ + { + Config: resourceConfigCreate(resourceType, resourceName, map[string]interface{}{ + "name": updatedEnvironment.Name, + "project_id": updatedEnvironment.ProjectId, + "template_id": updatedEnvironment.LatestDeploymentLog.BlueprintId, + "is_inactive": true, + "force_destroy": true, + }), + ExpectError: regexp.MustCompile("cannot create an inactive environment"), + }, + }, + } + + runUnitTest(t, testCase, func(mock *client.MockApiClientInterface) {}) + + }) + t.Run("Failure in create", func(t *testing.T) { testCase := resource.TestCase{ Steps: []resource.TestStep{ From 85cab91f804a43153d47532c4947c832c1b9c7b6 Mon Sep 17 00:00:00 2001 From: Tomer Heber Date: Fri, 6 Sep 2024 12:09:43 -0500 Subject: [PATCH 2/2] remove newline --- env0/resource_environment_test.go | 1 - 1 file changed, 1 deletion(-) diff --git a/env0/resource_environment_test.go b/env0/resource_environment_test.go index ef32feac..789c7fbd 100644 --- a/env0/resource_environment_test.go +++ b/env0/resource_environment_test.go @@ -2218,7 +2218,6 @@ func TestUnitEnvironmentResource(t *testing.T) { } runUnitTest(t, testCase, func(mock *client.MockApiClientInterface) {}) - }) t.Run("Failure in create", func(t *testing.T) {