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

Feat: is_remote_apply_enabled not being sent to BE #945

Merged
merged 1 commit into from
Aug 28, 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
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
Loading