include:
  - component: $CI_SERVER_FQDN/$CI_PROJECT_PATH/apply@$CI_COMMIT_SHA
    inputs:
      image_registry_base: $GITLAB_OPENTOFU_IMAGE_BASE
      version: $CI_COMMIT_SHA
      opentofu_version: $OPENTOFU_VERSION
      as: 'setup:apply'
      stage: setup
      root_dir: $TEST_TF_ROOT
      state_name: $TEST_TF_STATE_NAME
      no_plan: true
      auto_apply: true

  - component: $CI_SERVER_FQDN/$CI_PROJECT_PATH/validate-plan-destroy@$CI_COMMIT_SHA
    inputs:
      image_registry_base: $GITLAB_OPENTOFU_IMAGE_BASE
      version: $CI_COMMIT_SHA
      opentofu_version: $OPENTOFU_VERSION
      root_dir: $TEST_TF_ROOT
      state_name: $TEST_TF_STATE_NAME

stages: [setup, validate, build, cleanup]

# Required to run everything immediately, instead of manually.

'setup:apply':
  rules: [{when: always}]

fmt:
  rules: [{when: always}]

validate:
  rules: [{when: always}]

plan:
  rules: [{when: always}]

destroy:
  rules: [{when: always}]

delete-state:
  rules: [{when: always}]

