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

Merge branch 'var-file' into 'main'

Support var_file input in all templates

See merge request components/opentofu!160
parents 86fed257 e5efc717
No related branches found
No related tags found
No related merge requests found
...@@ -204,6 +204,11 @@ if [ $sourced -eq 0 ]; then ...@@ -204,6 +204,11 @@ if [ $sourced -eq 0 ]; then
# Authenticate to private registry # Authenticate to private registry
terraform_authenticate_private_registry terraform_authenticate_private_registry
var_file_args=""
if [ -n "${OPENTOFU_COMPONENT_VAR_FILE}" ]; then
var_file_args="--var-file=${OPENTOFU_COMPONENT_VAR_FILE}"
fi
case "${1}" in case "${1}" in
"apply") "apply")
auto_approve_args="" auto_approve_args=""
...@@ -215,7 +220,8 @@ if [ $sourced -eq 0 ]; then ...@@ -215,7 +220,8 @@ if [ $sourced -eq 0 ]; then
if [ "$TF_APPLY_NO_PLAN" = false ]; then if [ "$TF_APPLY_NO_PLAN" = false ]; then
tofu "${TF_CHDIR_OPT}" "${@}" -input=false "${auto_approve_args}" "${TF_PLAN_CACHE}" tofu "${TF_CHDIR_OPT}" "${@}" -input=false "${auto_approve_args}" "${TF_PLAN_CACHE}"
else else
tofu "${TF_CHDIR_OPT}" "${@}" -input=false "${auto_approve_args}" # shellcheck disable=SC2086
tofu "${TF_CHDIR_OPT}" "${@}" -input=false "${auto_approve_args}" ${var_file_args}
fi fi
;; ;;
"destroy") "destroy")
...@@ -232,7 +238,8 @@ if [ $sourced -eq 0 ]; then ...@@ -232,7 +238,8 @@ if [ $sourced -eq 0 ]; then
;; ;;
"plan") "plan")
$TF_IMPLICIT_INIT && terraform_init $TF_IMPLICIT_INIT && terraform_init
tofu "${TF_CHDIR_OPT}" "${@}" -input=false -out="${TF_PLAN_CACHE}" # shellcheck disable=SC2086
tofu "${TF_CHDIR_OPT}" "${@}" -input=false -out="${TF_PLAN_CACHE}" ${var_file_args}
;; ;;
"plan-json") "plan-json")
tofu "${TF_CHDIR_OPT}" show -json "${TF_PLAN_CACHE}" | \ tofu "${TF_CHDIR_OPT}" show -json "${TF_PLAN_CACHE}" | \
...@@ -241,15 +248,18 @@ if [ $sourced -eq 0 ]; then ...@@ -241,15 +248,18 @@ if [ $sourced -eq 0 ]; then
;; ;;
"validate") "validate")
$TF_IMPLICIT_INIT && terraform_init -backend=false $TF_IMPLICIT_INIT && terraform_init -backend=false
tofu "${TF_CHDIR_OPT}" "${@}" # shellcheck disable=SC2086
tofu "${TF_CHDIR_OPT}" "${@}" ${var_file_args}
;; ;;
"test") "test")
$TF_IMPLICIT_INIT && terraform_init -backend=false $TF_IMPLICIT_INIT && terraform_init -backend=false
tofu "${TF_CHDIR_OPT}" "${@}" # shellcheck disable=SC2086
tofu "${TF_CHDIR_OPT}" "${@}" ${var_file_args}
;; ;;
"graph") "graph")
$TF_IMPLICIT_INIT && terraform_init $TF_IMPLICIT_INIT && terraform_init
tofu "${TF_CHDIR_OPT}" "${@}" # shellcheck disable=SC2086
tofu "${TF_CHDIR_OPT}" "${@}" ${var_file_args}
;; ;;
--) --)
shift shift
......
...@@ -84,6 +84,10 @@ spec: ...@@ -84,6 +84,10 @@ spec:
default: false default: false
type: boolean type: boolean
description: 'Whether the apply job is manual or automatically run.' description: 'Whether the apply job is manual or automatically run.'
var_file:
default: ''
type: string
description: 'Path to a variables files relative to root_dir. Only used if no_plan is true otherwise the variables are coming from the plan.'
--- ---
...@@ -108,6 +112,7 @@ spec: ...@@ -108,6 +112,7 @@ spec:
TF_STATE_NAME: $[[ inputs.state_name ]] TF_STATE_NAME: $[[ inputs.state_name ]]
TF_APPLY_NO_PLAN: $[[ inputs.no_plan ]] TF_APPLY_NO_PLAN: $[[ inputs.no_plan ]]
TF_PLAN_NAME: $[[ inputs.plan_name ]] TF_PLAN_NAME: $[[ inputs.plan_name ]]
OPENTOFU_COMPONENT_VAR_FILE: '$[[ inputs.var_file ]]'
image: image:
name: '$[[ inputs.image_registry_base ]]/$[[ inputs.image_name ]]:$[[ inputs.version ]]-opentofu$[[ inputs.opentofu_version ]]-$[[ inputs.base_os ]]$[[ inputs.image_digest ]]$[[ inputs.image_digest ]]' name: '$[[ inputs.image_registry_base ]]/$[[ inputs.image_name ]]:$[[ inputs.version ]]-opentofu$[[ inputs.opentofu_version ]]-$[[ inputs.base_os ]]$[[ inputs.image_digest ]]$[[ inputs.image_digest ]]'
script: script:
......
...@@ -84,6 +84,10 @@ spec: ...@@ -84,6 +84,10 @@ spec:
default: false default: false
type: boolean type: boolean
description: 'Whether the destroy job is manual or automatically run.' description: 'Whether the destroy job is manual or automatically run.'
var_file:
default: ''
type: string
description: 'Path to a variables files relative to root_dir. Only used if no_plan is true otherwise the variables are coming from the plan.'
--- ---
...@@ -107,6 +111,7 @@ spec: ...@@ -107,6 +111,7 @@ spec:
TF_STATE_NAME: $[[ inputs.state_name ]] TF_STATE_NAME: $[[ inputs.state_name ]]
TF_APPLY_NO_PLAN: $[[ inputs.no_plan ]] TF_APPLY_NO_PLAN: $[[ inputs.no_plan ]]
TF_PLAN_NAME: $[[ inputs.plan_name ]] TF_PLAN_NAME: $[[ inputs.plan_name ]]
OPENTOFU_COMPONENT_VAR_FILE: '$[[ inputs.var_file ]]'
image: image:
name: '$[[ inputs.image_registry_base ]]/$[[ inputs.image_name ]]:$[[ inputs.version ]]-opentofu$[[ inputs.opentofu_version ]]-$[[ inputs.base_os ]]$[[ inputs.image_digest ]]' name: '$[[ inputs.image_registry_base ]]/$[[ inputs.image_name ]]:$[[ inputs.version ]]-opentofu$[[ inputs.opentofu_version ]]-$[[ inputs.base_os ]]$[[ inputs.image_digest ]]'
script: script:
......
...@@ -96,6 +96,10 @@ spec: ...@@ -96,6 +96,10 @@ spec:
plan_artifacts_access: plan_artifacts_access:
default: 'none' default: 'none'
description: 'Access level for the plan artifact. See https://docs.gitlab.com/ee/ci/yaml/#artifactsaccess for possible values.' description: 'Access level for the plan artifact. See https://docs.gitlab.com/ee/ci/yaml/#artifactsaccess for possible values.'
var_file:
default: ''
type: string
description: 'Path to a variables files relative to root_dir.'
--- ---
...@@ -123,6 +127,7 @@ include: ...@@ -123,6 +127,7 @@ include:
image_digest: $[[ inputs.image_digest ]] image_digest: $[[ inputs.image_digest ]]
root_dir: $[[ inputs.root_dir ]] root_dir: $[[ inputs.root_dir ]]
state_name: $[[ inputs.state_name ]] state_name: $[[ inputs.state_name ]]
var_file: $[[ inputs.var_file ]]
- local: '/templates/test.yml' - local: '/templates/test.yml'
inputs: inputs:
as: '$[[ inputs.job_name_prefix ]]test' as: '$[[ inputs.job_name_prefix ]]test'
...@@ -135,6 +140,7 @@ include: ...@@ -135,6 +140,7 @@ include:
image_digest: $[[ inputs.image_digest ]] image_digest: $[[ inputs.image_digest ]]
root_dir: $[[ inputs.root_dir ]] root_dir: $[[ inputs.root_dir ]]
state_name: $[[ inputs.state_name ]] state_name: $[[ inputs.state_name ]]
var_file: $[[ inputs.var_file ]]
rules: rules:
- exists: - exists:
- $[[ inputs.root_dir ]]/**/*.tftest.hcl - $[[ inputs.root_dir ]]/**/*.tftest.hcl
...@@ -151,6 +157,7 @@ include: ...@@ -151,6 +157,7 @@ include:
root_dir: $[[ inputs.root_dir ]] root_dir: $[[ inputs.root_dir ]]
state_name: $[[ inputs.state_name ]] state_name: $[[ inputs.state_name ]]
artifacts_access: $[[ inputs.plan_artifacts_access ]] artifacts_access: $[[ inputs.plan_artifacts_access ]]
var_file: $[[ inputs.var_file ]]
- local: '/templates/apply.yml' - local: '/templates/apply.yml'
inputs: inputs:
as: '$[[ inputs.job_name_prefix ]]apply' as: '$[[ inputs.job_name_prefix ]]apply'
...@@ -164,6 +171,7 @@ include: ...@@ -164,6 +171,7 @@ include:
root_dir: $[[ inputs.root_dir ]] root_dir: $[[ inputs.root_dir ]]
state_name: $[[ inputs.state_name ]] state_name: $[[ inputs.state_name ]]
auto_apply: $[[ inputs.auto_apply ]] auto_apply: $[[ inputs.auto_apply ]]
var_file: $[[ inputs.var_file ]]
- local: '/templates/destroy.yml' - local: '/templates/destroy.yml'
inputs: inputs:
as: '$[[ inputs.job_name_prefix ]]destroy' as: '$[[ inputs.job_name_prefix ]]destroy'
...@@ -177,6 +185,7 @@ include: ...@@ -177,6 +185,7 @@ include:
root_dir: $[[ inputs.root_dir ]] root_dir: $[[ inputs.root_dir ]]
state_name: $[[ inputs.state_name ]] state_name: $[[ inputs.state_name ]]
auto_destroy: $[[ inputs.auto_destroy ]] auto_destroy: $[[ inputs.auto_destroy ]]
var_file: $[[ inputs.var_file ]]
- local: '/templates/delete-state.yml' - local: '/templates/delete-state.yml'
inputs: inputs:
as: '$[[ inputs.job_name_prefix ]]delete-state' as: '$[[ inputs.job_name_prefix ]]delete-state'
......
...@@ -78,6 +78,10 @@ spec: ...@@ -78,6 +78,10 @@ spec:
description: | description: |
Name of the graph file that should be generated. Name of the graph file that should be generated.
It will be uploaded as an artifact. It will be uploaded as an artifact.
var_file:
default: ''
type: string
description: 'Path to a variables files relative to root_dir.'
--- ---
...@@ -93,6 +97,7 @@ spec: ...@@ -93,6 +97,7 @@ spec:
__CACHE_KEY_HACK: "$[[ inputs.root_dir ]]" __CACHE_KEY_HACK: "$[[ inputs.root_dir ]]"
TF_ROOT: $[[ inputs.root_dir ]] TF_ROOT: $[[ inputs.root_dir ]]
TF_STATE_NAME: $[[ inputs.state_name ]] TF_STATE_NAME: $[[ inputs.state_name ]]
OPENTOFU_COMPONENT_VAR_FILE: '$[[ inputs.var_file ]]'
image: image:
name: '$[[ inputs.image_registry_base ]]/$[[ inputs.image_name ]]:$[[ inputs.version ]]-opentofu$[[ inputs.opentofu_version ]]-$[[ inputs.base_os ]]$[[ inputs.image_digest ]]' name: '$[[ inputs.image_registry_base ]]/$[[ inputs.image_name ]]:$[[ inputs.version ]]-opentofu$[[ inputs.opentofu_version ]]-$[[ inputs.base_os ]]$[[ inputs.image_digest ]]'
script: script:
......
...@@ -93,6 +93,10 @@ spec: ...@@ -93,6 +93,10 @@ spec:
default: false default: false
type: boolean type: boolean
description: 'Whether the destroy job is manual or automatically run.' description: 'Whether the destroy job is manual or automatically run.'
var_file:
default: ''
type: string
description: 'Path to a variables files relative to root_dir.'
--- ---
...@@ -120,6 +124,7 @@ include: ...@@ -120,6 +124,7 @@ include:
image_digest: $[[ inputs.image_digest ]] image_digest: $[[ inputs.image_digest ]]
root_dir: $[[ inputs.root_dir ]] root_dir: $[[ inputs.root_dir ]]
state_name: $[[ inputs.state_name ]] state_name: $[[ inputs.state_name ]]
var_file: $[[ inputs.var_file ]]
- local: '/templates/graph.yml' - local: '/templates/graph.yml'
inputs: inputs:
as: '$[[ inputs.job_name_prefix ]]graph' as: '$[[ inputs.job_name_prefix ]]graph'
...@@ -130,6 +135,7 @@ include: ...@@ -130,6 +135,7 @@ include:
image_registry_base: $[[ inputs.image_registry_base ]] image_registry_base: $[[ inputs.image_registry_base ]]
image_name: $[[ inputs.image_name ]] image_name: $[[ inputs.image_name ]]
root_dir: $[[ inputs.root_dir ]] root_dir: $[[ inputs.root_dir ]]
var_file: $[[ inputs.var_file ]]
- local: '/templates/test.yml' - local: '/templates/test.yml'
inputs: inputs:
as: '$[[ inputs.job_name_prefix ]]test' as: '$[[ inputs.job_name_prefix ]]test'
...@@ -142,6 +148,7 @@ include: ...@@ -142,6 +148,7 @@ include:
image_digest: $[[ inputs.image_digest ]] image_digest: $[[ inputs.image_digest ]]
root_dir: $[[ inputs.root_dir ]] root_dir: $[[ inputs.root_dir ]]
state_name: $[[ inputs.state_name ]] state_name: $[[ inputs.state_name ]]
var_file: $[[ inputs.var_file ]]
- local: '/templates/plan.yml' - local: '/templates/plan.yml'
inputs: inputs:
as: '$[[ inputs.job_name_prefix ]]plan' as: '$[[ inputs.job_name_prefix ]]plan'
...@@ -154,6 +161,7 @@ include: ...@@ -154,6 +161,7 @@ include:
image_digest: $[[ inputs.image_digest ]] image_digest: $[[ inputs.image_digest ]]
root_dir: $[[ inputs.root_dir ]] root_dir: $[[ inputs.root_dir ]]
state_name: $[[ inputs.state_name ]] state_name: $[[ inputs.state_name ]]
var_file: $[[ inputs.var_file ]]
- local: '/templates/apply.yml' - local: '/templates/apply.yml'
inputs: inputs:
as: '$[[ inputs.job_name_prefix ]]apply' as: '$[[ inputs.job_name_prefix ]]apply'
...@@ -167,6 +175,7 @@ include: ...@@ -167,6 +175,7 @@ include:
root_dir: $[[ inputs.root_dir ]] root_dir: $[[ inputs.root_dir ]]
state_name: $[[ inputs.state_name ]] state_name: $[[ inputs.state_name ]]
auto_apply: $[[ inputs.auto_apply ]] auto_apply: $[[ inputs.auto_apply ]]
var_file: $[[ inputs.var_file ]]
- local: '/templates/destroy.yml' - local: '/templates/destroy.yml'
inputs: inputs:
as: '$[[ inputs.job_name_prefix ]]destroy' as: '$[[ inputs.job_name_prefix ]]destroy'
...@@ -180,6 +189,7 @@ include: ...@@ -180,6 +189,7 @@ include:
root_dir: $[[ inputs.root_dir ]] root_dir: $[[ inputs.root_dir ]]
state_name: $[[ inputs.state_name ]] state_name: $[[ inputs.state_name ]]
auto_destroy: $[[ inputs.auto_destroy ]] auto_destroy: $[[ inputs.auto_destroy ]]
var_file: $[[ inputs.var_file ]]
- local: '/templates/delete-state.yml' - local: '/templates/delete-state.yml'
inputs: inputs:
as: '$[[ inputs.job_name_prefix ]]delete-state' as: '$[[ inputs.job_name_prefix ]]delete-state'
......
...@@ -83,6 +83,10 @@ spec: ...@@ -83,6 +83,10 @@ spec:
artifacts_access: artifacts_access:
default: 'none' default: 'none'
description: 'Access level for the plan artifact. See https://docs.gitlab.com/ee/ci/yaml/#artifactsaccess for possible values.' description: 'Access level for the plan artifact. See https://docs.gitlab.com/ee/ci/yaml/#artifactsaccess for possible values.'
var_file:
default: ''
type: string
description: 'Path to a variables files relative to root_dir.'
--- ---
...@@ -117,6 +121,7 @@ spec: ...@@ -117,6 +121,7 @@ spec:
TF_ROOT: $[[ inputs.root_dir ]] TF_ROOT: $[[ inputs.root_dir ]]
TF_STATE_NAME: $[[ inputs.state_name ]] TF_STATE_NAME: $[[ inputs.state_name ]]
TF_PLAN_NAME: $[[ inputs.plan_name ]] TF_PLAN_NAME: $[[ inputs.plan_name ]]
OPENTOFU_COMPONENT_VAR_FILE: '$[[ inputs.var_file ]]'
image: image:
name: '$[[ inputs.image_registry_base ]]/$[[ inputs.image_name ]]:$[[ inputs.version ]]-opentofu$[[ inputs.opentofu_version ]]-$[[ inputs.base_os ]]$[[ inputs.image_digest ]]' name: '$[[ inputs.image_registry_base ]]/$[[ inputs.image_name ]]:$[[ inputs.version ]]-opentofu$[[ inputs.opentofu_version ]]-$[[ inputs.base_os ]]$[[ inputs.image_digest ]]'
script: script:
......
...@@ -73,6 +73,10 @@ spec: ...@@ -73,6 +73,10 @@ spec:
state_name: state_name:
default: default default: default
description: 'Remote OpenTofu state name.' description: 'Remote OpenTofu state name.'
var_file:
default: ''
type: string
description: 'Path to a variables files relative to root_dir.'
--- ---
...@@ -93,6 +97,7 @@ spec: ...@@ -93,6 +97,7 @@ spec:
__CACHE_KEY_HACK: "$[[ inputs.root_dir ]]" __CACHE_KEY_HACK: "$[[ inputs.root_dir ]]"
TF_ROOT: $[[ inputs.root_dir ]] TF_ROOT: $[[ inputs.root_dir ]]
TF_STATE_NAME: $[[ inputs.state_name ]] TF_STATE_NAME: $[[ inputs.state_name ]]
OPENTOFU_COMPONENT_VAR_FILE: '$[[ inputs.var_file ]]'
image: image:
name: '$[[ inputs.image_registry_base ]]/$[[ inputs.image_name ]]:$[[ inputs.version ]]-opentofu$[[ inputs.opentofu_version ]]-$[[ inputs.base_os ]]$[[ inputs.image_digest ]]' name: '$[[ inputs.image_registry_base ]]/$[[ inputs.image_name ]]:$[[ inputs.version ]]-opentofu$[[ inputs.opentofu_version ]]-$[[ inputs.base_os ]]$[[ inputs.image_digest ]]'
script: script:
......
...@@ -86,6 +86,10 @@ spec: ...@@ -86,6 +86,10 @@ spec:
plan_artifacts_access: plan_artifacts_access:
default: 'none' default: 'none'
description: 'Access level for the plan artifact. See https://docs.gitlab.com/ee/ci/yaml/#artifactsaccess for possible values.' description: 'Access level for the plan artifact. See https://docs.gitlab.com/ee/ci/yaml/#artifactsaccess for possible values.'
var_file:
default: ''
type: string
description: 'Path to a variables files relative to root_dir.'
--- ---
...@@ -113,6 +117,7 @@ include: ...@@ -113,6 +117,7 @@ include:
image_digest: $[[ inputs.image_digest ]] image_digest: $[[ inputs.image_digest ]]
root_dir: $[[ inputs.root_dir ]] root_dir: $[[ inputs.root_dir ]]
state_name: $[[ inputs.state_name ]] state_name: $[[ inputs.state_name ]]
var_file: $[[ inputs.var_file ]]
- local: '/templates/plan.yml' - local: '/templates/plan.yml'
inputs: inputs:
as: '$[[ inputs.job_name_prefix ]]plan' as: '$[[ inputs.job_name_prefix ]]plan'
...@@ -126,6 +131,7 @@ include: ...@@ -126,6 +131,7 @@ include:
root_dir: $[[ inputs.root_dir ]] root_dir: $[[ inputs.root_dir ]]
state_name: $[[ inputs.state_name ]] state_name: $[[ inputs.state_name ]]
artifacts_access: $[[ inputs.plan_artifacts_access ]] artifacts_access: $[[ inputs.plan_artifacts_access ]]
var_file: $[[ inputs.var_file ]]
- local: '/templates/apply.yml' - local: '/templates/apply.yml'
inputs: inputs:
as: '$[[ inputs.job_name_prefix ]]apply' as: '$[[ inputs.job_name_prefix ]]apply'
...@@ -139,3 +145,4 @@ include: ...@@ -139,3 +145,4 @@ include:
root_dir: $[[ inputs.root_dir ]] root_dir: $[[ inputs.root_dir ]]
state_name: $[[ inputs.state_name ]] state_name: $[[ inputs.state_name ]]
auto_apply: $[[ inputs.auto_apply ]] auto_apply: $[[ inputs.auto_apply ]]
var_file: $[[ inputs.var_file ]]
...@@ -89,6 +89,10 @@ spec: ...@@ -89,6 +89,10 @@ spec:
default: false default: false
type: boolean type: boolean
description: 'Whether the destroy job is manual or automatically run.' description: 'Whether the destroy job is manual or automatically run.'
var_file:
default: ''
type: string
description: 'Path to a variables files relative to root_dir.'
--- ---
...@@ -116,6 +120,7 @@ include: ...@@ -116,6 +120,7 @@ include:
image_digest: $[[ inputs.image_digest ]] image_digest: $[[ inputs.image_digest ]]
root_dir: $[[ inputs.root_dir ]] root_dir: $[[ inputs.root_dir ]]
state_name: $[[ inputs.state_name ]] state_name: $[[ inputs.state_name ]]
var_file: $[[ inputs.var_file ]]
- local: '/templates/plan.yml' - local: '/templates/plan.yml'
inputs: inputs:
as: '$[[ inputs.job_name_prefix ]]plan' as: '$[[ inputs.job_name_prefix ]]plan'
...@@ -131,6 +136,7 @@ include: ...@@ -131,6 +136,7 @@ include:
plan_name: $[[ inputs.plan_name ]] plan_name: $[[ inputs.plan_name ]]
artifacts_access: $[[ inputs.plan_artifacts_access ]] artifacts_access: $[[ inputs.plan_artifacts_access ]]
destroy: true destroy: true
var_file: $[[ inputs.var_file ]]
- local: '/templates/destroy.yml' - local: '/templates/destroy.yml'
inputs: inputs:
as: '$[[ inputs.job_name_prefix ]]destroy' as: '$[[ inputs.job_name_prefix ]]destroy'
...@@ -146,6 +152,7 @@ include: ...@@ -146,6 +152,7 @@ include:
no_plan: false no_plan: false
plan_name: $[[ inputs.plan_name ]] plan_name: $[[ inputs.plan_name ]]
auto_destroy: $[[ inputs.auto_destroy ]] auto_destroy: $[[ inputs.auto_destroy ]]
var_file: $[[ inputs.var_file ]]
- local: '/templates/delete-state.yml' - local: '/templates/delete-state.yml'
inputs: inputs:
as: '$[[ inputs.job_name_prefix ]]delete-state' as: '$[[ inputs.job_name_prefix ]]delete-state'
......
...@@ -79,6 +79,10 @@ spec: ...@@ -79,6 +79,10 @@ spec:
artifacts_access: artifacts_access:
default: 'none' default: 'none'
description: 'Access level for the plan artifact. See https://docs.gitlab.com/ee/ci/yaml/#artifactsaccess for possible values.' description: 'Access level for the plan artifact. See https://docs.gitlab.com/ee/ci/yaml/#artifactsaccess for possible values.'
var_file:
default: ''
type: string
description: 'Path to a variables files relative to root_dir.'
--- ---
...@@ -106,6 +110,7 @@ include: ...@@ -106,6 +110,7 @@ include:
image_digest: $[[ inputs.image_digest ]] image_digest: $[[ inputs.image_digest ]]
root_dir: $[[ inputs.root_dir ]] root_dir: $[[ inputs.root_dir ]]
state_name: $[[ inputs.state_name ]] state_name: $[[ inputs.state_name ]]
var_file: $[[ inputs.var_file ]]
- local: '/templates/plan.yml' - local: '/templates/plan.yml'
inputs: inputs:
as: '$[[ inputs.job_name_prefix ]]plan' as: '$[[ inputs.job_name_prefix ]]plan'
...@@ -119,3 +124,4 @@ include: ...@@ -119,3 +124,4 @@ include:
root_dir: $[[ inputs.root_dir ]] root_dir: $[[ inputs.root_dir ]]
state_name: $[[ inputs.state_name ]] state_name: $[[ inputs.state_name ]]
artifacts_access: $[[ inputs.artifacts_access ]] artifacts_access: $[[ inputs.artifacts_access ]]
var_file: $[[ inputs.var_file ]]
...@@ -73,6 +73,10 @@ spec: ...@@ -73,6 +73,10 @@ spec:
state_name: state_name:
default: default default: default
description: 'Remote OpenTofu state name.' description: 'Remote OpenTofu state name.'
var_file:
default: ''
type: string
description: 'Path to a variables files relative to root_dir.'
--- ---
...@@ -93,6 +97,7 @@ spec: ...@@ -93,6 +97,7 @@ spec:
TF_ROOT: $[[ inputs.root_dir ]] TF_ROOT: $[[ inputs.root_dir ]]
TF_STATE_NAME: $[[ inputs.state_name ]] TF_STATE_NAME: $[[ inputs.state_name ]]
TF_IGNORE_INIT_ERRORS: 'true' # Tofu can report errors which might be the reason init failed. TF_IGNORE_INIT_ERRORS: 'true' # Tofu can report errors which might be the reason init failed.
OPENTOFU_COMPONENT_VAR_FILE: '$[[ inputs.var_file ]]'
image: image:
name: '$[[ inputs.image_registry_base ]]/$[[ inputs.image_name ]]:$[[ inputs.version ]]-opentofu$[[ inputs.opentofu_version ]]-$[[ inputs.base_os ]]$[[ inputs.image_digest ]]' name: '$[[ inputs.image_registry_base ]]/$[[ inputs.image_name ]]:$[[ inputs.version ]]-opentofu$[[ inputs.opentofu_version ]]-$[[ inputs.base_os ]]$[[ inputs.image_digest ]]'
script: script:
......
...@@ -7,11 +7,20 @@ resource "local_file" "foo" { ...@@ -7,11 +7,20 @@ resource "local_file" "foo" {
filename = "${path.module}/foo.bar" filename = "${path.module}/foo.bar"
} }
variable "CI_PROJECT_NAME" { variable "ci_project_name" {
type = string type = string
default = "default" default = "default"
} }
variable "test_variable" {
type = string
default = "default value"
}
output "project_name" { output "project_name" {
value = var.CI_PROJECT_NAME value = var.ci_project_name
}
output "test_variable" {
value = var.test_variable
} }
test_variable = "varfile integration test"
include:
- component: $CI_SERVER_FQDN/$CI_PROJECT_PATH/full-pipeline@$CI_COMMIT_SHA
inputs:
image_registry_base: $GITLAB_OPENTOFU_IMAGE_BASE
version: $CI_COMMIT_SHA
base_os: $GITLAB_OPENTOFU_BASE_IMAGE_OS
opentofu_version: $OPENTOFU_VERSION
root_dir: $TEST_TF_ROOT
state_name: $TEST_TF_STATE_NAME
var_file: varfile.integration-test.tfvars
stages: [validate, test, build, deploy, cleanup]
# Required to run everything immediately, instead of manually.
fmt:
rules: [{when: always}]
validate:
rules: [{when: always}]
test:
rules: [{when: always}]
plan:
rules: [{when: always}]
apply:
rules: [{when: always}]
destroy:
rules: [{when: always}]
delete-state:
rules: [{when: always}]
...@@ -15,6 +15,7 @@ component: ...@@ -15,6 +15,7 @@ component:
- TestJob - TestJob
- ModuleRelease - ModuleRelease
- Destroy - Destroy
- VarFile
GITLAB_OPENTOFU_BASE_IMAGE_OS: GITLAB_OPENTOFU_BASE_IMAGE_OS:
- alpine - alpine
- debian - debian
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment