Skip to content

Commit

Permalink
Fix: fail when trying to create an in_active environment (#953)
Browse files Browse the repository at this point in the history
* Fix: fail when trying to create an in_active environment

* remove newline
  • Loading branch information
TomerHeber authored Sep 11, 2024
1 parent 969e5ff commit 18ec62e
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 1 deletion.
6 changes: 5 additions & 1 deletion env0/resource_environment.go
Original file line number Diff line number Diff line change
Expand Up @@ -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,
},
Expand Down Expand Up @@ -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
Expand Down
19 changes: 19 additions & 0 deletions env0/resource_environment_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -2201,6 +2201,25 @@ 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{
Expand Down

0 comments on commit 18ec62e

Please sign in to comment.