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

Refactor rules in all jobs

parent 8a3e24a5
No related branches found
No related tags found
No related merge requests found
...@@ -62,7 +62,11 @@ spec: ...@@ -62,7 +62,11 @@ spec:
auto_apply: auto_apply:
default: false default: false
type: boolean type: boolean
description: 'Whether the apply job is manual or automatically run.' description: 'Whether the apply job is manual or automatically run. Prepend to the `rules` input array.'
rules:
type: array
default: []
description: 'An array of rules for the conditional creation of the apply job.'
--- ---
...@@ -73,9 +77,8 @@ spec: ...@@ -73,9 +77,8 @@ spec:
action: start action: start
resource_group: $TF_STATE_NAME resource_group: $TF_STATE_NAME
rules: rules:
- if: '$CI_COMMIT_BRANCH == $CI_DEFAULT_BRANCH && "$[[ inputs.auto_apply ]]" == "true"' - if: '"[[ inputs.auto_apply ]]" == "true"'
- if: $CI_COMMIT_BRANCH == $CI_DEFAULT_BRANCH - $[[ inputs.rules ]]
when: manual
cache: cache:
key: "$__CACHE_KEY_HACK" key: "$__CACHE_KEY_HACK"
paths: paths:
......
...@@ -53,11 +53,17 @@ spec: ...@@ -53,11 +53,17 @@ spec:
command: command:
description: 'The gitlab-tofu command to run.' description: 'The gitlab-tofu command to run.'
rules:
type: array
default: []
description: 'An array of rules for the conditional creation of the apply job.'
--- ---
'$[[ inputs.as ]]': '$[[ inputs.as ]]':
stage: $[[ inputs.stage ]] stage: $[[ inputs.stage ]]
needs: [] needs: []
rules: $[[ inputs.rules ]]
cache: cache:
key: "$__CACHE_KEY_HACK" key: "$__CACHE_KEY_HACK"
paths: paths:
......
...@@ -15,17 +15,19 @@ spec: ...@@ -15,17 +15,19 @@ spec:
create_delete_state_job: create_delete_state_job:
default: 'true' default: 'true'
description: 'Wheather the delete-state job should be created or not.' description: 'Wheather the delete-state job should be created or not.'
rules:
type: array
default: []
description: 'An array of rules for the conditional creation of the apply job.'
--- ---
'$[[ inputs.as ]]': '$[[ inputs.as ]]':
stage: $[[ inputs.stage ]] stage: $[[ inputs.stage ]]
rules: $[[ inputs.rules ]]
resource_group: $TF_STATE_NAME resource_group: $TF_STATE_NAME
image: curlimages/curl:latest image: curlimages/curl:latest
variables: variables:
TF_STATE_NAME: $[[ inputs.state_name ]] TF_STATE_NAME: $[[ inputs.state_name ]]
script: script:
- curl --request DELETE -u "gitlab-ci-token:$CI_JOB_TOKEN" "$CI_API_V4_URL/projects/$CI_PROJECT_ID/terraform/state/$TF_STATE_NAME" - curl --request DELETE -u "gitlab-ci-token:$CI_JOB_TOKEN" "$CI_API_V4_URL/projects/$CI_PROJECT_ID/terraform/state/$TF_STATE_NAME"
rules:
- if: '$CI_COMMIT_BRANCH == $CI_DEFAULT_BRANCH'
- when: manual
...@@ -63,6 +63,10 @@ spec: ...@@ -63,6 +63,10 @@ spec:
default: false default: false
type: boolean type: boolean
description: 'Whether the destroy job is manual or automatically run.' description: 'Whether the destroy job is manual or automatically run.'
rules:
type: array
default: []
description: 'An array of rules for the conditional creation of the apply job.'
--- ---
...@@ -72,9 +76,7 @@ spec: ...@@ -72,9 +76,7 @@ spec:
name: $TF_STATE_NAME name: $TF_STATE_NAME
action: stop action: stop
resource_group: $TF_STATE_NAME resource_group: $TF_STATE_NAME
rules: rules: $[[ inputs.rules ]]
- if: '$CI_COMMIT_BRANCH == $CI_DEFAULT_BRANCH && "$[[ inputs.auto_destroy ]]" == "true"'
- when: manual
cache: cache:
key: "$__CACHE_KEY_HACK" key: "$__CACHE_KEY_HACK"
paths: paths:
......
...@@ -49,22 +49,21 @@ spec: ...@@ -49,22 +49,21 @@ spec:
root_dir: root_dir:
default: ${CI_PROJECT_DIR} default: ${CI_PROJECT_DIR}
description: 'Root directory for the OpenTofu project.' description: 'Root directory for the OpenTofu project.'
allow_failure: allow_failure:
default: true default: true
type: boolean type: boolean
description: 'If the job is allowed to fail or not.' description: 'If the job is allowed to fail or not.'
rules:
type: array
default: []
description: 'An array of rules for the conditional creation of the apply job.'
--- ---
'$[[ inputs.as ]]': '$[[ inputs.as ]]':
stage: $[[ inputs.stage ]] stage: $[[ inputs.stage ]]
needs: [] needs: []
rules: rules: $[[ inputs.rules ]]
- if: $CI_PIPELINE_SOURCE == "merge_request_event"
- if: $CI_OPEN_MERGE_REQUESTS # Don't add it to a *branch* pipeline if it's already in a merge request pipeline.
when: never
- if: $CI_COMMIT_BRANCH # If there's no open merge request, add it to a *branch* pipeline instead.
allow_failure: $[[ inputs.allow_failure ]] allow_failure: $[[ inputs.allow_failure ]]
cache: cache:
key: "$__CACHE_KEY_HACK" key: "$__CACHE_KEY_HACK"
......
...@@ -85,6 +85,11 @@ include: ...@@ -85,6 +85,11 @@ include:
image_registry_base: $[[ inputs.image_registry_base ]] image_registry_base: $[[ inputs.image_registry_base ]]
image_name: $[[ inputs.image_name ]] image_name: $[[ inputs.image_name ]]
root_dir: $[[ inputs.root_dir ]] root_dir: $[[ inputs.root_dir ]]
rules:
- if: $CI_PIPELINE_SOURCE == "merge_request_event"
- if: $CI_OPEN_MERGE_REQUESTS # Don't add it to a *branch* pipeline if it's already in a merge request pipeline.
when: never
- if: $CI_COMMIT_BRANCH # If there's no open merge request, add it to a *branch* pipeline instead.
- local: '/templates/validate.yml' - local: '/templates/validate.yml'
inputs: inputs:
as: 'validate' as: 'validate'
...@@ -95,6 +100,11 @@ include: ...@@ -95,6 +100,11 @@ include:
image_name: $[[ inputs.image_name ]] image_name: $[[ inputs.image_name ]]
root_dir: $[[ inputs.root_dir ]] root_dir: $[[ inputs.root_dir ]]
state_name: $[[ inputs.state_name ]] state_name: $[[ inputs.state_name ]]
rules:
- if: $CI_PIPELINE_SOURCE == "merge_request_event"
- if: $CI_OPEN_MERGE_REQUESTS # Don't add it to a *branch* pipeline if it's already in a merge request pipeline.
when: never
- if: $CI_COMMIT_BRANCH # If there's no open merge request, add it to a *branch* pipeline instead.
- local: '/templates/test.yml' - local: '/templates/test.yml'
inputs: inputs:
as: 'test' as: 'test'
...@@ -105,6 +115,11 @@ include: ...@@ -105,6 +115,11 @@ include:
image_name: $[[ inputs.image_name ]] image_name: $[[ inputs.image_name ]]
root_dir: $[[ inputs.root_dir ]] root_dir: $[[ inputs.root_dir ]]
state_name: $[[ inputs.state_name ]] state_name: $[[ inputs.state_name ]]
rules:
- if: $CI_PIPELINE_SOURCE == "merge_request_event"
- if: $CI_OPEN_MERGE_REQUESTS # Don't add it to a *branch* pipeline if it's already in a merge request pipeline.
when: never
- if: $CI_COMMIT_BRANCH # If there's no open merge request, add it to a *branch* pipeline instead.
rules: rules:
- exists: - exists:
- $[[ inputs.root_dir ]]/**/*.tftest.hcl - $[[ inputs.root_dir ]]/**/*.tftest.hcl
...@@ -119,6 +134,11 @@ include: ...@@ -119,6 +134,11 @@ include:
root_dir: $[[ inputs.root_dir ]] root_dir: $[[ inputs.root_dir ]]
state_name: $[[ inputs.state_name ]] state_name: $[[ inputs.state_name ]]
artifacts_access: $[[ inputs.plan_artifacts_access ]] artifacts_access: $[[ inputs.plan_artifacts_access ]]
rules:
- if: $CI_PIPELINE_SOURCE == "merge_request_event"
- if: $CI_OPEN_MERGE_REQUESTS # Don't add it to a *branch* pipeline if it's already in a merge request pipeline.
when: never
- if: $CI_COMMIT_BRANCH # If there's no open merge request, add it to a *branch* pipeline instead.
- local: '/templates/apply.yml' - local: '/templates/apply.yml'
inputs: inputs:
as: 'apply' as: 'apply'
...@@ -130,6 +150,9 @@ include: ...@@ -130,6 +150,9 @@ include:
root_dir: $[[ inputs.root_dir ]] root_dir: $[[ inputs.root_dir ]]
state_name: $[[ inputs.state_name ]] state_name: $[[ inputs.state_name ]]
auto_apply: $[[ inputs.auto_apply ]] auto_apply: $[[ inputs.auto_apply ]]
rules:
- if: $CI_COMMIT_BRANCH == $CI_DEFAULT_BRANCH
when: manual
- local: '/templates/destroy.yml' - local: '/templates/destroy.yml'
inputs: inputs:
as: 'destroy' as: 'destroy'
...@@ -141,11 +164,17 @@ include: ...@@ -141,11 +164,17 @@ include:
root_dir: $[[ inputs.root_dir ]] root_dir: $[[ inputs.root_dir ]]
state_name: $[[ inputs.state_name ]] state_name: $[[ inputs.state_name ]]
auto_destroy: $[[ inputs.auto_destroy ]] auto_destroy: $[[ inputs.auto_destroy ]]
rules:
- if: '$CI_COMMIT_BRANCH == $CI_DEFAULT_BRANCH && "$[[ inputs.auto_destroy ]]" == "true"'
- when: manual
- local: '/templates/delete-state.yml' - local: '/templates/delete-state.yml'
inputs: inputs:
as: 'delete-state' as: 'delete-state'
stage: $[[ inputs.stage_cleanup ]] stage: $[[ inputs.stage_cleanup ]]
state_name: $[[ inputs.state_name ]] state_name: $[[ inputs.state_name ]]
rules:
- if: '$CI_COMMIT_BRANCH == $CI_DEFAULT_BRANCH'
- when: manual
# NOTE: we have to define this `needs` here, because inputs don't support arrays, yet. # NOTE: we have to define this `needs` here, because inputs don't support arrays, yet.
delete-state: delete-state:
......
...@@ -30,10 +30,16 @@ spec: ...@@ -30,10 +30,16 @@ spec:
e.g. '0.1.0' e.g. '0.1.0'
default: ${CI_COMMIT_TAG} default: ${CI_COMMIT_TAG}
rules:
type: array
default: []
description: 'An array of rules for the conditional creation of the apply job.'
--- ---
'$[[ inputs.as ]]': '$[[ inputs.as ]]':
stage: $[[ inputs.stage ]] stage: $[[ inputs.stage ]]
rules: $[[ inputs.rules ]]
image: curlimages/curl:8.8.0 image: curlimages/curl:8.8.0
variables: variables:
TAR_FILENAME: /tmp/${CI_PROJECT_NAME}-${CI_COMMIT_SHA}.tgz TAR_FILENAME: /tmp/${CI_PROJECT_NAME}-${CI_COMMIT_SHA}.tgz
......
...@@ -62,6 +62,10 @@ spec: ...@@ -62,6 +62,10 @@ spec:
artifacts_access: artifacts_access:
default: 'none' default: 'none'
description: 'Access level for the plan artifact. See https://docs.gitlab.com/ee/ci/yaml/#artifactsaccess for possible values.' description: 'Access level for the plan artifact. See https://docs.gitlab.com/ee/ci/yaml/#artifactsaccess for possible values.'
rules:
type: array
default: []
description: 'An array of rules for the conditional creation of the apply job.'
--- ---
...@@ -81,11 +85,7 @@ spec: ...@@ -81,11 +85,7 @@ spec:
- $TF_ROOT/$[[ inputs.plan_name ]].cache - $TF_ROOT/$[[ inputs.plan_name ]].cache
reports: reports:
terraform: $TF_ROOT/$[[ inputs.plan_name]].json terraform: $TF_ROOT/$[[ inputs.plan_name]].json
rules: rules: $[[ inputs.rules ]]
- if: $CI_PIPELINE_SOURCE == "merge_request_event"
- if: $CI_OPEN_MERGE_REQUESTS # Don't add it to a *branch* pipeline if it's already in a merge request pipeline.
when: never
- if: $CI_COMMIT_BRANCH # If there's no open merge request, add it to a *branch* pipeline instead.
cache: cache:
key: "$__CACHE_KEY_HACK" key: "$__CACHE_KEY_HACK"
paths: paths:
......
...@@ -52,17 +52,17 @@ spec: ...@@ -52,17 +52,17 @@ spec:
state_name: state_name:
default: default default: default
description: 'Remote OpenTofu state name.' description: 'Remote OpenTofu state name.'
rules:
type: array
default: []
description: 'An array of rules for the conditional creation of the apply job.'
--- ---
'$[[ inputs.as ]]': '$[[ inputs.as ]]':
stage: $[[ inputs.stage ]] stage: $[[ inputs.stage ]]
needs: [] needs: []
rules: rules: $[[ inputs.rules ]]
- if: $CI_PIPELINE_SOURCE == "merge_request_event"
- if: $CI_OPEN_MERGE_REQUESTS # Don't add it to a *branch* pipeline if it's already in a merge request pipeline.
when: never
- if: $CI_COMMIT_BRANCH # If there's no open merge request, add it to a *branch* pipeline instead.
cache: cache:
key: "$__CACHE_KEY_HACK" key: "$__CACHE_KEY_HACK"
paths: paths:
......
...@@ -75,6 +75,11 @@ include: ...@@ -75,6 +75,11 @@ include:
image_registry_base: $[[ inputs.image_registry_base ]] image_registry_base: $[[ inputs.image_registry_base ]]
image_name: $[[ inputs.image_name ]] image_name: $[[ inputs.image_name ]]
root_dir: $[[ inputs.root_dir ]] root_dir: $[[ inputs.root_dir ]]
rules:
- if: $CI_PIPELINE_SOURCE == "merge_request_event"
- if: $CI_OPEN_MERGE_REQUESTS # Don't add it to a *branch* pipeline if it's already in a merge request pipeline.
when: never
- if: $CI_COMMIT_BRANCH # If there's no open merge request, add it to a *branch* pipeline instead.
- local: '/templates/validate.yml' - local: '/templates/validate.yml'
inputs: inputs:
as: 'validate' as: 'validate'
...@@ -85,6 +90,11 @@ include: ...@@ -85,6 +90,11 @@ include:
image_name: $[[ inputs.image_name ]] image_name: $[[ inputs.image_name ]]
root_dir: $[[ inputs.root_dir ]] root_dir: $[[ inputs.root_dir ]]
state_name: $[[ inputs.state_name ]] state_name: $[[ inputs.state_name ]]
rules:
- if: $CI_PIPELINE_SOURCE == "merge_request_event"
- if: $CI_OPEN_MERGE_REQUESTS # Don't add it to a *branch* pipeline if it's already in a merge request pipeline.
when: never
- if: $CI_COMMIT_BRANCH # If there's no open merge request, add it to a *branch* pipeline instead.
- local: '/templates/plan.yml' - local: '/templates/plan.yml'
inputs: inputs:
as: 'plan' as: 'plan'
...@@ -96,6 +106,11 @@ include: ...@@ -96,6 +106,11 @@ include:
root_dir: $[[ inputs.root_dir ]] root_dir: $[[ inputs.root_dir ]]
state_name: $[[ inputs.state_name ]] state_name: $[[ inputs.state_name ]]
artifacts_access: $[[ inputs.plan_artifacts_access ]] artifacts_access: $[[ inputs.plan_artifacts_access ]]
rules:
- if: $CI_PIPELINE_SOURCE == "merge_request_event"
- if: $CI_OPEN_MERGE_REQUESTS # Don't add it to a *branch* pipeline if it's already in a merge request pipeline.
when: never
- if: $CI_COMMIT_BRANCH # If there's no open merge request, add it to a *branch* pipeline instead.
- local: '/templates/apply.yml' - local: '/templates/apply.yml'
inputs: inputs:
as: 'apply' as: 'apply'
...@@ -107,3 +122,6 @@ include: ...@@ -107,3 +122,6 @@ include:
root_dir: $[[ inputs.root_dir ]] root_dir: $[[ inputs.root_dir ]]
state_name: $[[ inputs.state_name ]] state_name: $[[ inputs.state_name ]]
auto_apply: $[[ inputs.auto_apply ]] auto_apply: $[[ inputs.auto_apply ]]
rules:
- if: $CI_COMMIT_BRANCH == $CI_DEFAULT_BRANCH
when: manual
...@@ -78,6 +78,11 @@ include: ...@@ -78,6 +78,11 @@ include:
image_registry_base: $[[ inputs.image_registry_base ]] image_registry_base: $[[ inputs.image_registry_base ]]
image_name: $[[ inputs.image_name ]] image_name: $[[ inputs.image_name ]]
root_dir: $[[ inputs.root_dir ]] root_dir: $[[ inputs.root_dir ]]
rules:
- if: $CI_PIPELINE_SOURCE == "merge_request_event"
- if: $CI_OPEN_MERGE_REQUESTS # Don't add it to a *branch* pipeline if it's already in a merge request pipeline.
when: never
- if: $CI_COMMIT_BRANCH # If there's no open merge request, add it to a *branch* pipeline instead.
- local: '/templates/validate.yml' - local: '/templates/validate.yml'
inputs: inputs:
as: 'validate' as: 'validate'
...@@ -88,6 +93,11 @@ include: ...@@ -88,6 +93,11 @@ include:
image_name: $[[ inputs.image_name ]] image_name: $[[ inputs.image_name ]]
root_dir: $[[ inputs.root_dir ]] root_dir: $[[ inputs.root_dir ]]
state_name: $[[ inputs.state_name ]] state_name: $[[ inputs.state_name ]]
rules:
- if: $CI_PIPELINE_SOURCE == "merge_request_event"
- if: $CI_OPEN_MERGE_REQUESTS # Don't add it to a *branch* pipeline if it's already in a merge request pipeline.
when: never
- if: $CI_COMMIT_BRANCH # If there's no open merge request, add it to a *branch* pipeline instead.
- local: '/templates/plan.yml' - local: '/templates/plan.yml'
inputs: inputs:
as: 'plan' as: 'plan'
...@@ -101,6 +111,11 @@ include: ...@@ -101,6 +111,11 @@ include:
plan_name: $[[ inputs.plan_name ]] plan_name: $[[ inputs.plan_name ]]
artifacts_access: $[[ inputs.plan_artifacts_access ]] artifacts_access: $[[ inputs.plan_artifacts_access ]]
destroy: true destroy: true
rules:
- if: $CI_PIPELINE_SOURCE == "merge_request_event"
- if: $CI_OPEN_MERGE_REQUESTS # Don't add it to a *branch* pipeline if it's already in a merge request pipeline.
when: never
- if: $CI_COMMIT_BRANCH # If there's no open merge request, add it to a *branch* pipeline instead.
- local: '/templates/destroy.yml' - local: '/templates/destroy.yml'
inputs: inputs:
as: 'destroy' as: 'destroy'
...@@ -114,11 +129,17 @@ include: ...@@ -114,11 +129,17 @@ include:
no_plan: false no_plan: false
plan_name: $[[ inputs.plan_name ]] plan_name: $[[ inputs.plan_name ]]
auto_destroy: $[[ inputs.auto_destroy ]] auto_destroy: $[[ inputs.auto_destroy ]]
rules:
- if: '$CI_COMMIT_BRANCH == $CI_DEFAULT_BRANCH && "$[[ inputs.auto_destroy ]]" == "true"'
- when: manual
- local: '/templates/delete-state.yml' - local: '/templates/delete-state.yml'
inputs: inputs:
as: 'delete-state' as: 'delete-state'
stage: $[[ inputs.stage_cleanup ]] stage: $[[ inputs.stage_cleanup ]]
state_name: $[[ inputs.state_name ]] state_name: $[[ inputs.state_name ]]
rules:
- if: '$CI_COMMIT_BRANCH == $CI_DEFAULT_BRANCH'
- when: manual
# NOTE: we have to define this `needs` here, because inputs don't support arrays, yet. # NOTE: we have to define this `needs` here, because inputs don't support arrays, yet.
delete-state: delete-state:
......
...@@ -68,6 +68,11 @@ include: ...@@ -68,6 +68,11 @@ include:
image_registry_base: $[[ inputs.image_registry_base ]] image_registry_base: $[[ inputs.image_registry_base ]]
image_name: $[[ inputs.image_name ]] image_name: $[[ inputs.image_name ]]
root_dir: $[[ inputs.root_dir ]] root_dir: $[[ inputs.root_dir ]]
rules:
- if: $CI_PIPELINE_SOURCE == "merge_request_event"
- if: $CI_OPEN_MERGE_REQUESTS # Don't add it to a *branch* pipeline if it's already in a merge request pipeline.
when: never
- if: $CI_COMMIT_BRANCH # If there's no open merge request, add it to a *branch* pipeline instead.
- local: '/templates/validate.yml' - local: '/templates/validate.yml'
inputs: inputs:
as: 'validate' as: 'validate'
...@@ -78,6 +83,11 @@ include: ...@@ -78,6 +83,11 @@ include:
image_name: $[[ inputs.image_name ]] image_name: $[[ inputs.image_name ]]
root_dir: $[[ inputs.root_dir ]] root_dir: $[[ inputs.root_dir ]]
state_name: $[[ inputs.state_name ]] state_name: $[[ inputs.state_name ]]
rules:
- if: $CI_PIPELINE_SOURCE == "merge_request_event"
- if: $CI_OPEN_MERGE_REQUESTS # Don't add it to a *branch* pipeline if it's already in a merge request pipeline.
when: never
- if: $CI_COMMIT_BRANCH # If there's no open merge request, add it to a *branch* pipeline instead.
- local: '/templates/plan.yml' - local: '/templates/plan.yml'
inputs: inputs:
as: 'plan' as: 'plan'
...@@ -89,3 +99,8 @@ include: ...@@ -89,3 +99,8 @@ include:
root_dir: $[[ inputs.root_dir ]] root_dir: $[[ inputs.root_dir ]]
state_name: $[[ inputs.state_name ]] state_name: $[[ inputs.state_name ]]
artifacts_access: $[[ inputs.artifacts_access ]] artifacts_access: $[[ inputs.artifacts_access ]]
rules:
- if: $CI_PIPELINE_SOURCE == "merge_request_event"
- if: $CI_OPEN_MERGE_REQUESTS # Don't add it to a *branch* pipeline if it's already in a merge request pipeline.
when: never
- if: $CI_COMMIT_BRANCH # If there's no open merge request, add it to a *branch* pipeline instead.
...@@ -52,16 +52,16 @@ spec: ...@@ -52,16 +52,16 @@ spec:
state_name: state_name:
default: default default: default
description: 'Remote OpenTofu state name.' description: 'Remote OpenTofu state name.'
rules:
type: array
default: []
description: 'An array of rules for the conditional creation of the apply job.'
--- ---
'$[[ inputs.as ]]': '$[[ inputs.as ]]':
stage: $[[ inputs.stage ]] stage: $[[ inputs.stage ]]
rules: rules: $[[ inputs.rules ]]
- if: $CI_PIPELINE_SOURCE == "merge_request_event"
- if: $CI_OPEN_MERGE_REQUESTS # Don't add it to a *branch* pipeline if it's already in a merge request pipeline.
when: never
- if: $CI_COMMIT_BRANCH # If there's no open merge request, add it to a *branch* pipeline instead.
cache: cache:
key: "$__CACHE_KEY_HACK" key: "$__CACHE_KEY_HACK"
paths: paths:
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment