Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix: fail when trying to create an in_active environment #953

Merged
merged 2 commits into from
Sep 11, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading