diff --git a/.gitlab/README.md b/.gitlab/README.md index b16477ee5295d408b841b12de32ea1a59609b1f4..73a6804c9f7e5c46cc10e01b6543e7690e8452b7 100644 --- a/.gitlab/README.md +++ b/.gitlab/README.md @@ -35,7 +35,7 @@ include: version: <VERSION> opentofu_version: <OPENTOFU_VERSION> -stages: [validate, test, build, deploy, cleanup] +stages: [validate, build, deploy, cleanup] ``` A concrete example may look like this: @@ -51,7 +51,7 @@ include: version: latest opentofu_version: 1.6.0 -stages: [validate, test, build, deploy, cleanup] +stages: [validate, build, deploy, cleanup] --- @@ -65,10 +65,21 @@ include: version: 0.0.0-alpha1 opentofu_version: 1.6.0 -stages: [validate, test, build, deploy, cleanup] +stages: [validate, build, deploy, cleanup] ``` -Instead of including the `full-pipeline`, it's also possible to include individual jobs +### Opinionated Templates + +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-apply`](templates/validate-plan-apply.yml) + +### Job Templates + +Instead of including the `full-pipeline` or another opinionated tempalte, +it's also possible to include individual jobs and compose your own pipeline, for example, to just run the `fmt` job you can do: ```yaml diff --git a/README.md b/README.md index 74e64f97bd609ec991e1c190ce6fa01247a215e4..08835ac88e9eb8b94074d2d0b5a4ad17c00cf47f 100644 --- a/README.md +++ b/README.md @@ -37,7 +37,7 @@ include: version: <VERSION> opentofu_version: <OPENTOFU_VERSION> -stages: [validate, test, build, deploy, cleanup] +stages: [validate, build, deploy, cleanup] ``` A concrete example may look like this: @@ -53,7 +53,7 @@ include: version: latest opentofu_version: 1.6.0 -stages: [validate, test, build, deploy, cleanup] +stages: [validate, build, deploy, cleanup] --- @@ -67,10 +67,21 @@ include: version: 0.0.0-alpha1 opentofu_version: 1.6.0 -stages: [validate, test, build, deploy, cleanup] +stages: [validate, build, deploy, cleanup] ``` -Instead of including the `full-pipeline`, it's also possible to include individual jobs +### Opinionated Templates + +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-apply`](templates/validate-plan-apply.yml) + +### Job Templates + +Instead of including the `full-pipeline` or another opinionated tempalte, +it's also possible to include individual jobs and compose your own pipeline, for example, to just run the `fmt` job you can do: ```yaml diff --git a/templates/validate-plan-apply.yml b/templates/validate-plan-apply.yml new file mode 100644 index 0000000000000000000000000000000000000000..56d65a9823108859c36fc77d93ce7aab04c4f99d --- /dev/null +++ b/templates/validate-plan-apply.yml @@ -0,0 +1,89 @@ +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.' + + # 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.0' + options: + - '$OPENTOFU_VERSION' + - '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.' + auto_apply: + default: 'false' + description: 'Whether the apply job is manual or automatically run.' + +--- + +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 ]] + - local: '/templates/apply.yml' + inputs: + as: '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 ]]