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

feat: add module-release component

parent a2d731da
No related branches found
No related tags found
No related merge requests found
spec:
inputs:
# Job and Stage name
as:
default: 'module-release'
description: 'Defines the name of this job.'
stage:
default: 'release'
description: 'Defines the stage that this job will belong to.'
root_dir:
default: ${CI_PROJECT_DIR}
description: 'Root directory for the OpenTofu module.'
module_name:
default: ${CI_PROJECT_NAME}
description: |
Name of the module that should be published.
Must comply with the naming restrictions of the module registry.
module_system:
default: local
description: |
System that this module can be used with.
e.g. 'local' or 'azurerm'
module_version:
description: |
Version of the module that should be published.
e.g. '0.1.0'
default: ${CI_COMMIT_TAG}
---
'$[[ inputs.as ]]':
stage: $[[ inputs.stage ]]
image: curlimages/curl:8.8.0
variables:
TAR_FILENAME: /tmp/${CI_PROJECT_NAME}-${CI_COMMIT_REF_NAME}.tgz
TF_ROOT: $[[ inputs.root_dir ]]
UPLOAD_URL:
${CI_API_V4_URL}/projects/${CI_PROJECT_ID}/packages/terraform/modules/$[[ inputs.module_name ]]/$[[ inputs.module_system ]]/$[[ inputs.module_version ]]/file
script:
- >-
tar -vczf "$TAR_FILENAME"
-C "$TF_ROOT"
--exclude=./.git
--exclude=./.terraform*
.
- >-
curl
--fail-with-body
--location
--header "JOB-TOKEN: ${CI_JOB_TOKEN}"
--upload-file "$TAR_FILENAME"
"$UPLOAD_URL"
variables:
MODULE_SYSTEM: local
MODULE_VERSION: 0.0.0-$CI_COMMIT_SHA
include:
- component: $CI_SERVER_FQDN/$CI_PROJECT_PATH/module-release@$CI_COMMIT_SHA
inputs:
root_dir: $TEST_TF_ROOT/modules/random-pet
module_system: $MODULE_SYSTEM
module_version: $MODULE_VERSION
stages: [release, destroy]
# Required to run everything immediately, instead of manually.
module-release:
rules: [{when: always}]
delete-module:
stage: destroy
image: curlimages/curl:latest
needs: [module-release]
rules: [{when: always}]
script:
- >-
PACKAGE_ID=$(
curl
--header "JOB-TOKEN: ${CI_JOB_TOKEN}"
--fail-with-body
"${CI_API_V4_URL}/projects/${CI_PROJECT_ID}/packages?package_type=terraform_module&package_version=${MODULE_VERSION}"
| sed -E 's/\[\{"id":"?([^,"]*)"?.*/\1/'
)
- echo deleting package $PACKAGE_ID
- >-
curl
--request DELETE
--header "JOB-TOKEN: ${CI_JOB_TOKEN}"
--fail-with-body
"${CI_API_V4_URL}/projects/${CI_PROJECT_ID}/packages/${PACKAGE_ID}"
...@@ -12,4 +12,5 @@ component: ...@@ -12,4 +12,5 @@ component:
- PIPELINE_NAME: [Defaults] - PIPELINE_NAME: [Defaults]
- PIPELINE_NAME: [JobTemplates] - PIPELINE_NAME: [JobTemplates]
- PIPELINE_NAME: [TestJob] - PIPELINE_NAME: [TestJob]
- PIPELINE_NAME: [ModuleRelease]
- PIPELINE_NAME: [Destroy] - PIPELINE_NAME: [Destroy]
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment