Skip to content

Commit

Permalink
Edit workspace controller
Browse files Browse the repository at this point in the history
  • Loading branch information
sheneska committed Feb 20, 2025
1 parent a26e3fd commit 03d72b3
Showing 1 changed file with 17 additions and 7 deletions.
24 changes: 17 additions & 7 deletions internal/controller/workspace_controller.go
Original file line number Diff line number Diff line change
Expand Up @@ -215,6 +215,11 @@ func applyMethodToBool(applyMethod string) bool {
return applyMethod == "auto"
}

// autoApplyRunTriggerToBool turns spec.autoapplyRunTrigger field into bool
func autoApplyRunTriggerToBool(autoApplyRunTrigger bool) bool {
return autoApplyRunTrigger
}

func (r *WorkspaceReconciler) addFinalizer(ctx context.Context, instance *appv1alpha2.Workspace) error {
patch := client.MergeFrom(instance.DeepCopy())
controllerutil.AddFinalizer(instance, workspaceFinalizer)
Expand Down Expand Up @@ -249,13 +254,14 @@ func (r *WorkspaceReconciler) updateStatus(ctx context.Context, w *workspaceInst
func (r *WorkspaceReconciler) createWorkspace(ctx context.Context, w *workspaceInstance) (*tfc.Workspace, error) {
spec := w.instance.Spec
options := tfc.WorkspaceCreateOptions{
Name: tfc.String(spec.Name),
AllowDestroyPlan: tfc.Bool(spec.AllowDestroyPlan),
AutoApply: tfc.Bool(applyMethodToBool(spec.ApplyMethod)),
Description: tfc.String(spec.Description),
ExecutionMode: tfc.String(spec.ExecutionMode),
TerraformVersion: tfc.String(spec.TerraformVersion),
WorkingDirectory: tfc.String(spec.WorkingDirectory),
Name: tfc.String(spec.Name),
AllowDestroyPlan: tfc.Bool(spec.AllowDestroyPlan),
AutoApply: tfc.Bool(applyMethodToBool(spec.ApplyMethod)),
AutoApplyRunTrigger: tfc.Bool(autoApplyRunTriggerToBool(spec.AutoApplyRunTrigger)),
Description: tfc.String(spec.Description),
ExecutionMode: tfc.String(spec.ExecutionMode),
TerraformVersion: tfc.String(spec.TerraformVersion),
WorkingDirectory: tfc.String(spec.WorkingDirectory),
}

if spec.ExecutionMode == "agent" {
Expand Down Expand Up @@ -349,6 +355,10 @@ func (r *WorkspaceReconciler) updateWorkspace(ctx context.Context, w *workspaceI
updateOptions.AutoApply = tfc.Bool(applyMethodToBool(spec.ApplyMethod))
}

if workspace.AutoApplyRunTrigger != autoApplyRunTriggerToBool(spec.AutoApplyRunTrigger) {
updateOptions.AutoApplyRunTrigger = tfc.Bool(autoApplyRunTriggerToBool(spec.AutoApplyRunTrigger))
}

if workspace.AllowDestroyPlan != spec.AllowDestroyPlan {
updateOptions.AllowDestroyPlan = tfc.Bool(spec.AllowDestroyPlan)
}
Expand Down

0 comments on commit 03d72b3

Please sign in to comment.