From 6d4e809d23abc78d753bef3c718cf8951e38c163 Mon Sep 17 00:00:00 2001 From: Timo Furrer <tfurrer@gitlab.com> Date: Fri, 26 Jan 2024 13:58:24 +0100 Subject: [PATCH] Add validate-plan template --- .gitlab/README.md.template | 1 + README.md | 1 + templates/validate-plan.yml | 74 +++++++++++++++++++++++++++++++++++++ 3 files changed, 76 insertions(+) create mode 100644 templates/validate-plan.yml diff --git a/.gitlab/README.md.template b/.gitlab/README.md.template index d69eb2e..df17d9c 100644 --- a/.gitlab/README.md.template +++ b/.gitlab/README.md.template @@ -74,6 +74,7 @@ This component repository also provides some templates that may often be used, for example one that only runs validation (`fmt` and `validate`), plan and an apply, but no destructive actions. +- [`validate-plan`](templates/validate-plan.yml) - [`validate-plan-apply`](templates/validate-plan-apply.yml) ### Job Templates diff --git a/README.md b/README.md index 5b174b4..b58af40 100644 --- a/README.md +++ b/README.md @@ -76,6 +76,7 @@ This component repository also provides some templates that may often be used, for example one that only runs validation (`fmt` and `validate`), plan and an apply, but no destructive actions. +- [`validate-plan`](templates/validate-plan.yml) - [`validate-plan-apply`](templates/validate-plan-apply.yml) ### Job Templates diff --git a/templates/validate-plan.yml b/templates/validate-plan.yml new file mode 100644 index 0000000..090330c --- /dev/null +++ b/templates/validate-plan.yml @@ -0,0 +1,74 @@ +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.' + + # 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 + root_dir: + default: ${CI_PROJECT_DIR} + description: 'Root directory for the OpenTofu project.' + state_name: + default: default + description: 'Remote OpenTofu state name.' + +--- + +include: + - local: '/templates/fmt.yml' + inputs: + as: '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: '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: '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 ]] -- GitLab