diff --git a/.mega-linter.yml b/.mega-linter.yml index 202985dbb3b4e06852a4e28e45b542b6488aa39f..4702c00255410df3de59410af0ff517a20211fbe 100644 --- a/.mega-linter.yml +++ b/.mega-linter.yml @@ -21,6 +21,8 @@ DISABLE: DISABLE_LINTERS: - JSON_V8R - YAML_PRETTIER + - REPOSITORY_CHECKOV + - TERRAFORM_TERRASCAN FLAVOR_SUGGESTIONS: false diff --git a/README-fr.md b/README-fr.md index 00a6488aead86d5875a73844cc6d7bc09a7e6e96..195e0e21f744cd733d03da336b24f2185053beea 100644 --- a/README-fr.md +++ b/README-fr.md @@ -68,6 +68,7 @@ Chaque fonctionnalité testée peut être activée avec une variable `MGCI_TEST_ | `MGCI_TEST_REGISTRY_GENERIC` | Lancement du test du registre de paquets génériques | `false` | | `MGCI_TEST_REGISTRY_CONTAINER` | Lancement du test du registre des conteneurs | `false` | | `MGCI_TEST_RUNNERS_TAGS` | Lancement du test des tags de runner | `false` | +| `MGCI_TEST_TERRAFORM_MODULE` | Lancement du test de module Terraform | `false` | | `MGCI_RUNNERS_TAGS` | Liste des Tags de runners à tester, format | `` | | `MGCI_API_TOKEN` | Token d'accès `Owner` au dépôt pour tester l'API | `` | | `MATTERMOST_URL` | URL de l'instance Mattermost à tester | `` | @@ -218,17 +219,17 @@ MGCI_TEST_CACHE_JOB_TAGS=cache - [x] Registre : purge des conteneurs - [x] Registre : générique - [x] Registre : NPM +- [x] Registre : Terraform module - [x] Proxy de dépendances - [x] Releases -- [X] Runners : tags attendus -- [X] Runners : enregistrement et suppression d'un runner +- [x] Runners : tags attendus +- [x] Runners : enregistrement et suppression d'un runner - [x] Health check (uniquement disponible pour une instance auto-hébergée) -- [X] Mattermost : Health check -- [X] Environnement : création et destruction +- [x] Mattermost : Health check +- [x] Environnement : création et destruction ### 🏗️ À venir -- [ ] [Terraform module](https://gitlab.com/froggit/tools/mgci/-/issues/16) - [ ] [Terraform state](https://gitlab.com/froggit/tools/mgci/-/issues/13) ## Test de l'API @@ -311,6 +312,12 @@ Si vous activez ce test, il faut également créer la variable `MATTERMOST_URL`, - **Nom des jobs** : `runners:register` - **Description** : le job `runners:register` teste la fonctionnalité d'enregistrement et de suppression d'un runner. Il va enregistrer un runner pour le projet avec le tag `test-runner` puis le supprimer tout de suite après. +## Test du module Terraform + +- **Nom du fichier** : `templates/terraform_module.yml` +- **Nom des jobs** : `terraform:module:upload` et `terraform:module:test` +-- **Description** : le job `terraform:module:upload` va téléverser notre module Terraform de test situé dans `src/terraform` vers le registre de modules Terraform de Gitlab. Dans un second temps, le job `terraform:module:test` va tester ce module. + ## Contribuer Ce projet étant sous la licence [GPL3](https://www.gnu.org/licenses/gpl.html), il est possible d'y contribuer pour y apporter des améliorations, des nouvelles fonctionnalités. diff --git a/README.md b/README.md index 762386d164ebf5331fee70c02725f9853fa0cea6..8158182ed00ee349ca784b4eed8a3a97fbfdab9a 100644 --- a/README.md +++ b/README.md @@ -68,6 +68,7 @@ Each tested feature can be activated with a `MGCI_TEST_` variable that | `MGCI_TEST_REGISTRY_GENERIC` | Run the generic packages registry test | `false` | | `MGCI_TEST_REGISTRY_CONTAINER` | Run the container registry test | `false` | | `MGCI_TEST_RUNNERS_TAGS` | Run the runner tags test | `false` | +| `MGCI_TEST_TERRAFORM_MODULE` | Run the Terraform module test | `false` | | `MGCI_RUNNERS_TAGS` | List of runner tags to test, format | `` | | `MGCI_API_TOKEN` | `Owner` access token to the repository for API testing | `` | | `MATTERMOST_URL` | URL of the Mattermost instance to test | `` | @@ -217,6 +218,7 @@ MGCI_TEST_CACHE_JOB_TAGS=cache - [x] Registry: Container cleanup - [x] Registry: Generic - [x] Registry: NPM +- [x] Registry: Terraform module - [x] Dependency proxy - [x] Releases - [x] Runners: expected tags @@ -227,7 +229,6 @@ MGCI_TEST_CACHE_JOB_TAGS=cache ### 🏗️ Upcoming -- [ ] [Terraform module](https://gitlab.com/froggit/tools/mgci/-/issues/16) - [ ] [Terraform state](https://gitlab.com/froggit/tools/mgci/-/issues/13) --- @@ -312,6 +313,12 @@ If you enable this test, you also need to create the `MATTERMOST_URL` variable, - **Job names**: `runners:register` - **Description**: the `runners:register` job tests the functionality of registering and deleting a runner. It will register a runner for the project with the `test-runner` tag and then delete it immediately after. +## Test du module Terraform + +- **File name** : `templates/terraform_module.yml` +- **Job names** : `terraform:module:upload` et `terraform:module:test` +-- **Description** : the`terraform:module:upload` job uploads our Terraform test module located in `src/terraform` to the Gitlab Terraform module registry. Then, the `terraform:module:test` job tests that module. + ## Contributing This project is licensed under [GPL3](https://www.gnu.org/licenses/gpl.html), and contributions are welcome to bring improvements, new features, etc. diff --git a/includes-if/tags/terraform_module.yml b/includes-if/tags/terraform_module.yml new file mode 100644 index 0000000000000000000000000000000000000000..6454f66d3b6ba4e21e78bc401032239e1a16bce0 --- /dev/null +++ b/includes-if/tags/terraform_module.yml @@ -0,0 +1,3 @@ +--- +.terraform: + tags: [$MGCI_TEST_TERRAFORM_MODULE_MODULE_JOB_TAGS] diff --git a/src/terraform/main.tf b/src/terraform/main.tf new file mode 100644 index 0000000000000000000000000000000000000000..0514e4fac627b5cb624ee84a157d6901601af4a4 --- /dev/null +++ b/src/terraform/main.tf @@ -0,0 +1,10 @@ +terraform { + required_version = "= 1.10.5" +} + +resource "local_file" "file" { + content = var.text + filename = "${var.filename}.txt" + file_permission = "0644" + directory_permission = "0755" +} diff --git a/src/terraform/variables.tf b/src/terraform/variables.tf new file mode 100644 index 0000000000000000000000000000000000000000..84eb40e3941306af35c9368ef054bc5b2724f0d1 --- /dev/null +++ b/src/terraform/variables.tf @@ -0,0 +1,11 @@ +variable "filename" { + description = "The filename of the file to be created." + type = string + default = null +} + +variable "text" { + description = "The text contents of the file to be created." + type = string + default = null +} diff --git a/templates/bases/variables.yml b/templates/bases/variables.yml index 52e56cfb552353562e419eea702e9b1b304590b8..ca5a72f084f7ddc989d1b6a3c23cdc3b41e9c809 100644 --- a/templates/bases/variables.yml +++ b/templates/bases/variables.yml @@ -34,3 +34,4 @@ variables: MGCI_TEST_REGISTRY_NPM: "false" MGCI_TEST_REGISTRY_GENERIC: "false" MGCI_TEST_REGISTRY_CONTAINER: "false" + MGCI_TEST_TERRAFORM_MODULE: "false" diff --git a/templates/set_packages_version.yml b/templates/set_packages_version.yml index 4de293ecda109bc109cf9c337de1bb9bd0a7f0f7..d74a895aabf85b1b29dd329273b47e32995f60ae 100644 --- a/templates/set_packages_version.yml +++ b/templates/set_packages_version.yml @@ -13,3 +13,4 @@ packages:version: - if: $MGCI_TEST_RELEASE == "true" - if: $MGCI_TEST_REGISTRY_NPM == "true" - if: $MGCI_TEST_REGISTRY_GENERIC == "true" + - if: $MGCI_TEST_TERRAFORM_MODULE == "true" diff --git a/templates/terraform_module.yml b/templates/terraform_module.yml new file mode 100644 index 0000000000000000000000000000000000000000..8dfc152df9330abba2fd89c878ef476f61ce2be8 --- /dev/null +++ b/templates/terraform_module.yml @@ -0,0 +1,44 @@ +--- + +.terraform: + rules: + - if: $MGCI_TEST_TERRAFORM_MODULE == "true" && ($CI_COMMIT_BRANCH == $CI_DEFAULT_BRANCH || $CI_PROJECT_PATH == 'froggit/tools/mgci') + +terraform:module:upload: + extends: .terraform + stage: build + image: curlimages/curl:latest + variables: + TERRAFORM_MODULE_DIR: ${CI_PROJECT_DIR}/src/terraform + TERRAFORM_MODULE_NAME: mgci-test-terraform-module + TERRAFORM_MODULE_SYSTEM: local + TERRAFORM_MODULE_VERSION: ${PACKAGE_VERSION} + script: + - tar -cvzf ${TERRAFORM_MODULE_NAME}-${TERRAFORM_MODULE_SYSTEM}-${TERRAFORM_MODULE_VERSION}.tgz -C ${TERRAFORM_MODULE_DIR} --exclude=./.git . + - 'curl --header "JOB-TOKEN: ${CI_JOB_TOKEN}" --upload-file ${TERRAFORM_MODULE_NAME}-${TERRAFORM_MODULE_SYSTEM}-${TERRAFORM_MODULE_VERSION}.tgz ${CI_API_V4_URL}/projects/${CI_PROJECT_ID}/packages/terraform/modules/${TERRAFORM_MODULE_NAME}/${TERRAFORM_MODULE_SYSTEM}/${TERRAFORM_MODULE_VERSION}/file' + +terraform:module:test: + extends: .terraform + stage: test + needs: ["terraform:module:upload"] + image: + name: hashicorp/terraform:1.10.5 + entrypoint: [""] + before_script: + - cd ${CI_PROJECT_DIR}/test/terraform + - sed -i "s/gitlab\.com/${CI_SERVER_HOST}/g" main.tf + - sed -i "s/version = \".*\"/version = \"${PACKAGE_VERSION}\"/g" main.tf + variables: + FILENAME: test + TEXT: "Hello world" + script: + - terraform init + - terraform validate + - terraform fmt --check + - terraform apply -auto-approve -var="filename=${FILENAME}" -var="text=${TEXT}" + - cat ${FILENAME}.txt | grep "${TEXT}" + +include: + - local: 'includes-if/tags/terraform.yml' + rules: + - if: $MGCI_TEST_TERRAFORM_MODULE_JOB_TAGS diff --git a/test/terraform/main.tf b/test/terraform/main.tf new file mode 100644 index 0000000000000000000000000000000000000000..b844fc6c357943d9b718c863e142e5e211856fc2 --- /dev/null +++ b/test/terraform/main.tf @@ -0,0 +1,10 @@ +terraform { + required_version = "= 1.10.5" +} + +module "mgci-test-terraform-module" { + source = "gitlab.com/froggit/mgci-test-terraform-module/local" + version = "0.0.0" + filename = var.filename + text = var.text +} diff --git a/test/terraform/variables.tf b/test/terraform/variables.tf new file mode 100644 index 0000000000000000000000000000000000000000..84eb40e3941306af35c9368ef054bc5b2724f0d1 --- /dev/null +++ b/test/terraform/variables.tf @@ -0,0 +1,11 @@ +variable "filename" { + description = "The filename of the file to be created." + type = string + default = null +} + +variable "text" { + description = "The text contents of the file to be created." + type = string + default = null +}