Files
homelab-v/tofu/state/README.md
T
KarteekandVegard Hagen f457ce825f feat: create GCS bucket to store remote state
feat: Add gcloud tofu code to automatically create gcs buckets to use as remote backend. Also setup workload identity federation, and store it to infisical, to use it in github actions.

Signed-off-by: Karteek <[email protected]>

feat(tofu): modularise gcs-state

Create a Google Cloud Storage (GCS) bucket and store the state for doing it in the bucket itself

Signed-off-by: Vegard Hagen <[email protected]>

feat(wif): enable workload identify federation

Signed-off-by: Vegard Hagen <[email protected]>
2025-07-19 18:54:05 +02:00

882 B

Google Cloud Storage

Example configuration for creating Google Cloud Storage bucket for storing an encrypted Tofu state in.

Prerequisites

Google Cloud Platform project with an active Billing Account.

Getting started

  1. Install gcloud — Instructions: https://cloud.google.com/sdk/docs/install-sdk
  2. Run gcloud init
  3. Authenticate using gcloud auth application-default login

Before initialising, disable the GCS backend in providers.tofu (by e.g. commenting it out) since we can't store the state in something that doesn't exist yet.

After the initial tofy apply to create the bucket, the state can be migrated by adding

backend "gcs" {
  bucket = var.bucket_name
  prefix = var.state_prefix
}

back in and running

tofu init -migrate-state

to migrate the state to the remote GCS bucket.