Skip to content

Commit

Permalink
Feat: is_remote_apply_enabled not being sent to BE (#945)
Browse files Browse the repository at this point in the history
  • Loading branch information
TomerHeber authored Aug 28, 2024
1 parent e97a257 commit f64b40d
Show file tree
Hide file tree
Showing 4 changed files with 67 additions and 4 deletions.
3 changes: 2 additions & 1 deletion client/environment.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
}
Expand Down Expand Up @@ -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.
Expand Down
2 changes: 1 addition & 1 deletion env0/resource_environment.go
Original file line number Diff line number Diff line change
Expand Up @@ -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,
},
Expand Down
65 changes: 64 additions & 1 deletion env0/resource_environment_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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{
Expand Down
1 change: 0 additions & 1 deletion env0/utils.go
Original file line number Diff line number Diff line change
Expand Up @@ -253,7 +253,6 @@ func getFieldName(field reflect.StructField) *parsedField {
res.omitEmpty = true
}
}

}

return &res
Expand Down

0 comments on commit f64b40d

Please sign in to comment.