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

Fix test

parent a1440f2c
No related branches found
No related tags found
No related merge requests found
spec: spec:
inputs: inputs:
# Stages
stage_validate: stage_validate:
default: 'validate' default: 'validate'
description: 'Defines the validate stage' description: 'Defines the validate stage'
...@@ -15,30 +16,45 @@ spec: ...@@ -15,30 +16,45 @@ spec:
stage_cleanup: stage_cleanup:
default: 'cleanup' default: 'cleanup'
description: 'Defines the cleanup stage' description: 'Defines the cleanup stage'
enable_destroy_job:
default: false # Versions
description: 'Weather the destroy job should be created' opentofu_version:
default: '1.6.0'
options:
- '1.6.0'
- '1.6.0-rc1'
description: 'Released version of upstream OpenTofu'
# Images
gitlab_opentofu_image:
default: '$CI_REGISTRY/components/opentofu/gitlab-opentofu-$[[ inputs.opentofu_version ]]'
description: 'Image name of the gitlab-opentofu image'
# Configuration
root_dir:
default: ${CI_PROJECT_DIR}
description: 'Root directory for the OpenTofu project'
state_name:
default: default
description: 'State name'
--- ---
.default: .default:
image: image:
name: "$CI_TEMPLATE_REGISTRY_HOST/gitlab-org/terraform-images/stable:latest" name: $[[ inputs.gitlab_opentofu_image ]]
cache: cache:
key: "${TF_ROOT}" key: "$[[ inputs.root_dir ]]"
paths: paths:
- ${TF_ROOT}/.terraform/ - $[[ inputs.root_dir ]]/.terraform/
variables:
TF_ROOT: ${CI_PROJECT_DIR} # The relative path to the root directory of the Terraform project
TF_STATE_NAME: default # The name of the state file used by the GitLab Managed Terraform state backend
fmt: fmt:
extends: .default extends: .default
stage: $[[ inputs.stage_validate ]] stage: $[[ inputs.stage_validate ]]
needs: [] needs: []
script: script:
- gitlab-opentofu fmt - gitlab-tofu fmt
allow_failure: true allow_failure: true
rules: rules:
- if: $CI_PIPELINE_SOURCE == "merge_request_event" - if: $CI_PIPELINE_SOURCE == "merge_request_event"
...@@ -50,7 +66,7 @@ validate: ...@@ -50,7 +66,7 @@ validate:
extends: .default extends: .default
stage: $[[ inputs.stage_validate ]] stage: $[[ inputs.stage_validate ]]
script: script:
- gitlab-opentofu validate - gitlab-tofu validate
rules: rules:
- if: $CI_PIPELINE_SOURCE == "merge_request_event" - if: $CI_PIPELINE_SOURCE == "merge_request_event"
- if: $CI_OPEN_MERGE_REQUESTS # Don't add it to a *branch* pipeline if it's already in a merge request pipeline. - if: $CI_OPEN_MERGE_REQUESTS # Don't add it to a *branch* pipeline if it's already in a merge request pipeline.
...@@ -61,12 +77,12 @@ plan: ...@@ -61,12 +77,12 @@ plan:
extends: .default extends: .default
stage: $[[ inputs.stage_build ]] stage: $[[ inputs.stage_build ]]
script: script:
- gitlab-opentofu plan - gitlab-tofu plan
- gitlab-opentofu plan-json - gitlab-tofu plan-json
environment: environment:
name: ${TF_STATE_NAME} name: $[[ inputs.state_name ]]
action: prepare action: prepare
resource_group: ${TF_STATE_NAME} resource_group: $[[ inputs.state_name ]]
artifacts: artifacts:
# Terraform's cache files can include secrets which can be accidentally exposed. # Terraform's cache files can include secrets which can be accidentally exposed.
# Please exercise caution when utilizing secrets in your Terraform infrastructure and # Please exercise caution when utilizing secrets in your Terraform infrastructure and
...@@ -76,9 +92,9 @@ plan: ...@@ -76,9 +92,9 @@ plan:
# See: https://docs.gitlab.com/ee/ci/yaml/#artifactspublic # See: https://docs.gitlab.com/ee/ci/yaml/#artifactspublic
public: false public: false
paths: paths:
- ${TF_ROOT}/plan.cache - $[[ inputs.root_dir ]]/plan.cache
reports: reports:
terraform: ${TF_ROOT}/plan.json terraform: $[[ inputs.root_dir ]]/plan.json
rules: rules:
- if: $CI_PIPELINE_SOURCE == "merge_request_event" - if: $CI_PIPELINE_SOURCE == "merge_request_event"
- if: $CI_OPEN_MERGE_REQUESTS # Don't add it to a *branch* pipeline if it's already in a merge request pipeline. - if: $CI_OPEN_MERGE_REQUESTS # Don't add it to a *branch* pipeline if it's already in a merge request pipeline.
...@@ -89,11 +105,11 @@ apply: ...@@ -89,11 +105,11 @@ apply:
extends: .default extends: .default
stage: $[[ inputs.stage_deploy ]] stage: $[[ inputs.stage_deploy ]]
script: script:
- gitlab-opentofu apply - gitlab-tofu apply
environment: environment:
name: $TF_STATE_NAME name: $TF_STATE_NAME
action: start action: start
resource_group: ${TF_STATE_NAME} resource_group: $[[ inputs.state_name ]]
rules: rules:
- if: $CI_COMMIT_BRANCH == $CI_DEFAULT_BRANCH && $TF_AUTO_DEPLOY == "true" - if: $CI_COMMIT_BRANCH == $CI_DEFAULT_BRANCH && $TF_AUTO_DEPLOY == "true"
- if: $CI_COMMIT_BRANCH == $CI_DEFAULT_BRANCH - if: $CI_COMMIT_BRANCH == $CI_DEFAULT_BRANCH
...@@ -101,10 +117,8 @@ apply: ...@@ -101,10 +117,8 @@ apply:
destroy: destroy:
extends: .default extends: .default
stage: $[[ inputs.stage_destroy ]] stage: $[[ inputs.stage_cleanup ]]
script: script:
- gitlab-opentofu destroy - gitlab-tofu destroy
resource_group: ${TF_STATE_NAME} resource_group: $[[ inputs.state_name ]]
when: manual when: manual
rules:
- if: $[[ inputs.enable_destroy_job ]]
include: include:
- component: gitlab.com/$CI_PROJECT_PATH/full-pipeline@$CI_COMMIT_SHA - component: gitlab.com/$CI_PROJECT_PATH/full-pipeline@$CI_COMMIT_SHA
inputs:
gitlab_opentofu_image: $GITLAB_OPENTOFU_IMAGE_NAME
root_dir: $TF_ROOT
state_name: $TF_STATE_NAME
stages: [validate, test, build, deploy, cleanup]
# Required to run everything immediately, instead of manually.
apply:
rules: [{when: always}]
destroy:
rules: [{when: always}]
...@@ -4,9 +4,9 @@ component: ...@@ -4,9 +4,9 @@ component:
IMAGE: $OPENTOFU_IMAGE_NAME IMAGE: $OPENTOFU_IMAGE_NAME
OPENTOFU_VERSION: $STABLE_OPENTOFU_VERSION OPENTOFU_VERSION: $STABLE_OPENTOFU_VERSION
TF_STATE_NAME: ci-integration-$CI_PIPELINE_IID-$CI_NODE_INDEX TF_STATE_NAME: ci-integration-$CI_PIPELINE_IID-$CI_NODE_INDEX
TF_ROOT: tests TF_ROOT: tests/terraform
trigger: trigger:
include: tests/integration-test/$PIPELINE include: tests/integration-tests/$PIPELINE
strategy: depend strategy: depend
rules: rules:
- if: '$CI_PROJECT_PATH == "components/opentofu"' - if: '$CI_PROJECT_PATH == "components/opentofu"'
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment