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 { type TerraformTaskParams struct {
Plan bool `json:"plan"` Plan bool `json:"plan"`
Destroy bool `json:"destroy"`
AutoApprove bool `json:"auto_approve"` AutoApprove bool `json:"auto_approve"`
} }

View File

@ -36,6 +36,11 @@ const (
SurveyVarEnum TemplateType = "enum" SurveyVarEnum TemplateType = "enum"
) )
type TerraformTemplateParams struct {
AllowDestroy bool `json:"allow_destroy"`
AllowAutoApprove bool `json:"allow_auto_approve"`
}
type SurveyVarEnumValue struct { type SurveyVarEnumValue struct {
Name string `json:"name" backup:"name"` Name string `json:"name" backup:"name"`
Value string `json:"value" backup:"value"` Value string `json:"value" backup:"value"`

View File

@ -238,11 +238,25 @@ func (t *LocalJob) getTerraformArgs(username string, incomingVersion *string) (a
return 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 { 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 { for _, secret := range t.Environment.Secrets {

View File

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

View File

@ -74,7 +74,11 @@
<v-row> <v-row>
<v-col cols="12" md="6" class="pb-0"> <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 <v-tabs
fixed-tabs fixed-tabs
v-model="itemTypeIndex" v-model="itemTypeIndex"

View File

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