feat(terraform): auto approve and plan flags

This commit is contained in:
Denis Gukov 2024-11-24 22:06:05 +05:00
parent 29c7f53d02
commit 289cd6d937
2 changed files with 20 additions and 4 deletions

View File

@ -1,6 +1,7 @@
package db package db
import ( import (
"encoding/json"
"fmt" "fmt"
"github.com/go-gorp/gorp/v3" "github.com/go-gorp/gorp/v3"
"time" "time"
@ -9,7 +10,7 @@ import (
"github.com/semaphoreui/semaphore/util" "github.com/semaphoreui/semaphore/util"
) )
type ShellTaskParams struct { type DefaultTaskParams struct {
} }
type TerraformTaskParams struct { type TerraformTaskParams struct {
@ -70,7 +71,11 @@ type Task struct {
} }
func (task *Task) GetParams(target interface{}) error { func (task *Task) GetParams(target interface{}) error {
return nil content, err := json.Marshal(task.TaskParams)
if err != nil {
return err
}
return json.Unmarshal(content, target)
} }
func (task *Task) PreInsert(gorp.SqlExecutor) error { func (task *Task) PreInsert(gorp.SqlExecutor) error {
@ -124,7 +129,18 @@ func (task *Task) GetUrl() *string {
} }
func (task *Task) ValidateNewTask(template Template) error { func (task *Task) ValidateNewTask(template Template) error {
return nil
var params interface{}
switch template.App {
case AppAnsible:
params = &AnsibleTaskParams{}
case AppTerraform, AppTofu:
params = &TerraformTaskParams{}
default:
params = &DefaultTaskParams{}
}
return task.GetParams(params)
} }
func (task *TaskWithTpl) Fill(d Store) error { func (task *TaskWithTpl) Fill(d Store) error {

View File

@ -437,7 +437,7 @@ func (t *LocalJob) Run(username string, incomingVersion *string) (err error) {
params = db.TerraformTaskParams{} params = db.TerraformTaskParams{}
default: default:
args, err = t.getShellArgs(username, incomingVersion) args, err = t.getShellArgs(username, incomingVersion)
params = db.ShellTaskParams{} params = db.DefaultTaskParams{}
} }
if err != nil { if err != nil {