feat: add destroy flag and rename env to var groups

This commit is contained in:
Denis Gukov 2024-12-02 00:04:23 +05:00
parent 9e6439b20f
commit d5fc539aae
6 changed files with 274 additions and 236 deletions

View File

@ -15,6 +15,7 @@ type DefaultTaskParams struct {
type TerraformTaskParams struct {
Plan bool `json:"plan"`
Destroy bool `json:"destroy"`
AutoApprove bool `json:"auto_approve"`
}

View File

@ -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"`

View File

@ -238,11 +238,25 @@ func (t *LocalJob) getTerraformArgs(username string, incomingVersion *string) (a
return
}
var params db.TerraformTaskParams
err = t.Task.GetParams(&params)
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 {

View File

@ -20,243 +20,255 @@
class="mb-4"
></v-text-field>
<v-subheader class="px-0">
<v-icon class="mr-1">mdi-variable</v-icon> {{ $t('extraVariables') }}
<v-tabs grow v-model="tab">
<v-tab key="variables">Variables</v-tab>
<v-tab key="secrets">Secrets</v-tab>
</v-tabs>
<v-tooltip bottom color="black" open-delay="300" max-width="400">
<template v-slot:activator="{ on, attrs }">
<v-icon
class="ml-1"
v-bind="attrs"
v-on="on"
>mdi-help-circle</v-icon>
</template>
<span>
<v-tabs-items v-model="tab">
<v-tab-item key="variables">
<v-subheader class="px-0">
{{ $t('extraVariables') }}
<v-tooltip bottom color="black" open-delay="300" max-width="400">
<template v-slot:activator="{ on, attrs }">
<v-icon
class="ml-1"
v-bind="attrs"
v-on="on"
>mdi-help-circle</v-icon>
</template>
<span>
Variables passed via <code>--extra-vars</code> (Ansible) or
<code>-var</code> (Terraform/OpenTofu).
</span>
</v-tooltip>
</v-tooltip>
<v-spacer />
<v-spacer />
<v-btn-toggle
v-model="extraVarsEditMode"
tile
group
>
<v-btn value="table" small class="mr-0" style="border-radius: 4px;">
Table
</v-btn>
<v-btn value="json" small class="mr-0" style="border-radius: 4px;">
JSON
</v-btn>
</v-btn-toggle>
</v-subheader>
<v-btn-toggle
v-model="extraVarsEditMode"
tile
group
>
<v-btn value="table" small class="mr-0" style="border-radius: 4px;">
Table
</v-btn>
<v-btn value="json" small class="mr-0" style="border-radius: 4px;">
JSON
</v-btn>
</v-btn-toggle>
</v-subheader>
<codemirror
v-if="extraVarsEditMode === 'json'"
:style="{ border: '1px solid lightgray' }"
v-model="json"
:options="cmOptions"
:placeholder="$t('enterExtraVariablesJson')"
/>
<codemirror
v-if="extraVarsEditMode === 'json'"
:style="{ border: '1px solid lightgray' }"
v-model="json"
:options="cmOptions"
:placeholder="$t('enterExtraVariablesJson')"
/>
<div v-else-if="extraVarsEditMode === 'table'">
<v-data-table
v-if="extraVars != null"
:items="extraVars"
:items-per-page="-1"
class="elevation-1"
hide-default-footer
:no-data-text="$t('noValues')"
style="background: #8585850f"
>
<template v-slot:item="props">
<tr>
<td class="pa-1">
<v-text-field
solo-inverted
flat
hide-details
v-model="props.item.name"
class="v-text-field--solo--no-min-height"
:placeholder="$t('name')"
></v-text-field>
</td>
<td class="pa-1">
<v-text-field
solo-inverted
flat
hide-details
v-model="props.item.value"
class="v-text-field--solo--no-min-height"
:placeholder="$t('Value')"
></v-text-field>
</td>
<td style="width: 38px;">
<v-icon
small
class="pa-1"
@click="removeExtraVar(props.item)"
>
mdi-delete
</v-icon>
</td>
</tr>
</template>
</v-data-table>
<div class="mt-2 mb-4" v-if="extraVars != null">
<v-btn
color="primary"
@click="addExtraVar()"
>{{ $t('New Extra Variable') }}</v-btn>
</div>
<v-alert color="error" v-else>Can't be displayed as table.</v-alert>
</div>
<div>
<v-subheader class="px-0 mt-4">
<v-icon class="mr-1">mdi-application-settings</v-icon>
{{ $t('environmentVariables') }}
</v-subheader>
<v-data-table
:items="env"
:items-per-page="-1"
class="elevation-1"
hide-default-footer
:no-data-text="$t('noValues')"
style="background: #8585850f"
>
<template v-slot:item="props">
<tr>
<td class="pa-1">
<v-text-field
solo-inverted
flat
hide-details
v-model="props.item.name"
class="v-text-field--solo--no-min-height"
:placeholder="$t('name')"
></v-text-field>
</td>
<td class="pa-1">
<v-text-field
solo-inverted
flat
hide-details
v-model="props.item.value"
class="v-text-field--solo--no-min-height"
:placeholder="$t('Value')"
></v-text-field>
</td>
<td style="width: 38px;">
<v-icon
small
class="pa-1"
@click="removeEnvVar(props.item)"
>
mdi-delete
</v-icon>
</td>
</tr>
</template>
</v-data-table>
<div class="mt-2 mb-4">
<v-btn
color="primary"
@click="addEnvVar()"
>{{ $t('New Environment Variable') }}</v-btn>
</div>
</div>
<div>
<v-subheader class="px-0 mt-4">
<v-icon class="mr-1">mdi-lock</v-icon>{{ $t('Secrets') }}
</v-subheader>
<v-data-table
:items="secrets.filter(s => !s.remove)"
:items-per-page="-1"
class="elevation-1"
hide-default-footer
:no-data-text="$t('noValues')"
style="background: #8585850f"
>
<template v-slot:item="props">
<tr>
<td class="pa-1">
<v-icon>
{{ props.item.type === 'var' ? 'mdi-variable' : 'mdi-application-settings' }}
</v-icon>
</td>
<td class="pa-1">
<v-text-field
solo-inverted
flat
hide-details
v-model="props.item.name"
class="v-text-field--solo--no-min-height"
:placeholder="$t('name')"
></v-text-field>
</td>
<td class="pa-1">
<v-text-field
solo-inverted
flat
hide-details
v-model="props.item.value"
placeholder="*******"
class="v-text-field--solo--no-min-height"
></v-text-field>
</td>
<td style="width: 38px;">
<v-icon
small
class="pa-1"
@click="removeSecret(props.item)"
>
mdi-delete
</v-icon>
</td>
</tr>
</template>
</v-data-table>
<div class="mt-2 mb-4">
<v-menu
offset-y
>
<template v-slot:activator="{ on, attrs }">
<div v-else-if="extraVarsEditMode === 'table'">
<v-data-table
v-if="extraVars != null"
:items="extraVars"
:items-per-page="-1"
class="elevation-1"
hide-default-footer
:no-data-text="$t('noValues')"
style="background: #8585850f"
>
<template v-slot:item="props">
<tr>
<td class="pa-1">
<v-text-field
solo-inverted
flat
hide-details
v-model="props.item.name"
class="v-text-field--solo--no-min-height"
:placeholder="$t('name')"
></v-text-field>
</td>
<td class="pa-1">
<v-text-field
solo-inverted
flat
hide-details
v-model="props.item.value"
class="v-text-field--solo--no-min-height"
:placeholder="$t('Value')"
></v-text-field>
</td>
<td style="width: 38px;">
<v-icon
small
class="pa-1"
@click="removeExtraVar(props.item)"
>
mdi-delete
</v-icon>
</td>
</tr>
</template>
</v-data-table>
<div class="mt-2 mb-4" v-if="extraVars != null">
<v-btn
v-bind="attrs"
v-on="on"
color="primary"
>New Secret</v-btn>
</template>
<v-list>
<v-list-item
link
@click="addSecret('var')"
>
<v-list-item-icon>
<v-icon>mdi-variable</v-icon>
</v-list-item-icon>
<v-list-item-title>{{ $t('Secret Extra Variable') }}</v-list-item-title>
</v-list-item>
<v-list-item
link
@click="addSecret('env')"
>
<v-list-item-icon>
<v-icon>mdi-application-settings</v-icon>
</v-list-item-icon>
<v-list-item-title>{{ $t('Secret Environment Variable') }}</v-list-item-title>
</v-list-item>
</v-list>
</v-menu>
</div>
@click="addExtraVar()"
>{{ $t('New Extra Variable') }}</v-btn>
</div>
<v-alert color="error" v-else>Can't be displayed as table.</v-alert>
</div>
</div>
<div>
<v-subheader class="px-0 mt-4">
<v-icon class="mr-1">mdi-application-settings</v-icon>
{{ $t('environmentVariables') }}
</v-subheader>
<v-data-table
:items="env"
:items-per-page="-1"
class="elevation-1"
hide-default-footer
:no-data-text="$t('noValues')"
style="background: #8585850f"
>
<template v-slot:item="props">
<tr>
<td class="pa-1">
<v-text-field
solo-inverted
flat
hide-details
v-model="props.item.name"
class="v-text-field--solo--no-min-height"
:placeholder="$t('name')"
></v-text-field>
</td>
<td class="pa-1">
<v-text-field
solo-inverted
flat
hide-details
v-model="props.item.value"
class="v-text-field--solo--no-min-height"
:placeholder="$t('Value')"
></v-text-field>
</td>
<td style="width: 38px;">
<v-icon
small
class="pa-1"
@click="removeEnvVar(props.item)"
>
mdi-delete
</v-icon>
</td>
</tr>
</template>
</v-data-table>
<div class="mt-2 mb-4">
<v-btn
color="primary"
@click="addEnvVar()"
>{{ $t('New Environment Variable') }}</v-btn>
</div>
</div>
</v-tab-item>
<v-tab-item key="secrets">
<div>
<v-subheader class="px-0 mt-4">
{{ $t('Secrets') }}
</v-subheader>
<v-data-table
:items="secrets.filter(s => !s.remove)"
:items-per-page="-1"
class="elevation-1"
hide-default-footer
:no-data-text="$t('noValues')"
style="background: #8585850f"
>
<template v-slot:item="props">
<tr>
<td class="pa-1">
<v-icon>
{{ props.item.type === 'var' ? 'mdi-variable' : 'mdi-application-settings' }}
</v-icon>
</td>
<td class="pa-1">
<v-text-field
solo-inverted
flat
hide-details
v-model="props.item.name"
class="v-text-field--solo--no-min-height"
:placeholder="$t('name')"
></v-text-field>
</td>
<td class="pa-1">
<v-text-field
solo-inverted
flat
hide-details
v-model="props.item.value"
placeholder="*******"
class="v-text-field--solo--no-min-height"
></v-text-field>
</td>
<td style="width: 38px;">
<v-icon
small
class="pa-1"
@click="removeSecret(props.item)"
>
mdi-delete
</v-icon>
</td>
</tr>
</template>
</v-data-table>
<div class="mt-2 mb-4">
<v-menu
offset-y
>
<template v-slot:activator="{ on, attrs }">
<v-btn
v-bind="attrs"
v-on="on"
color="primary"
>New Secret</v-btn>
</template>
<v-list>
<v-list-item
link
@click="addSecret('var')"
>
<v-list-item-icon>
<v-icon>mdi-variable</v-icon>
</v-list-item-icon>
<v-list-item-title>{{ $t('Secret Extra Variable') }}</v-list-item-title>
</v-list-item>
<v-list-item
link
@click="addSecret('env')"
>
<v-list-item-icon>
<v-icon>mdi-application-settings</v-icon>
</v-list-item-icon>
<v-list-item-title>{{ $t('Secret Environment Variable') }}</v-list-item-title>
</v-list-item>
</v-list>
</v-menu>
</div>
</div>
</v-tab-item>
</v-tabs-items>
</v-form>
</template>
@ -342,6 +354,8 @@ export default {
env: [],
secrets: [],
tab: 'variables',
cmOptions: {
tabSize: 2,
mode: 'application/json',

View File

@ -74,7 +74,11 @@
<v-row>
<v-col cols="12" md="6" class="pb-0">
<v-card class="mb-6" :color="$vuetify.theme.dark ? '#212121' : 'white'">
<v-card
class="mb-6"
:color="$vuetify.theme.dark ? '#212121' : 'white'"
style="background: #8585850f"
>
<v-tabs
fixed-tabs
v-model="itemTypeIndex"

View File

@ -43,7 +43,7 @@ export default {
youHaveReadonlyAccess: 'You have read-only access',
taskTemplates: 'Task Templates',
inventory: 'Inventory',
environment: 'Environment Variables',
environment: 'Variable Groups',
keyStore: 'Key Store',
repositories: 'Repositories',
darkMode: 'Dark Mode',
@ -68,10 +68,10 @@ export default {
cancel: 'Cancel',
noViews: 'No views',
addView: 'Add view',
editEnvironment: 'Edit Environment',
deleteEnvironment: 'Delete environment',
newEnvironment: 'New Environment',
environmentName: 'Environment Name',
editEnvironment: 'Edit Variable Group',
deleteEnvironment: 'Delete variable group',
newEnvironment: 'New Group',
environmentName: 'Group Name',
extraVariables: 'Extra variables',
enterExtraVariablesJson: 'Enter extra variables JSON...',
environmentVariables: 'Environment variables',
@ -177,7 +177,7 @@ export default {
exampleSiteyml: 'Example: site.yml',
inventory2: 'Inventory *',
repository: 'Repository',
environment3: 'Environment *',
environment3: 'Variable Group *',
vaultPassword: 'Vault Password',
vaultPassword2: 'Vault Password',
view: 'View',