From d7e7cd65d9f5c3e6b8c488b18c40f8192fd65502 Mon Sep 17 00:00:00 2001 From: Tomer Heber Date: Wed, 28 Aug 2024 07:39:48 -0500 Subject: [PATCH] Feat: is_remote_apply_enabled not being sent to BE --- client/environment.go | 3 +- env0/resource_environment.go | 2 +- env0/resource_environment_test.go | 65 ++++++++++++++++++++++++++++++- env0/utils.go | 1 - 4 files changed, 67 insertions(+), 4 deletions(-) diff --git a/client/environment.go b/client/environment.go index 24e18a47..77d0addd 100644 --- a/client/environment.go +++ b/client/environment.go @@ -29,7 +29,7 @@ func (c *ConfigurationVariableType) WriteResourceData(fieldName string, d *schem case 0: valStr = "environment" case 1: - valStr = "terraform" + valStr = TERRAFORM default: return fmt.Errorf("unknown configuration variable type %d", val) } @@ -150,6 +150,7 @@ type EnvironmentCreate struct { PreventAutoDeploy *bool `json:"preventAutoDeploy,omitempty" tfschema:"-"` K8sNamespace string `json:"k8sNamespace,omitempty"` ConfigurationSetChanges *ConfigurationSetChanges `json:"configurationSetChanges,omitempty" tfschema:"-"` + IsRemoteApplyEnabled bool `json:"isRemoteApplyEnabled"` } // When converted to JSON needs to be flattened. See custom MarshalJSON below. diff --git a/env0/resource_environment.go b/env0/resource_environment.go index 3eadea5a..458a2f42 100644 --- a/env0/resource_environment.go +++ b/env0/resource_environment.go @@ -342,7 +342,7 @@ func resourceEnvironment() *schema.Resource { }, "is_remote_apply_enabled": { Type: schema.TypeBool, - Description: "enables remote apply when set to true (defaults to false). Can only be enabled when is_remote_backend and approve_plan_automatically are enabled. Can only enabled for an existing environment", + Description: "enables remote apply when set to true (defaults to false). Can only be enabled when is_remote_backend and approve_plan_automatically are enabled", Optional: true, Default: false, }, diff --git a/env0/resource_environment_test.go b/env0/resource_environment_test.go index 6cdc277c..2d7650f5 100644 --- a/env0/resource_environment_test.go +++ b/env0/resource_environment_test.go @@ -624,7 +624,70 @@ func TestUnitEnvironmentResource(t *testing.T) { }) }) - t.Run("remote apply is enabled", func(t *testing.T) { + t.Run("remote apply is enabled on create", func(t *testing.T) { + templateId := "template-id" + + environment := client.Environment{ + Id: uuid.New().String(), + Name: "name", + ProjectId: "project-id", + LatestDeploymentLog: client.DeploymentLog{ + BlueprintId: templateId, + }, + IsRemoteBackend: boolPtr(true), + RequiresApproval: boolPtr(false), + IsRemoteApplyEnabled: true, + } + + testCase := resource.TestCase{ + Steps: []resource.TestStep{ + { + Config: resourceConfigCreate(resourceType, resourceName, map[string]interface{}{ + "name": environment.Name, + "project_id": environment.ProjectId, + "template_id": templateId, + "is_remote_backend": *environment.IsRemoteBackend, + "approve_plan_automatically": !*environment.RequiresApproval, + "force_destroy": true, + "is_remote_apply_enabled": true, + }), + Check: resource.ComposeAggregateTestCheckFunc( + resource.TestCheckResourceAttr(accessor, "id", environment.Id), + resource.TestCheckResourceAttr(accessor, "name", environment.Name), + resource.TestCheckResourceAttr(accessor, "project_id", environment.ProjectId), + resource.TestCheckResourceAttr(accessor, "template_id", templateId), + resource.TestCheckResourceAttr(accessor, "is_remote_backend", "true"), + resource.TestCheckResourceAttr(accessor, "approve_plan_automatically", "true"), + resource.TestCheckResourceAttr(accessor, "is_remote_apply_enabled", "true"), + ), + }, + }, + } + + runUnitTest(t, testCase, func(mock *client.MockApiClientInterface) { + gomock.InOrder( + mock.EXPECT().Template(environment.LatestDeploymentLog.BlueprintId).Times(1).Return(template, nil), + mock.EXPECT().EnvironmentCreate(client.EnvironmentCreate{ + Name: environment.Name, + ProjectId: environment.ProjectId, + + DeployRequest: &client.DeployRequest{ + BlueprintId: templateId, + UserRequiresApproval: boolPtr(false), + }, + IsRemoteBackend: environment.IsRemoteBackend, + RequiresApproval: environment.RequiresApproval, + IsRemoteApplyEnabled: environment.IsRemoteApplyEnabled, + }).Times(1).Return(environment, nil), + mock.EXPECT().Environment(environment.Id).Times(1).Return(environment, nil), + mock.EXPECT().ConfigurationVariablesByScope(client.ScopeEnvironment, environment.Id).Times(1).Return(client.ConfigurationChanges{}, nil), + mock.EXPECT().ConfigurationSetsAssignments("ENVIRONMENT", environment.Id).Times(1).Return(nil, nil), + mock.EXPECT().EnvironmentDestroy(environment.Id).Times(1), + ) + }) + }) + + t.Run("remote apply is enabled on update", func(t *testing.T) { templateId := "template-id" environment := client.Environment{ diff --git a/env0/utils.go b/env0/utils.go index 52ef70bb..dcde55c4 100644 --- a/env0/utils.go +++ b/env0/utils.go @@ -253,7 +253,6 @@ func getFieldName(field reflect.StructField) *parsedField { res.omitEmpty = true } } - } return &res