Skip to content

Commit

Permalink
Merge branch 'main' into feat-parent-path-#948
Browse files Browse the repository at this point in the history
  • Loading branch information
TomerHeber authored Sep 11, 2024
2 parents 40dcdef + bfb99c1 commit 0415038
Show file tree
Hide file tree
Showing 3 changed files with 25 additions and 2 deletions.
2 changes: 1 addition & 1 deletion docs/resources/environment.md
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,7 @@ If true must specify one of the following - 'github_installation_id' if using Gi
- `drift_detection_cron` (String) cron expression for scheduled drift detection of the environment (cannot be used with resource_drift_detection resource)
- `force_destroy` (Boolean) Destroy safeguard. Must be enabled before delete/destroy
- `id` (String) the environment's id
- `is_inactive` (Boolean) If 'true', it marks the environment as inactive. It can be re-activated by setting it to 'false' or removing this field.
- `is_inactive` (Boolean) 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
- `is_remote_apply_enabled` (Boolean) enables remote apply when set to true (defaults to false). Can only be enabled when is_remote_backend and approve_plan_automatically are enabled
- `is_remote_backend` (Boolean) should use remote backend
- `k8s_namespace` (String) kubernetes (or helm) namespace to be used. If modified deletes current environment and creates a new one
Expand Down
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 0415038

Please sign in to comment.