From c38d817a7c5cc2812bae360603f7b5b78eed0033 Mon Sep 17 00:00:00 2001 From: Alon Noga Date: Thu, 30 May 2024 14:25:39 +0300 Subject: [PATCH] add soft delete to configuration variable --- env0/resource_configuration_variable.go | 10 +++++++ env0/resource_configuration_variable_test.go | 31 ++++++++++++++++++++ 2 files changed, 41 insertions(+) diff --git a/env0/resource_configuration_variable.go b/env0/resource_configuration_variable.go index 91fb5f08..8d9755fd 100644 --- a/env0/resource_configuration_variable.go +++ b/env0/resource_configuration_variable.go @@ -110,6 +110,11 @@ func resourceConfigurationVariable() *schema.Resource { Description: "the value of this variable must match provided regular expression (enforced only in env0 UI)", Optional: true, }, + "soft_delete": { + Type: schema.TypeBool, + Description: "soft delete the configuration variable, once removed from the configuration it won't be deleted from env0", + Optional: true, + }, }, } } @@ -237,6 +242,11 @@ func resourceConfigurationVariableUpdate(ctx context.Context, d *schema.Resource } func resourceConfigurationVariableDelete(ctx context.Context, d *schema.ResourceData, meta interface{}) diag.Diagnostics { + // don't delete the configuration variable if it's a soft delete + if softDelete, ok := d.GetOk("soft_delete"); ok && softDelete.(bool) { + return nil + } + apiClient := meta.(client.ApiClientInterface) id := d.Id() diff --git a/env0/resource_configuration_variable_test.go b/env0/resource_configuration_variable_test.go index 639b267a..d241d53e 100644 --- a/env0/resource_configuration_variable_test.go +++ b/env0/resource_configuration_variable_test.go @@ -773,4 +773,35 @@ resource "%s" "test" { mock.EXPECT().ConfigurationVariableDelete(configVar.Id).Times(1).Return(nil) }) }) + + t.Run("When soft delete is on, it should not actually delete", func(t *testing.T) { + createTestCase := resource.TestCase{ + Steps: []resource.TestStep{ + { + Config: resourceConfigCreate(resourceType, resourceName, map[string]interface{}{ + "name": configVar.Name, + "description": configVar.Description, + "value": configVar.Value, + "is_read_only": strconv.FormatBool(*configVar.IsReadOnly), + "is_required": strconv.FormatBool(*configVar.IsRequired), + "soft_delete": true, + }), + Check: resource.ComposeAggregateTestCheckFunc( + resource.TestCheckResourceAttr(accessor, "id", configVar.Id), + resource.TestCheckResourceAttr(accessor, "name", configVar.Name), + resource.TestCheckResourceAttr(accessor, "description", configVar.Description), + resource.TestCheckResourceAttr(accessor, "value", configVar.Value), + resource.TestCheckResourceAttr(accessor, "is_read_only", strconv.FormatBool(*configVar.IsReadOnly)), + resource.TestCheckResourceAttr(accessor, "is_required", strconv.FormatBool(*configVar.IsRequired)), + ), + }, + }, + } + + runUnitTest(t, createTestCase, func(mock *client.MockApiClientInterface) { + mock.EXPECT().ConfigurationVariableCreate(configurationVariableCreateParams).Times(1).Return(configVar, nil) + mock.EXPECT().ConfigurationVariablesById(configVar.Id).Times(1).Return(configVar, nil) + mock.EXPECT().ConfigurationVariableDelete(configVar.Id).Times(0) + }) + }) }