From d5fc539aae6319c43adda5afaf33e429333d51bb Mon Sep 17 00:00:00 2001 From: Denis Gukov Date: Mon, 2 Dec 2024 00:04:23 +0500 Subject: [PATCH] feat: add destroy flag and rename env to var groups --- db/Task.go | 1 + db/Template.go | 5 + services/tasks/LocalJob.go | 20 +- web/src/components/EnvironmentForm.vue | 466 +++++++++++++------------ web/src/components/TemplateForm.vue | 6 +- web/src/lang/en.js | 12 +- 6 files changed, 274 insertions(+), 236 deletions(-) diff --git a/db/Task.go b/db/Task.go index dbf186aa..6cc2b8d0 100644 --- a/db/Task.go +++ b/db/Task.go @@ -15,6 +15,7 @@ type DefaultTaskParams struct { type TerraformTaskParams struct { Plan bool `json:"plan"` + Destroy bool `json:"destroy"` AutoApprove bool `json:"auto_approve"` } diff --git a/db/Template.go b/db/Template.go index d04f8e6c..7fb90963 100644 --- a/db/Template.go +++ b/db/Template.go @@ -36,6 +36,11 @@ const ( SurveyVarEnum TemplateType = "enum" ) +type TerraformTemplateParams struct { + AllowDestroy bool `json:"allow_destroy"` + AllowAutoApprove bool `json:"allow_auto_approve"` +} + type SurveyVarEnumValue struct { Name string `json:"name" backup:"name"` Value string `json:"value" backup:"value"` diff --git a/services/tasks/LocalJob.go b/services/tasks/LocalJob.go index 61cd13b2..c0d46e62 100644 --- a/services/tasks/LocalJob.go +++ b/services/tasks/LocalJob.go @@ -238,11 +238,25 @@ func (t *LocalJob) getTerraformArgs(username string, incomingVersion *string) (a return } + var params db.TerraformTaskParams + err = t.Task.GetParams(¶ms) + if err != nil { + return + } + + if params.Destroy { + args = append(args, "-destroy") + } + for name, value := range extraVars { - if name == "semaphore_vars" { - continue + + var v []byte + v, err = json.Marshal(value) + if err != nil { + return } - args = append(args, "-var", fmt.Sprintf("%s=%s", name, value)) + + args = append(args, "-var", fmt.Sprintf("%s=%s", name, v)) } for _, secret := range t.Environment.Secrets { diff --git a/web/src/components/EnvironmentForm.vue b/web/src/components/EnvironmentForm.vue index 6dfd967f..0b7b3327 100644 --- a/web/src/components/EnvironmentForm.vue +++ b/web/src/components/EnvironmentForm.vue @@ -20,243 +20,255 @@ class="mb-4" > - - mdi-variable {{ $t('extraVariables') }} + + Variables + Secrets + - - - + + + + {{ $t('extraVariables') }} + + + + Variables passed via --extra-vars (Ansible) or -var (Terraform/OpenTofu). - + - + - - - Table - - - JSON - - - + + + Table + + + JSON + + + - + -
- - - -
- {{ $t('New Extra Variable') }} -
- Can't be displayed as table. -
- -
- - mdi-application-settings - {{ $t('environmentVariables') }} - - - - -
- {{ $t('New Environment Variable') }} -
-
- -
- - mdi-lock{{ $t('Secrets') }} - - - - - - -
- - - - - - mdi-variable - - {{ $t('Secret Extra Variable') }} - - - - mdi-application-settings - - {{ $t('Secret Environment Variable') }} - - - -
+ @click="addExtraVar()" + >{{ $t('New Extra Variable') }} +
+ Can't be displayed as table. + - +
+ + mdi-application-settings + {{ $t('environmentVariables') }} + + + + +
+ {{ $t('New Environment Variable') }} +
+
+ + + +
+ + {{ $t('Secrets') }} + + + + + + +
+ + + + + + mdi-variable + + {{ $t('Secret Extra Variable') }} + + + + mdi-application-settings + + {{ $t('Secret Environment Variable') }} + + + +
+ +
+ +
+ @@ -342,6 +354,8 @@ export default { env: [], secrets: [], + tab: 'variables', + cmOptions: { tabSize: 2, mode: 'application/json', diff --git a/web/src/components/TemplateForm.vue b/web/src/components/TemplateForm.vue index 0ac3e0f0..906a8323 100644 --- a/web/src/components/TemplateForm.vue +++ b/web/src/components/TemplateForm.vue @@ -74,7 +74,11 @@ - +