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

Merge branch 'cleanup' into 'main'

style: Remove trailing whitespace and use-less use of cat

See merge request components/opentofu!57
parents 551b462f 62d94da7
No related branches found
No related tags found
No related merge requests found
Showing with 46 additions and 46 deletions
......@@ -5,7 +5,7 @@ workflow:
- if: $CI_COMMIT_TAG
- if: $CI_COMMIT_REF_PROTECTED == "true"
include:
include:
- local: tests/unit.gitlab-ci.yml
rules:
- changes:
......@@ -29,7 +29,7 @@ include:
- if: $CI_COMMIT_TAG
# FIXME: we cannot make this work for all use cases because of the following:
# - cannot pass parallel.matrix to the component, thus we need to extend it
# - that leads to a problem that when this component is ruled out, the extended job fails,
# - that leads to a problem that when this component is ruled out, the extended job fails,
# because it doesn't have a script or trigger.
# Additionally, when this project is mirrored into another instance the component reference fails.
# This may be solved with https://gitlab.com/gitlab-org/gitlab/-/issues/434260#note_1776822074
......@@ -186,7 +186,7 @@ gitlab-opentofu-image:deploy:with-opentofu-version:
entrypoint: [""]
variables:
RELEASE_IMAGE_NAME: "$CI_REGISTRY_IMAGE/gitlab-opentofu"
# OCI image tags are not compatible with semver, specifically the build metadata part
# OCI image tags are not compatible with semver, specifically the build metadata part
# indicated with a `+` sign, see https://github.com/distribution/distribution/issues/1201
# We use a dash `-` here, instead of the `+`.
# This may be problematic, because it indicates a semver prerelease.
......@@ -259,13 +259,13 @@ create-release:
- if: $CI_COMMIT_TAG
before_script:
- apk add --update yq envsubst
script:
script:
- echo "Creating release $CI_COMMIT_TAG"
- AVAILABLE_OPENTOFU_VERSIONS=$(yq -r '.spec.inputs.opentofu_version.options | filter((. | test("\$.*")) == false) | .[] | "- [`" + . + "`](https://github.com/opentofu/opentofu/releases/tag/v" + . + ")"' templates/full-pipeline.yml)
- export AVAILABLE_OPENTOFU_VERSIONS
- 'AVAILABLE_IMAGES=$(cat image*.md | sort -r | tee images.md | sed -E "s/(\(digest: .*\))/\n - \1/")'
- export AVAILABLE_IMAGES
- cat .gitlab/release-notes.md.template | envsubst > release-notes.md
- envsubst < .gitlab/release-notes.md.template > release-notes.md
artifacts:
paths:
- images.md
......
# OpenTofu CI/CD Component
> 🚧 **NOTE** 🚧
>
>
> The `src/gitlab-tofu.sh` script is still merely a copy from [`gitlab-terraform`](https://gitlab.com/gitlab-org/terraform-images).
> Therefore, lots of things in this script and in the templates are still Terraform-related and haven't
> been changed to their OpenTofu equivalents.
> Have a look at the [Migrating from the Terraform CI/CD templates](#migrating-from-the-terraform-cicd-templates)
> Have a look at the [Migrating from the Terraform CI/CD templates](#migrating-from-the-terraform-cicd-templates)
section when migrating from Terraform CI/CD templates.
This project is home to the **OpenTofu CI/CD component** and it's related assets,
This project is home to the **OpenTofu CI/CD component** and it's related assets,
like the `gitlab-tofu` wrapper script and OCI images containing that script
together with an OpenTofu version.
......@@ -107,7 +107,7 @@ fmt:
### Opinionated Templates
This component repository also provides some templates that may often be used,
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.
......@@ -207,7 +207,7 @@ plan:
## Releases & Versioning
This project currently releases tagged commits.
This project currently releases tagged commits.
An overview of releases can be found on the [Releases page](https://gitlab.com/components/opentofu/-/releases)
and a Changelog can be found [here](CHANGELOG.md).
......@@ -221,7 +221,7 @@ The component release versions follow [Semantic Versioning 2.0.0](https://semver
This project releases multiple OCI image variants that can be used with the component.
The intention is that the images used in a component have the same version and or not mixed.
Due to the limitations described in https://gitlab.com/gitlab-org/gitlab/-/issues/438275
Due to the limitations described in https://gitlab.com/gitlab-org/gitlab/-/issues/438275
it's currently required to provide the component version in the `component` include field
and as the `version` input. Check out the [Usage](#Usage) section for examples.
......@@ -233,7 +233,7 @@ Each component release deploys the following images:
- `registry.gitlab.com/components/opentofu/gitlab-opentofu:<VERSION>`
- Includes the latest stable OpenTofu version at the time of releasing the component
In the above examples `<VERSION>` references the component version and `<OPENTOFU_VERSION>`
In the above examples `<VERSION>` references the component version and `<OPENTOFU_VERSION>`
an OpenTofu release, from [here](https://github.com/opentofu/opentofu/releases).
*Note: unfortunately, these image versions are not SemVer compatible,
......@@ -249,7 +249,7 @@ GitLab CI/CD components are not yet distributed and available on self-managed Gi
It's also not possible to just include CI/CD components across instance, thus an include like
`- component: gitlab.com/components/opentofu/full-pipeline@~latest` won't work from a
self-managed instance.
However, you could mirror this project from GitLab.com onto any self-managed instance using
However, you could mirror this project from GitLab.com onto any self-managed instance using
a [repository pull mirror](https://docs.gitlab.com/ee/user/project/repository/mirror/pull.html).
and then use the component as you would from GitLab.com, but change the domain, like so:
......
......@@ -11,7 +11,7 @@ include:
- component: gitlab.com/components/opentofu/full-pipeline@$CI_COMMIT_TAG
inputs:
# The version must currently be specified explicitly as an input,
# to find the correctly associated images. # This can be removed
# to find the correctly associated images. # This can be removed
# once https://gitlab.com/gitlab-org/gitlab/-/issues/438275 is solved.
version: $CI_COMMIT_TAG
opentofu_version: $LATEST_OPENTOFU_VERSION
......
......@@ -3,7 +3,7 @@
# Regex from https://semver.org/#is-there-a-suggested-regular-expression-regex-to-check-a-semver-string
SEMANTIC_VERSION_REGEX='^(0|[1-9]\d*)\.(0|[1-9]\d*)\.(0|[1-9]\d*)(?:-((?:0|[1-9]\d*|\d*[a-zA-Z-][0-9a-zA-Z-]*)(?:\.(?:0|[1-9]\d*|\d*[a-zA-Z-][0-9a-zA-Z-]*))*))?(?:\+([0-9a-zA-Z-]+(?:\.[0-9a-zA-Z-]+)*))?$'
match=$(cat - | perl -ne "print if /$SEMANTIC_VERSION_REGEX/")
match=$(perl -ne "print if /$SEMANTIC_VERSION_REGEX/")
if [ -z "$match" ]; then
echo "The given version doesn't match the semantic versioning format."
......
......@@ -4,7 +4,7 @@
# Script to fetch all Terraform States of a project,
# optionally filter states which are older than a given
# date time.
#
#
# The output is in CSV and contains a header line
# containing the names of the columns.
# You can easily store it as CSV using:
......@@ -12,14 +12,14 @@
# or stream it to another script, e.g. without the header line:
# `fetch-states.sh | sed -n '1d;p' | ...`
#
# The script is optimized to run in a GitLab pipeline
# The script is optimized to run in a GitLab pipeline
# and therefore uses environment variables which are
# defined there by default.
#
#
# It requires an additional `GITLAB_TOKEN` variable, which
# contains a valid GitLab token with permissions to read
# Terraform states.
#
#
if [ -z "$FETCH_OLDER_THAN" ]; then
FETCH_OLDER_THAN=$(date "+%Y-%m-%dT%H:%M:%SZ")
......
......@@ -4,15 +4,15 @@
# Script to remove the given Terraform States.
# The states are read from stdin in the format:
# `<state-name>,<last-updated-at>`
#
# The script is optimized to run in a GitLab pipeline
#
# The script is optimized to run in a GitLab pipeline
# and therefore uses environment variables which are
# defined there by default.
#
#
# It requires an additional `GITLAB_TOKEN` variable, which
# contains a valid GitLab token with permissions to delete
# Terraform states.
#
#
GITLAB_BASE_TF_ADDRESS="${CI_API_V4_URL}/projects/${CI_PROJECT_ID}/terraform/state"
......
......@@ -22,12 +22,12 @@ from the templates and the components pipeline defintion - at least in the featu
## Backports
The OpenTofu CI/CD component needs to be backported as OpenTofu CI/CD template,
The OpenTofu CI/CD component needs to be backported as OpenTofu CI/CD template,
because components are not yet properly supported in self-managed instances.
That is, they are not bundled and it's not possible to use a component across instances.
The OpenTofu CI/CD job and pipeline templates can be generated using `make backports`.
The output is generated into the `backports` folder.
The output is generated into the `backports` folder.
Please contribute those files only upon full manual inspection to the canonical GitLab repository.
## Releasing
......
......@@ -22,8 +22,8 @@ BACKPORTS_BASE_FILE := $(BACKPORTS_BASE_DIR)/Base.latest.gitlab-ci.yml
.PHONY: backports
# NOTE: this make target requires GNU sed and not the mac OS sed.
# Install it with `brew install gnu-sed` and follow the instructions in `brew info gnu-sed` to
# NOTE: this make target requires GNU sed and not the mac OS sed.
# Install it with `brew install gnu-sed` and follow the instructions in `brew info gnu-sed` to
# make it the standard `sed` binary (if you wish) or temporarily alias sed=gsed
backports:
@echo "Generating $(BACKPORTS_BASE_FILE) ..."
......@@ -35,7 +35,7 @@ backports:
@sed '1,/^---$$/d' templates/apply.yml | sed -e 's/$$\[\[ inputs.as \]\]/.opentofu:apply/' | sed -e 's/$$\[\[ inputs.stage \]\]/deploy/' | sed -e 's/$$\[\[ inputs.auto_apply \]\]/$$_TF_AUTO_APPLY/' >> $(BACKPORTS_BASE_FILE)
@sed '1,/^---$$/d' templates/destroy.yml | sed -e 's/$$\[\[ inputs.as \]\]/.opentofu:destroy/' | sed -e 's/$$\[\[ inputs.stage \]\]/cleanup/' | sed -e 's/$$\[\[ inputs.auto_destroy \]\]/$$_TF_AUTO_DESTROY/' | sed -e 's/$$\[\[ inputs.create_destroy_job \]\]/$$TF_CREATE_DESTROY_JOB/' >> $(BACKPORTS_BASE_FILE)
@sed '1,/^---$$/d' templates/delete-state.yml | sed -e 's/$$\[\[ inputs.as \]\]/.opentofu:delete-state/' | sed -e 's/$$\[\[ inputs.stage \]\]/cleanup/' | sed -e 's/$$\[\[ inputs.create_delete_state_job \]\]/$$TF_CREATE_DELETE_STATE_JOB/' >> $(BACKPORTS_BASE_FILE)
@# 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/'
......
......@@ -3,14 +3,14 @@
# OpenTofu CI/CD Component
> 🚧 **NOTE** 🚧
>
>
> The `src/gitlab-tofu.sh` script is still merely a copy from [`gitlab-terraform`](https://gitlab.com/gitlab-org/terraform-images).
> Therefore, lots of things in this script and in the templates are still Terraform-related and haven't
> been changed to their OpenTofu equivalents.
> Have a look at the [Migrating from the Terraform CI/CD templates](#migrating-from-the-terraform-cicd-templates)
> Have a look at the [Migrating from the Terraform CI/CD templates](#migrating-from-the-terraform-cicd-templates)
section when migrating from Terraform CI/CD templates.
This project is home to the **OpenTofu CI/CD component** and it's related assets,
This project is home to the **OpenTofu CI/CD component** and it's related assets,
like the `gitlab-tofu` wrapper script and OCI images containing that script
together with an OpenTofu version.
......@@ -109,7 +109,7 @@ fmt:
### Opinionated Templates
This component repository also provides some templates that may often be used,
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.
......@@ -230,7 +230,7 @@ plan:
## Releases & Versioning
This project currently releases tagged commits.
This project currently releases tagged commits.
An overview of releases can be found on the [Releases page](https://gitlab.com/components/opentofu/-/releases)
and a Changelog can be found [here](CHANGELOG.md).
......@@ -244,7 +244,7 @@ The component release versions follow [Semantic Versioning 2.0.0](https://semver
This project releases multiple OCI image variants that can be used with the component.
The intention is that the images used in a component have the same version and or not mixed.
Due to the limitations described in https://gitlab.com/gitlab-org/gitlab/-/issues/438275
Due to the limitations described in https://gitlab.com/gitlab-org/gitlab/-/issues/438275
it's currently required to provide the component version in the `component` include field
and as the `version` input. Check out the [Usage](#Usage) section for examples.
......@@ -256,7 +256,7 @@ Each component release deploys the following images:
- `registry.gitlab.com/components/opentofu/gitlab-opentofu:<VERSION>`
- Includes the latest stable OpenTofu version at the time of releasing the component
In the above examples `<VERSION>` references the component version and `<OPENTOFU_VERSION>`
In the above examples `<VERSION>` references the component version and `<OPENTOFU_VERSION>`
an OpenTofu release, from [here](https://github.com/opentofu/opentofu/releases).
*Note: unfortunately, these image versions are not SemVer compatible,
......@@ -272,7 +272,7 @@ GitLab CI/CD components are not yet distributed and available on self-managed Gi
It's also not possible to just include CI/CD components across instance, thus an include like
`- component: gitlab.com/components/opentofu/full-pipeline@~latest` won't work from a
self-managed instance.
However, you could mirror this project from GitLab.com onto any self-managed instance using
However, you could mirror this project from GitLab.com onto any self-managed instance using
a [repository pull mirror](https://docs.gitlab.com/ee/user/project/repository/mirror/pull.html).
and then use the component as you would from GitLab.com, but change the domain, like so:
......
......@@ -3,7 +3,7 @@ spec:
# Stages
stage_validate:
default: 'validate'
description: 'Defines the validate stage. This stage includes the `fmt` and `validate` jobs.'
description: 'Defines the validate stage. This stage includes the `fmt` and `validate` jobs.'
stage_test:
default: 'test'
description: 'Defines the test stage. This stage includes the `test` job.'
......@@ -99,7 +99,7 @@ include:
root_dir: $[[ inputs.root_dir ]]
state_name: $[[ inputs.state_name ]]
rules:
- exists:
- exists:
- $[[ inputs.root_dir ]]/**/*.tftest.hcl
- local: '/templates/plan.yml'
inputs:
......
......@@ -3,7 +3,7 @@ spec:
# Stages
stage_validate:
default: 'validate'
description: 'Defines the validate stage. This stage includes the `fmt` and `validate` jobs.'
description: 'Defines the validate stage. This stage includes the `fmt` and `validate` jobs.'
stage_test:
default: 'test'
description: 'Defines the test stage. This stage includes the `test` job.'
......
......@@ -3,7 +3,7 @@ spec:
# Stages
stage_validate:
default: 'validate'
description: 'Defines the validate stage. This stage includes the `fmt` and `validate` jobs.'
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.'
......
......@@ -3,7 +3,7 @@ spec:
# Stages
stage_validate:
default: 'validate'
description: 'Defines the validate stage. This stage includes the `fmt` and `validate` jobs.'
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.'
......
......@@ -17,7 +17,7 @@ plan:
extends: .opentofu:plan
rules: [{when: always}]
apply:
apply:
extends: .opentofu:apply
rules: [{when: always}]
......
......@@ -23,7 +23,7 @@ test:
plan:
rules: [{when: always}]
apply:
apply:
rules: [{when: always}]
destroy:
......
......@@ -132,7 +132,7 @@ gitlab-tofu-init-without-reconfigure:
- gitlab-tofu init -no-color >/tmp/output.txt 2>&1 || FAILED=true
- cat /tmp/output.txt
- test $FAILED = true
- 'cat /tmp/output.txt | grep "Error: Backend configuration changed"'
- 'grep "Error: Backend configuration changed" /tmp/output.txt'
gitlab-tofu-init-with-reconfigure:
extends:
......@@ -306,7 +306,7 @@ gitlab-tofu-without-implicit-init:
- gitlab-tofu $CMD -no-color >/tmp/output.txt 2>&1 || FAILED=true
- cat /tmp/output.txt
- test $FAILED = true
- 'cat /tmp/output.txt | grep "$ERROR"'
- 'grep "$ERROR" /tmp/output.txt'
parallel:
matrix:
- CMD: apply
......@@ -333,4 +333,4 @@ gitlab-tofu-no-wrapper:
- gitlab-tofu -- apply -no-color >/tmp/output.txt 2>&1 || FAILED=true
- cat /tmp/output.txt
- test $FAILED = true
- 'cat /tmp/output.txt | grep "Error: Backend initialization required, please run \"tofu init\""'
- 'grep "Error: Backend initialization required, please run \"tofu init\"" /tmp/output.txt'
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment