diff --git a/.gitlab/README.md.template b/.gitlab/README.md.template index 5306016f1d238cf80d8f3e15b09af51dcd7aa74e..e119f758c70c59a81df63623704f634cb8c6c040 100644 --- a/.gitlab/README.md.template +++ b/.gitlab/README.md.template @@ -238,6 +238,9 @@ include: This example assumes your GitLab instance is hosted on `gitlab.example.com` and this component project is mirrored in the `components/opentofu` project. +If the component is being mirrored to another path then `components/opentofu`, then you also +need to change that path in the `include:component` and additionally provide the correct +`image_registry_base` input. ## Migrating from the Terraform CI/CD templates @@ -267,6 +270,23 @@ whereas the Terraform CI/CD templates used [`variables`](https://docs.gitlab.com We recommend that you use the `inputs` with the OpenTofu component where available and required. However, if needed you may overwrite the jobs and set the `variables` you like. +## Can I use this component with Terraform? + +Probably. Although, we don't officially support it or maintain any compatibility layer where necessary. + +The OpenTofu CI/CD component job mainly interface with the [`gitlab-tofu`](src/gitlab-tofu.sh) script +that is distributed with the `gitlab-opentofu` container image used as the base image for the jobs. +This base image also contains the `tofu` binary. + +If you'd want to use Terraform instead you may provide your own container image +that contains at least a script called `gitlab-tofu` so that it's compatible with the component jobs. +Everything else in the job can be custom, like replacing `tofu` with `terraform`. + +You may provide the `image_registry_base` input to any of the component includes, pointing to the +container registry URI hosting the container image. The container image name can be configured in +the `image_name` input. The image has be versioned so that it is compatible +with [the image versioning of this project](#image-versions). + ## Contributing See the [CONTRIBUTING.md](CONTRIBUTING.md) guide. diff --git a/Makefile b/Makefile index 62a8d4f8484d75cd785406c67d2ebc1febd812e4..5620bef1039266348dba42370a90375b3a41b418 100644 --- a/Makefile +++ b/Makefile @@ -38,6 +38,7 @@ backports: @# Common inputs @sed -i $(BACKPORTS_BASE_FILE) -e 's/$$\[\[ inputs.image_registry_base \]\]/$$GITLAB_OPENTOFU_IMAGE_REGISTRY_BASE/' + @sed -i $(BACKPORTS_BASE_FILE) -e 's/$$\[\[ inputs.image_name \]\]/gitlab-opentofu/' @sed -i $(BACKPORTS_BASE_FILE) -e 's/$$\[\[ inputs.version \]\]/$$GITLAB_OPENTOFU_VERSION/' @sed -i $(BACKPORTS_BASE_FILE) -e 's/$$\[\[ inputs.opentofu_version \]\]/$$OPENTOFU_VERSION/' @sed -i $(BACKPORTS_BASE_FILE) -e 's/$$\[\[ inputs.root_dir \]\]/$$TF_ROOT/' diff --git a/README.md b/README.md index 7fdec3e369963f4cc0640b88ceec4fc45693fbd3..50bb932edf560639d40786c4bf37d817fbd56918 100644 --- a/README.md +++ b/README.md @@ -180,6 +180,8 @@ Have a look at the individual template spec to learn about the available inputs. | `stage_cleanup` | `cleanup` | Defines the cleanup stage. This stage includes the `destroy` and `delete-state` jobs. | | `version` | `latest` | Version of this component. Has to be the same as the one in the component include entry. | | `opentofu_version` | `1.6.1` | OpenTofu version that should be used. Must be one of `1.6.1`, `1.6.0`, `1.6.0-rc1`. | +| `image_registry_base` | `$CI_REGISTRY/components/opentofu` | Host URI to the job images. Will be combined with `image_name` to construct the actual image URI. | +| `image_name` | `gitlab-opentofu` | Image name for the job images. Hosted under `image_registry_base`. | | `root_dir` | `${CI_PROJECT_DIR}` | Root directory for the OpenTofu project. | | `state_name` | `default` | Remote OpenTofu state name. | | `auto_apply` | `false` | Whether the apply job is manual or automatically run. | @@ -257,6 +259,9 @@ include: This example assumes your GitLab instance is hosted on `gitlab.example.com` and this component project is mirrored in the `components/opentofu` project. +If the component is being mirrored to another path then `components/opentofu`, then you also +need to change that path in the `include:component` and additionally provide the correct +`image_registry_base` input. ## Migrating from the Terraform CI/CD templates @@ -286,6 +291,23 @@ whereas the Terraform CI/CD templates used [`variables`](https://docs.gitlab.com We recommend that you use the `inputs` with the OpenTofu component where available and required. However, if needed you may overwrite the jobs and set the `variables` you like. +## Can I use this component with Terraform? + +Probably. Although, we don't officially support it or maintain any compatibility layer where necessary. + +The OpenTofu CI/CD component job mainly interface with the [`gitlab-tofu`](src/gitlab-tofu.sh) script +that is distributed with the `gitlab-opentofu` container image used as the base image for the jobs. +This base image also contains the `tofu` binary. + +If you'd want to use Terraform instead you may provide your own container image +that contains at least a script called `gitlab-tofu` so that it's compatible with the component jobs. +Everything else in the job can be custom, like replacing `tofu` with `terraform`. + +You may provide the `image_registry_base` input to any of the component includes, pointing to the +container registry URI hosting the container image. The container image name can be configured in +the `image_name` input. The image has be versioned so that it is compatible +with [the image versioning of this project](#image-versions). + ## Contributing See the [CONTRIBUTING.md](CONTRIBUTING.md) guide. diff --git a/templates/apply.yml b/templates/apply.yml index ae0de41adb77c6e7f896a357748a8a155092c4e9..9896c11408627f0365780dd9c74b6d2fca76176f 100644 --- a/templates/apply.yml +++ b/templates/apply.yml @@ -27,6 +27,7 @@ spec: # Images image_registry_base: default: '$CI_REGISTRY/components/opentofu' + description: 'Host URI to the job images. Will be combined with `image_name` to construct the actual image URI.' # 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. @@ -35,6 +36,10 @@ spec: # default: '$CI_REGISTRY/components/opentofu/gitlab-opentofu:$[[ inputs.version ]]-opentofu$[[ inputs.opentofu_version ]]' # description: 'Tag of the gitlab-opentofu image.' + image_name: + default: 'gitlab-opentofu' + description: 'Image name for the job images. Hosted under `image_registry_base`.' + # Configuration root_dir: default: ${CI_PROJECT_DIR} @@ -68,6 +73,6 @@ spec: TF_ROOT: $[[ inputs.root_dir ]] TF_STATE_NAME: $[[ inputs.state_name ]] image: - name: '$[[ inputs.image_registry_base ]]/gitlab-opentofu:$[[ inputs.version ]]-opentofu$[[ inputs.opentofu_version ]]' + name: '$[[ inputs.image_registry_base ]]/$[[ inputs.image_name ]]:$[[ inputs.version ]]-opentofu$[[ inputs.opentofu_version ]]' script: - gitlab-tofu apply diff --git a/templates/destroy.yml b/templates/destroy.yml index a14695bdfea385e38eda5a18f7398f61b5f1d17f..95c49a3cfb3e8f8891cfe29fe88c998ea8541ab2 100644 --- a/templates/destroy.yml +++ b/templates/destroy.yml @@ -27,6 +27,7 @@ spec: # Images image_registry_base: default: '$CI_REGISTRY/components/opentofu' + description: 'Host URI to the job images. Will be combined with `image_name` to construct the actual image URI.' # 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. @@ -35,6 +36,10 @@ spec: # default: '$CI_REGISTRY/components/opentofu/gitlab-opentofu:$[[ inputs.version ]]-opentofu$[[ inputs.opentofu_version ]]' # description: 'Tag of the gitlab-opentofu image.' + image_name: + default: 'gitlab-opentofu' + description: 'Image name for the job images. Hosted under `image_registry_base`.' + # Configuration root_dir: default: ${CI_PROJECT_DIR} @@ -67,6 +72,6 @@ spec: TF_ROOT: $[[ inputs.root_dir ]] TF_STATE_NAME: $[[ inputs.state_name ]] image: - name: '$[[ inputs.image_registry_base ]]/gitlab-opentofu:$[[ inputs.version ]]-opentofu$[[ inputs.opentofu_version ]]' + name: '$[[ inputs.image_registry_base ]]/$[[ inputs.image_name ]]:$[[ inputs.version ]]-opentofu$[[ inputs.opentofu_version ]]' script: - gitlab-tofu destroy diff --git a/templates/fmt.yml b/templates/fmt.yml index 3f48faa674a586d823e14a2440f64fd414c4482b..01bf85df0fd3d97b8910d33fae5e1cbdbd6dc9c7 100644 --- a/templates/fmt.yml +++ b/templates/fmt.yml @@ -27,6 +27,7 @@ spec: # Images image_registry_base: default: '$CI_REGISTRY/components/opentofu' + description: 'Host URI to the job images. Will be combined with `image_name` to construct the actual image URI.' # 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. @@ -35,6 +36,10 @@ spec: # default: '$CI_REGISTRY/components/opentofu/gitlab-opentofu:$[[ inputs.version ]]-opentofu$[[ inputs.opentofu_version ]]' # description: 'Tag of the gitlab-opentofu image.' + image_name: + default: 'gitlab-opentofu' + description: 'Image name for the job images. Hosted under `image_registry_base`.' + # Configuration root_dir: default: ${CI_PROJECT_DIR} @@ -67,6 +72,6 @@ spec: __CACHE_KEY_HACK: "$[[ inputs.root_dir ]]" TF_ROOT: $[[ inputs.root_dir ]] image: - name: '$[[ inputs.image_registry_base ]]/gitlab-opentofu:$[[ inputs.version ]]-opentofu$[[ inputs.opentofu_version ]]' + name: '$[[ inputs.image_registry_base ]]/$[[ inputs.image_name ]]:$[[ inputs.version ]]-opentofu$[[ inputs.opentofu_version ]]' script: - gitlab-tofu fmt diff --git a/templates/full-pipeline.yml b/templates/full-pipeline.yml index 8c9a83325f77329d8405ba8811327c3cb2fb0d2c..cebc9dcf8df58db71526821beaa4c6950ba59627 100644 --- a/templates/full-pipeline.yml +++ b/templates/full-pipeline.yml @@ -33,6 +33,7 @@ spec: # Images image_registry_base: default: '$CI_REGISTRY/components/opentofu' + description: 'Host URI to the job images. Will be combined with `image_name` to construct the actual image URI.' # 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. @@ -41,6 +42,10 @@ spec: # default: '$CI_REGISTRY/components/opentofu/gitlab-opentofu:$[[ inputs.version ]]-opentofu$[[ inputs.opentofu_version ]]' # description: 'Tag of the gitlab-opentofu image.' + image_name: + default: 'gitlab-opentofu' + description: 'Image name for the job images. Hosted under `image_registry_base`.' + # Configuration root_dir: default: ${CI_PROJECT_DIR} @@ -65,6 +70,7 @@ include: version: $[[ inputs.version ]] opentofu_version: $[[ inputs.opentofu_version ]] image_registry_base: $[[ inputs.image_registry_base ]] + image_name: $[[ inputs.image_name ]] root_dir: $[[ inputs.root_dir ]] - local: '/templates/validate.yml' inputs: @@ -73,6 +79,7 @@ include: version: $[[ inputs.version ]] opentofu_version: $[[ inputs.opentofu_version ]] image_registry_base: $[[ inputs.image_registry_base ]] + image_name: $[[ inputs.image_name ]] root_dir: $[[ inputs.root_dir ]] state_name: $[[ inputs.state_name ]] - local: '/templates/plan.yml' @@ -82,6 +89,7 @@ include: version: $[[ inputs.version ]] opentofu_version: $[[ inputs.opentofu_version ]] image_registry_base: $[[ inputs.image_registry_base ]] + image_name: $[[ inputs.image_name ]] root_dir: $[[ inputs.root_dir ]] state_name: $[[ inputs.state_name ]] - local: '/templates/apply.yml' @@ -91,6 +99,7 @@ include: version: $[[ inputs.version ]] opentofu_version: $[[ inputs.opentofu_version ]] image_registry_base: $[[ inputs.image_registry_base ]] + image_name: $[[ inputs.image_name ]] root_dir: $[[ inputs.root_dir ]] state_name: $[[ inputs.state_name ]] auto_apply: $[[ inputs.auto_apply ]] @@ -101,6 +110,7 @@ include: version: $[[ inputs.version ]] opentofu_version: $[[ inputs.opentofu_version ]] image_registry_base: $[[ inputs.image_registry_base ]] + image_name: $[[ inputs.image_name ]] root_dir: $[[ inputs.root_dir ]] state_name: $[[ inputs.state_name ]] auto_destroy: $[[ inputs.auto_destroy ]] diff --git a/templates/job-templates.yml b/templates/job-templates.yml index 5a2b17c87d58c1f069c9ab327253b76529d511cd..b67f9fbcea68002b80fa6672781747676aa66d73 100644 --- a/templates/job-templates.yml +++ b/templates/job-templates.yml @@ -33,6 +33,7 @@ spec: # Images image_registry_base: default: '$CI_REGISTRY/components/opentofu' + description: 'Host URI to the job images. Will be combined with `image_name` to construct the actual image URI.' # 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. @@ -41,6 +42,10 @@ spec: # default: '$CI_REGISTRY/components/opentofu/gitlab-opentofu:$[[ inputs.version ]]-opentofu$[[ inputs.opentofu_version ]]' # description: 'Tag of the gitlab-opentofu image.' + image_name: + default: 'gitlab-opentofu' + description: 'Image name for the job images. Hosted under `image_registry_base`.' + # Configuration job_name_prefix: default: '.opentofu:' @@ -68,6 +73,7 @@ include: version: $[[ inputs.version ]] opentofu_version: $[[ inputs.opentofu_version ]] image_registry_base: $[[ inputs.image_registry_base ]] + image_name: $[[ inputs.image_name ]] root_dir: $[[ inputs.root_dir ]] - local: '/templates/validate.yml' inputs: @@ -76,6 +82,7 @@ include: version: $[[ inputs.version ]] opentofu_version: $[[ inputs.opentofu_version ]] image_registry_base: $[[ inputs.image_registry_base ]] + image_name: $[[ inputs.image_name ]] root_dir: $[[ inputs.root_dir ]] state_name: $[[ inputs.state_name ]] - local: '/templates/plan.yml' @@ -85,6 +92,7 @@ include: version: $[[ inputs.version ]] opentofu_version: $[[ inputs.opentofu_version ]] image_registry_base: $[[ inputs.image_registry_base ]] + image_name: $[[ inputs.image_name ]] root_dir: $[[ inputs.root_dir ]] state_name: $[[ inputs.state_name ]] - local: '/templates/apply.yml' @@ -94,6 +102,7 @@ include: version: $[[ inputs.version ]] opentofu_version: $[[ inputs.opentofu_version ]] image_registry_base: $[[ inputs.image_registry_base ]] + image_name: $[[ inputs.image_name ]] root_dir: $[[ inputs.root_dir ]] state_name: $[[ inputs.state_name ]] auto_apply: $[[ inputs.auto_apply ]] @@ -104,6 +113,7 @@ include: version: $[[ inputs.version ]] opentofu_version: $[[ inputs.opentofu_version ]] image_registry_base: $[[ inputs.image_registry_base ]] + image_name: $[[ inputs.image_name ]] root_dir: $[[ inputs.root_dir ]] state_name: $[[ inputs.state_name ]] auto_destroy: $[[ inputs.auto_destroy ]] diff --git a/templates/plan.yml b/templates/plan.yml index 0e3e413812bc5c6cf15afb0f148a9b779316bd62..5f8aea337ebcc3b65eeddf1a5736e166bc14a2b3 100644 --- a/templates/plan.yml +++ b/templates/plan.yml @@ -27,6 +27,7 @@ spec: # Images image_registry_base: default: '$CI_REGISTRY/components/opentofu' + description: 'Host URI to the job images. Will be combined with `image_name` to construct the actual image URI.' # 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. @@ -35,6 +36,10 @@ spec: # default: '$CI_REGISTRY/components/opentofu/gitlab-opentofu:$[[ inputs.version ]]-opentofu$[[ inputs.opentofu_version ]]' # description: 'Tag of the gitlab-opentofu image.' + image_name: + default: 'gitlab-opentofu' + description: 'Image name for the job images. Hosted under `image_registry_base`.' + # Configuration root_dir: default: ${CI_PROJECT_DIR} @@ -78,7 +83,7 @@ spec: TF_ROOT: $[[ inputs.root_dir ]] TF_STATE_NAME: $[[ inputs.state_name ]] image: - name: '$[[ inputs.image_registry_base ]]/gitlab-opentofu:$[[ inputs.version ]]-opentofu$[[ inputs.opentofu_version ]]' + name: '$[[ inputs.image_registry_base ]]/$[[ inputs.image_name ]]:$[[ inputs.version ]]-opentofu$[[ inputs.opentofu_version ]]' script: - gitlab-tofu plan - gitlab-tofu plan-json diff --git a/templates/validate-plan-apply.yml b/templates/validate-plan-apply.yml index 7a2c735dbb9e797a6e95ea876c2c05e9ba1a5e9c..f37014ce7a418686e9ec34e1f49aef2421b65646 100644 --- a/templates/validate-plan-apply.yml +++ b/templates/validate-plan-apply.yml @@ -30,6 +30,7 @@ spec: # Images image_registry_base: default: '$CI_REGISTRY/components/opentofu' + description: 'Host URI to the job images. Will be combined with `image_name` to construct the actual image URI.' # 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. @@ -38,6 +39,10 @@ spec: # default: '$CI_REGISTRY/components/opentofu/gitlab-opentofu:$[[ inputs.version ]]-opentofu$[[ inputs.opentofu_version ]]' # description: 'Tag of the gitlab-opentofu image.' + image_name: + default: 'gitlab-opentofu' + description: 'Image name for the job images. Hosted under `image_registry_base`.' + # Configuration root_dir: default: ${CI_PROJECT_DIR} @@ -59,6 +64,7 @@ include: version: $[[ inputs.version ]] opentofu_version: $[[ inputs.opentofu_version ]] image_registry_base: $[[ inputs.image_registry_base ]] + image_name: $[[ inputs.image_name ]] root_dir: $[[ inputs.root_dir ]] - local: '/templates/validate.yml' inputs: @@ -67,6 +73,7 @@ include: version: $[[ inputs.version ]] opentofu_version: $[[ inputs.opentofu_version ]] image_registry_base: $[[ inputs.image_registry_base ]] + image_name: $[[ inputs.image_name ]] root_dir: $[[ inputs.root_dir ]] state_name: $[[ inputs.state_name ]] - local: '/templates/plan.yml' @@ -76,6 +83,7 @@ include: version: $[[ inputs.version ]] opentofu_version: $[[ inputs.opentofu_version ]] image_registry_base: $[[ inputs.image_registry_base ]] + image_name: $[[ inputs.image_name ]] root_dir: $[[ inputs.root_dir ]] state_name: $[[ inputs.state_name ]] - local: '/templates/apply.yml' @@ -85,6 +93,7 @@ include: version: $[[ inputs.version ]] opentofu_version: $[[ inputs.opentofu_version ]] image_registry_base: $[[ inputs.image_registry_base ]] + image_name: $[[ inputs.image_name ]] root_dir: $[[ inputs.root_dir ]] state_name: $[[ inputs.state_name ]] auto_apply: $[[ inputs.auto_apply ]] diff --git a/templates/validate-plan.yml b/templates/validate-plan.yml index 5d9560bb0f436be9d7df6a9f5ede69fdfa11e182..d3274eb6b5f354e80390fbad22c273e1109e0b55 100644 --- a/templates/validate-plan.yml +++ b/templates/validate-plan.yml @@ -27,6 +27,7 @@ spec: # Images image_registry_base: default: '$CI_REGISTRY/components/opentofu' + description: 'Host URI to the job images. Will be combined with `image_name` to construct the actual image URI.' # 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. @@ -35,6 +36,10 @@ spec: # default: '$CI_REGISTRY/components/opentofu/gitlab-opentofu:$[[ inputs.version ]]-opentofu$[[ inputs.opentofu_version ]]' # description: 'Tag of the gitlab-opentofu image.' + image_name: + default: 'gitlab-opentofu' + description: 'Image name for the job images. Hosted under `image_registry_base`.' + # Configuration root_dir: default: ${CI_PROJECT_DIR} @@ -53,6 +58,7 @@ include: version: $[[ inputs.version ]] opentofu_version: $[[ inputs.opentofu_version ]] image_registry_base: $[[ inputs.image_registry_base ]] + image_name: $[[ inputs.image_name ]] root_dir: $[[ inputs.root_dir ]] - local: '/templates/validate.yml' inputs: @@ -61,6 +67,7 @@ include: version: $[[ inputs.version ]] opentofu_version: $[[ inputs.opentofu_version ]] image_registry_base: $[[ inputs.image_registry_base ]] + image_name: $[[ inputs.image_name ]] root_dir: $[[ inputs.root_dir ]] state_name: $[[ inputs.state_name ]] - local: '/templates/plan.yml' @@ -70,5 +77,6 @@ include: version: $[[ inputs.version ]] opentofu_version: $[[ inputs.opentofu_version ]] image_registry_base: $[[ inputs.image_registry_base ]] + image_name: $[[ inputs.image_name ]] root_dir: $[[ inputs.root_dir ]] state_name: $[[ inputs.state_name ]] diff --git a/templates/validate.yml b/templates/validate.yml index 0dc8e3d59fceb7688afb8492531678ad14d4f234..75558a861f2a4b37cc2a133689cd8c3abfb0207b 100644 --- a/templates/validate.yml +++ b/templates/validate.yml @@ -27,6 +27,7 @@ spec: # Images image_registry_base: default: '$CI_REGISTRY/components/opentofu' + description: 'Host URI to the job images. Will be combined with `image_name` to construct the actual image URI.' # 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. @@ -35,6 +36,10 @@ spec: # default: '$CI_REGISTRY/components/opentofu/gitlab-opentofu:$[[ inputs.version ]]-opentofu$[[ inputs.opentofu_version ]]' # description: 'Tag of the gitlab-opentofu image.' + image_name: + default: 'gitlab-opentofu' + description: 'Image name for the job images. Hosted under `image_registry_base`.' + # Configuration root_dir: default: ${CI_PROJECT_DIR} @@ -62,6 +67,6 @@ spec: TF_ROOT: $[[ inputs.root_dir ]] TF_STATE_NAME: $[[ inputs.state_name ]] image: - name: '$[[ inputs.image_registry_base ]]/gitlab-opentofu:$[[ inputs.version ]]-opentofu$[[ inputs.opentofu_version ]]' + name: '$[[ inputs.image_registry_base ]]/$[[ inputs.image_name ]]:$[[ inputs.version ]]-opentofu$[[ inputs.opentofu_version ]]' script: - gitlab-tofu validate