Skip to content

Commit

Permalink
add soft delete to configuration variable
Browse files Browse the repository at this point in the history
  • Loading branch information
Alon Noga authored and Alon Noga committed May 30, 2024
1 parent 4a3c011 commit c38d817
Show file tree
Hide file tree
Showing 2 changed files with 41 additions and 0 deletions.
10 changes: 10 additions & 0 deletions env0/resource_configuration_variable.go
Original file line number Diff line number Diff line change
Expand Up @@ -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,
},
},
}
}
Expand Down Expand Up @@ -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()
Expand Down
31 changes: 31 additions & 0 deletions env0/resource_configuration_variable_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
})
})
}

0 comments on commit c38d817

Please sign in to comment.