Skip to content
Snippets Groups Projects
Unverified Commit 24fb555f authored by Timo Furrer's avatar Timo Furrer
Browse files

Add job templates template

parent 709bdaca
No related branches found
No related tags found
No related merge requests found
......@@ -80,7 +80,7 @@ but no destructive actions.
### Job Templates
Instead of including the `full-pipeline` or another opinionated tempalte,
Instead of including the `full-pipeline` or another opinionated template,
it's also possible to include individual jobs
and compose your own pipeline, for example, to just run the `fmt` job you can do:
......@@ -96,6 +96,29 @@ include:
root_dir: tofu/
```
Or you can also include the `job-templates` template, that will include
all available OpenTofu jobs as hidden job templates prefixed with `.opentofu:`.
Those are especially useful when you want to minimize your includes and
you want to extend the jobs:
```yaml
include:
- component: gitlab.com/components/opentofu/job-templates@<VERSON>
inputs:
# The version must currently be specified explicitly as an input,
# to find the correctly associated images. # This can be removed
# once https://gitlab.com/gitlab-org/gitlab/-/issues/438275 is solved.
version: <VERSION>
opentofu_version: 1.6.1
plan:
extends: [.opentofu:plan]
parallel:
matrix:
- TF_ROOT: test/
- TF_ROOT: prod/
```
Have a look at the [`full-pipeline`](templates/full-pipeline.yml) for how it's constructed.
The following job components exist:
......
......@@ -82,7 +82,7 @@ but no destructive actions.
### Job Templates
Instead of including the `full-pipeline` or another opinionated tempalte,
Instead of including the `full-pipeline` or another opinionated template,
it's also possible to include individual jobs
and compose your own pipeline, for example, to just run the `fmt` job you can do:
......@@ -98,6 +98,29 @@ include:
root_dir: tofu/
```
Or you can also include the `job-templates` template, that will include
all available OpenTofu jobs as hidden job templates prefixed with `.opentofu:`.
Those are especially useful when you want to minimize your includes and
you want to extend the jobs:
```yaml
include:
- component: gitlab.com/components/opentofu/job-templates@<VERSON>
inputs:
# The version must currently be specified explicitly as an input,
# to find the correctly associated images. # This can be removed
# once https://gitlab.com/gitlab-org/gitlab/-/issues/438275 is solved.
version: <VERSION>
opentofu_version: 1.6.1
plan:
extends: [.opentofu:plan]
parallel:
matrix:
- TF_ROOT: test/
- TF_ROOT: prod/
```
Have a look at the [`full-pipeline`](templates/full-pipeline.yml) for how it's constructed.
The following job components exist:
......
spec:
inputs:
# Stages
stage_validate:
default: 'validate'
description: 'Defines the validate stage. This stage includes the `fmt` and `validate` jobs.'
stage_build:
default: 'build'
description: 'Defines the build stage. This stage includes the `plan` job.'
stage_deploy:
default: 'deploy'
description: 'Defines the deploy stage. This stage includes the `apply` job.'
stage_cleanup:
default: 'cleanup'
description: 'Defines the cleanup stage. This stage includes the `destroy` and `delete-state` jobs.'
# Versions
# This version is only required, because we cannot access the context of the component,
# see https://gitlab.com/gitlab-org/gitlab/-/issues/438275
version:
default: 'latest'
description: 'Version of this component. Has to be the same as the one in the component include entry.'
opentofu_version:
default: '1.6.1'
options:
- '$OPENTOFU_VERSION'
- '1.6.1'
- '1.6.0'
- '1.6.0-rc1'
description: 'OpenTofu version that should be used.'
# Images
image_registry_base:
default: '$CI_REGISTRY/components/opentofu'
# FIXME: not yet possible because of https://gitlab.com/gitlab-org/gitlab/-/issues/438722
# gitlab_opentofu_image:
# # FIXME: This should reference the component tag that is used.
# # Currently, blocked by https://gitlab.com/gitlab-org/gitlab/-/issues/438275
# # default: '$CI_REGISTRY/components/opentofu/gitlab-opentofu:$[[ inputs.opentofu_version ]]'
# default: '$CI_REGISTRY/components/opentofu/gitlab-opentofu:$[[ inputs.version ]]-opentofu$[[ inputs.opentofu_version ]]'
# description: 'Tag of the gitlab-opentofu image.'
# Configuration
job_name_prefix:
default: '.opentofu:'
description: 'Prefix for all job names. Jobs will be hidden if leading with a dot `.`.'
root_dir:
default: ${CI_PROJECT_DIR}
description: 'Root directory for the OpenTofu project.'
state_name:
default: default
description: 'Remote OpenTofu state name.'
auto_apply:
default: 'false'
description: 'Whether the apply job is manual or automatically run.'
auto_destroy:
default: 'false'
description: 'Whether the destroy job is manual or automatically run.'
---
include:
- local: '/templates/fmt.yml'
inputs:
as: '$[[ inputs.job_name_prefix ]]fmt'
stage: $[[ inputs.stage_validate ]]
version: $[[ inputs.version ]]
opentofu_version: $[[ inputs.opentofu_version ]]
image_registry_base: $[[ inputs.image_registry_base ]]
root_dir: $[[ inputs.root_dir ]]
- local: '/templates/validate.yml'
inputs:
as: '$[[ inputs.job_name_prefix ]]validate'
stage: $[[ inputs.stage_validate ]]
version: $[[ inputs.version ]]
opentofu_version: $[[ inputs.opentofu_version ]]
image_registry_base: $[[ inputs.image_registry_base ]]
root_dir: $[[ inputs.root_dir ]]
state_name: $[[ inputs.state_name ]]
- local: '/templates/plan.yml'
inputs:
as: '$[[ inputs.job_name_prefix ]]plan'
stage: $[[ inputs.stage_build ]]
version: $[[ inputs.version ]]
opentofu_version: $[[ inputs.opentofu_version ]]
image_registry_base: $[[ inputs.image_registry_base ]]
root_dir: $[[ inputs.root_dir ]]
state_name: $[[ inputs.state_name ]]
- local: '/templates/apply.yml'
inputs:
as: '$[[ inputs.job_name_prefix ]]apply'
stage: $[[ inputs.stage_deploy ]]
version: $[[ inputs.version ]]
opentofu_version: $[[ inputs.opentofu_version ]]
image_registry_base: $[[ inputs.image_registry_base ]]
root_dir: $[[ inputs.root_dir ]]
state_name: $[[ inputs.state_name ]]
auto_apply: $[[ inputs.auto_apply ]]
- local: '/templates/destroy.yml'
inputs:
as: '$[[ inputs.job_name_prefix ]]destroy'
stage: $[[ inputs.stage_cleanup ]]
version: $[[ inputs.version ]]
opentofu_version: $[[ inputs.opentofu_version ]]
image_registry_base: $[[ inputs.image_registry_base ]]
root_dir: $[[ inputs.root_dir ]]
state_name: $[[ inputs.state_name ]]
auto_destroy: $[[ inputs.auto_destroy ]]
- local: '/templates/delete-state.yml'
inputs:
as: '$[[ inputs.job_name_prefix ]]delete-state'
stage: $[[ inputs.stage_cleanup ]]
state_name: $[[ inputs.state_name ]]
include:
- component: gitlab.com/$CI_PROJECT_PATH/job-templates@$CI_COMMIT_SHA
inputs:
image_registry_base: $GITLAB_OPENTOFU_IMAGE_BASE
version: $CI_COMMIT_SHA
opentofu_version: $OPENTOFU_VERSION
root_dir: $TEST_TF_ROOT
state_name: $TEST_TF_STATE_NAME
stages: [validate, test, build, deploy, cleanup]
# Required to run everything immediately, instead of manually.
fmt:
extends: '.opentofu:fmt'
rules: [{when: always}]
validate:
extends: '.opentofu:validate'
rules: [{when: always}]
plan:
extends: '.opentofu:plan'
rules: [{when: always}]
apply:
extends: '.opentofu:apply'
rules: [{when: always}]
destroy:
extends: '.opentofu:destroy'
rules: [{when: always}]
delete-state:
extends: '.opentofu:delete-state'
needs: [destroy]
rules: [{when: always}]
......@@ -10,6 +10,7 @@ component:
parallel:
matrix:
- PIPELINE_NAME: [Defaults]
- PIPELINE_NAME: [JobTemplates]
backport-templates:
stage: test-integration
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment