Skip to content

feat(terraform): monolithic support - #75

Draft
MichaelThamm wants to merge 1 commit into
mainfrom
test/monolithic-option
Draft

feat(terraform): monolithic support#75
MichaelThamm wants to merge 1 commit into
mainfrom
test/monolithic-option

Conversation

@MichaelThamm

@MichaelThamm MichaelThamm commented May 27, 2026

Copy link
Copy Markdown
Contributor

Caution

Since we are making breaking changes:

  1. API changes are not that serious because we can gate that on releases
  2. juju_application reference changes are serious because this will replace the app. We need to either implement a move { } if we want the state to move. However, this is not too serious because our users use S3 storage backends anyways

Issue

Solution

Summary

Replaces the three hardcoded worker modules (mimir_backend, mimir_read, mimir_write) with a single module.mimir_worker using for_each over a var.workers map. This enables both microservices and monolithic deployment modes from the same module interface.

Motivation

  • Reduce duplication: all three worker modules were identical except for the role config key
  • Enable monolithic mode (role-all) with a single worker instead of three
  • Simplify the variable interface from ~15 per-role variables to one structured map

Usage

Microservices (default, same as before):

module "mimir" {
  source = "git::https://github.com/canonical/mimir-operators//terraform"
  # ...
  workers = {
    backend = { units = 3 }
    read    = { units = 2, storage_directives = { "data" = "10G" } }
    write   = { units = 2 }
  }
}

Monolithic (single worker with all roles):

module "mimir" {
  source = "git::https://github.com/canonical/mimir-operators//terraform"
  # ...
  workers = {
    all = { units = 3 }
  }
}

Breaking Changes

Before After
var.backend_name / var.read_name / var.write_name var.workers.<role>.app_name
var.backend_config / var.read_config / var.write_config var.workers.<role>.config
var.backend_units / var.read_units / var.write_units var.workers.<role>.units
var.backend_worker_storage_directives / etc. var.workers.<role>.storage_directives
var.worker_constraints var.workers.<role>.constraints
module.mimir_backend / module.mimir_read / module.mimir_write module.mimir_worker["backend"] / ["read"] / ["write"]
juju_integration.coordinator_to_backend / etc. juju_integration.coordinator_to_worker["backend"] / etc.

State migration: Existing deployments will need to recreate worker resources. The Terraform state addresses change due to the for_each refactor.

Validations

  • Worker map keys restricted to ["all", "backend", "read", "write"]
  • "all" cannot coexist with other role keys
  • Per-worker units must be >= 1
  • Anti-affinity (top-level bool) overrides per-worker constraints when enabled

Unchanged

  • Coordinator module, S3 integrator, and their variables remain the same
  • var.worker_resources and var.worker_revision remain top-level (shared across all workers)
  • provides/requires outputs unchanged
  • app_names output now dynamically includes whichever workers are deployed

Context

Testing Instructions

  • Add unit tests to assert features work

Upgrade Notes

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants