Consider Automatic State Storage Configuration

I think this should be part of the component by default, but at least in the documentation.

When using a third party maintained template, requiring changes to the .tf files causes the need to maintain and merge a fork of the original code (e.g. EKS Blueprints are "Product Managed" IaC from AWS).

The following code automates the backend state management nulling out the http value:

ensure_gitlab_state_storage:
  stage: .pre
  image: bash
  script:
    - |
      if [[ ! -f gitlabforstatestorage.tf ]]; then
        echo "No gitlabforstatestorage.tf detected, creating one to ensure the backend state storge is mapped to Gitlab..."
        cat << 'ENDOFFILEDATA' > gitlabforstatestorage.tf
      # GitLab's Open Tofu Component performs transparent, integrated state management with 
      # it's built-in feature: https://docs.gitlab.com/ee/user/infrastructure/iac/terraform_state.html
      # The following terrform code is required for GitLab state management to be used.
      terraform {
        backend "http" {
        }
      }
      ENDOFFILEDATA
      fi
  artifacts:
    paths:
      - gitlabforstatestorage.tf

cc: @timofurrer

Assignee Loading
Time tracking Loading