Skip to content
Beta

Rehost to STACKIT: Spring Boot with Terraform and Ansible

Last updated on

Stackit LogoStackit Logo
STACKIT

Rehost to STACKIT: Spring Boot with Terraform and Ansible

Rehost Spring Boot and PostgreSQL to a STACKIT VM with Terraform and Ansible: prepare inputs, provision, rehearse, cut over, validate, and hand over operations.

LIFT

Rehost Strategy

Use Discovery evidence to confirm that preserving the Spring Boot JAR, systemd service model, and PostgreSQL engine on a VM meets the migration goals; Kubernetes, Cloud Foundry, or PostgreSQL Flex would instead be Replatform. Derive the delivery sequence from that decision: Landing Zone, Terraform infrastructure, Ansible configuration, separate PostgreSQL migration, and the rehearsed runbook.

Design and mobilizeDesignRehost In 2 trails
R-strategy migration method Decision flow from discovery to production with the seven R-strategies: Relocate, Rehost, Replatform, Repurchase, Refactor, Retain, and Retire. R-strategy migration methodFrom discovery and path selection through the seven R-strategies to validation, transition, and production.DiscoveryDiscoveryAssess / prioritizeAssess / prioritizeDetermine migration pathDetermine migration pathValidationValidationTransitionTransitionProductionProductionRelocateRelocate(move VM)Define Landing ZoneDefine Landing ZoneUse migration toolsUse migration toolsAUTOMATEMANUALInstallInstallConfigConfigDeployDeployValidation & handoverRehostingRehosting(move application)Define Landing ZoneDefine Landing ZoneUse migration toolsUse migration toolsAUTOMATEMANUALInstallInstallConfigConfigDeployDeployReplatformingReplatforming(lift and reshape)Define Landing ZoneDefine Landing ZoneMap Target PlatformMap Target PlatformAdapt Platform StackAdapt Platform StackRepurchasingRepurchasing(replace, drop and shop)Purchase COTS/SaaS and licensingPurchase COTS/SaaS and licensingMigrate business processMigrate business processRefactoringRefactoring(re-architecting applications)Redesign application/ infrastructure architectureRedesign application/ infrastructure architectureApp code developmentApp code developmentFull ALM/SDLCFull ALM/SDLCIntegrationIntegrationRetain/moveRetain/movekeep for now or move laterRetire/decommissionRetire/decommissionLanding zone foundationLanding zone foundationShared platform base for all paths
R-strategy method with Rehost as the application-level lift-and-shift path

Rehost (lift-and-shift) migrates workloads with minimal application change. It is primarily a run strategy to reduce transition risk and accelerate migration throughput.

In practical terms, Rehost is application-wave oriented: each workload gets a defined target runtime mapping, cutover path, and runbook package for repeatable factory delivery.

OPS

Target Architecture

InternetApplication ProjectPublic IPUbuntu VMObservabilityBackup ArchiveSpring Boot JAR + systemdSelf-managed PostgreSQLNode exporter restricted HTTP/SSHlocalhost SQLrestricted scrapeboot-volume backup
BASE

Prepare the Workspace

Use an isolated Linux lab with Git, Terraform, Ansible, ShellCheck, SSH/SCP, curl, jq, and PostgreSQL server/client tools including pg_config. The sample dump scripts use runuser and the local postgres OS account and require root privileges in that lab. When Server Backup is enabled, the cutover workflow also needs an authenticated STACKIT CLI. Use the Terraform version that created an existing saved plan; plan files are version-specific.

Start in a parent directory without an existing checkout of the same name. This revision contains the migration workflows and declarative Observability management. Its JAR is unchanged from the artifact pinned by the Replatform reference:

Terminal window
umask 077 &&
git clone https://github.com/stackitcloud/stackit-cmf-Rehost-springboot.git &&
git -C stackit-cmf-Rehost-springboot checkout --detach b9225eb35c64b9ef4761c208fadb9a2356431793 &&
test -f stackit-cmf-Rehost-springboot/scripts/run_cutover.sh &&
cd stackit-cmf-Rehost-springboot &&
printf '%s\n' "Workspace ready. Continue from this Rehost checkout." || {
printf '%s\n' "Preparation failed. Resolve the error before continuing." >&2
false
}

Run the following steps from that checkout only after preparation succeeds. Preserve an existing checkout, state and evidence rather than replacing them. Keep credentials, plans, state, dumps, inventory and evidence private and outside version control; do not enable shell tracing.

SAFE

Configure Private Target Inputs

Create the private variable file only when it does not already exist:

Terminal window
umask 077
test -e env.tfvars || cp env.tfvars.example env.tfvars
chmod 600 env.tfvars

Edit the file before planning. Configure the approved existing project or project-creation scope, service-account key path, SSH key pair, available image, availability zone, VM flavor and storage. Restrict SSH and application ingress to the source CIDRs actually observed on the target path. Verify the SSH host key through a trusted channel before migration scripts use strict host checking. Set SSH_KEY and SSH_USER for those scripts when they differ from ~/.ssh/id_rsa and ubuntu; keep them consistent with Terraform’s private_ssh_key_path and ssh_user.

Enable VM-local PostgreSQL, Observability and Server Backup for this walkthrough. For the initial runtime deployment, leave postgresql_restore_after_copy = false and the source dump path empty: provisioning must not import the source before rehearsal and cutover approval. Supply the database password through the approved secret mechanism as TF_VAR_postgresql_app_password and retain it securely for subsequent plans; do not put it in the variable file, shell history or documentation.

Confirm permissions, quota, cost approval and the private Terraform backend before initialization. This workflow assumes a prepared execution host, not a complete lab installation procedure.

SAFE

Prepare Source Evidence

Create a custom-format source dump and record its SHA-256 checksum, expected row count, and a workload-specific deterministic fingerprint. The repository includes a reproducible eight-row sample:

Terminal window
./scripts/create_source_dump.sh
./scripts/validate_source_dump.sh

The validation script restores into a separate local PostgreSQL cluster before the dump can enter a migration rehearsal. These scripts generate the bundled sample in temporary local clusters; they do not export a running application or the STACKIT VM. Use a fresh artifact directory and do not overwrite a dump already approved for migration. For a real source, export it under the agreed write-freeze procedure and record equivalent checksum, count and fingerprint evidence.

BASE

Provision the Target

Configure an existing STACKIT project or project creation, restrict SSH and application ingress to approved source CIDRs, and pass the database password through TF_VAR_postgresql_app_password rather than a variable file. Review a saved plan before apply.

Terminal window
terraform init &&
./scripts/check.sh &&
terraform plan -input=false -var-file=env.tfvars -out=tfplan

Stop if initialization, checks or planning fail. Review resource changes, target project, ingress, cost and the disabled initial restore before explicitly applying that saved plan:

Terminal window
terraform apply tfplan

Terraform runs Ansible after provisioning. A successful apply proves completion of that orchestration, not acceptance of migrated data. Check the runtime before beginning rehearsal:

Terminal window
./scripts/validate_deployment.sh
STEP

Rehearse and Approve

Run the rehearsal against a temporary database on the target VM:

Terminal window
./scripts/run_migration_rehearsal.sh

The rehearsal checks the source evidence, restores the dump, compares row count and fingerprint, and removes its temporary database without changing the production springmusic database.

  • Access readiness: SSH, deployment credentials, DB access, secrets access validated.
  • Baseline captured: Current versions, environment variables, ports, certificates, scheduled jobs documented.
  • Capacity validated: CPU, RAM, disk IOPS, and storage capacity on target VM confirmed.
  • Security controls ready: Firewall rules, IAM mapping, TLS cert chain, and logging in place.
  • Source evidence ready: Dump checksum, expected record count, and deterministic data fingerprint recorded.
  • Rollback readiness: Pre-restore dump path, expected original record count, authority, and deadline agreed.
LIVE

Cutover

End-to-End Migration Wave Flow Four sequential stages lead from wave approval through preparation and cutover to stabilization and handover. Every wave follows the same controlled factory flow. Secure scope and baseline, execute migration, prove acceptance, and hand over safely to operations. 1 APPROVE Scope and baseline Window, rollback, and ownership Freeze versions and dependencies 2 PREPARE Readiness and R-path Validate source and target Run playbook by archetype 3 CUT OVER Cutover and acceptance Route traffic to STACKIT safely Validate tech, function, operations 4 STABILIZE Learn and hand over Resolve findings in short loops Hand over to Optimize and Operate Traceable wave completion: accepted, stabilized, and fully handed over
Controlled migration wave from readiness through cutover, validation, and handover
  1. Create target app user and required filesystem layout.
  2. Install Java runtime and supporting OS packages.
  3. Deploy app artifact to target path.
  4. Configure service unit (systemd) and environment file.
  5. Install self-managed PostgreSQL, create the application role and database, and restrict access to localhost.
  6. Enable node exporter, Observability scraping, and the Server Backup schedule.
  1. Create a custom-format PostgreSQL dump without source ownership or privileges.
  2. Record and validate its checksum, expected row count, and deterministic fingerprint.
  3. Run ./scripts/run_migration_rehearsal.sh against a temporary target database.
  4. Confirm that rehearsal removed its temporary database and left the production target database unchanged.
  5. Verify the original target rollback dump in a separate temporary database.
  1. Freeze source writes and create the final approved dump.
  2. Run ./scripts/run_cutover.sh --confirm with the approved source evidence.
  3. Require the saved Terraform plan to change only the Ansible orchestration resource.
  4. Validate row count, fingerprint, ownership, application-role write behavior, services, and endpoint.
  5. Require a final Terraform no-op plan, record acceptance, and start stabilization watch.
LIVE

Run the Approved Cutover

Set the expected source evidence in env.tfvars:

enable_local_postgresql = true
postgresql_source_dump_local_path = "artifacts/source-postgresql.dump"
postgresql_restore_after_copy = true
postgresql_expected_album_count = 8
postgresql_expected_album_fingerprint = "<source-fingerprint>"

Then execute the explicit approval gate:

Terminal window
./scripts/run_cutover.sh --confirm

The script requires a fully available Server Backup no older than 24 hours, creates a saved Terraform plan that replaces only the Ansible orchestration resource, rejects unrelated infrastructure changes, applies the restore, validates data and runtime behavior, and requires a final no-op Terraform plan. Retries of the same source-dump hash preserve the original database rollback point.

SAFE

Validate or Roll Back

  • Technical health: Spring Boot, PostgreSQL, and node exporter active; local and approved public HTTP checks pass.
  • Functional checks: The application returns the migrated Spring Music records.
  • Data checks: Expected row count and fingerprint match; table ownership belongs to the application role.
  • Security checks: Runtime environment and rollback dump have root-only or database-owner-only permissions.
  • Operations checks: Observability scrape, Server Backup schedule, evidence files, and escalation ownership verified.
  • Critical functional failure: Core business flow unavailable after fix window.
  • Data integrity risk: Mismatch in critical records with no fast remediation.
  • Operational instability: Repeated restarts or unresolved severe alerts.
  1. Invoke the approved rollback decision before the deadline and preserve logs and evidence.
  2. Run ./scripts/rollback_postgresql.sh --confirm to stop Spring Boot and preserve the current target database.
  3. Restore the protected pre-cutover dump and validate the expected original row count.
  4. Restart Spring Boot and validate local and approved public reachability.
  5. Resume the agreed source or target operating state and publish the rollback evidence and decision.
SAFE

Verify Data and Runtime

Validation checks the source row count and fingerprint, table ownership, a transactionally rolled-back write as the application role, application reachability, services, and the protected rollback dump.

Terminal window
./scripts/validate_migration.sh
./scripts/validate_deployment.sh
./scripts/verify_rollback.sh

If an approved rollback trigger is met during the rollback window, preserve the current target database and restore the original pre-cutover dump:

Terminal window
./scripts/rollback_postgresql.sh --confirm
SAFE

Retain Apply and Acceptance Evidence

Every rehearsal, cutover, and rollback writes an evidence.env file below artifacts/evidence/<timestamp>-<mode>/. Accept a cutover only when the evidence records the expected checksum, row count, fingerprint, target VM, successful runtime validation, and final Terraform no-op.

Terminal window
./scripts/validate_migration.sh
./scripts/validate_deployment.sh
terraform plan -var-file=env.tfvars -detailed-exitcode

Use the same approved source path, restore flag, expected count and fingerprint as the completed cutover. Exit code 0 means no changes, 2 means changes are proposed, and 1 means an error. A plan alone is not proof of apply. The cutover workflow records status=passed and terraform_noop=true only after applying its saved plan and completing data and runtime validation.

GOAL

Stabilization

  • Artifacts delivered: Final config set, deployment manifest, validation evidence, rollback log.
  • Ownership transfer: Named on-call owner and escalation route confirmed.
  • Stabilization period: 24-72 hours with enhanced monitoring and daily status check.
  • Exit criteria: No critical alerts, stable key metrics, and business owner sign-off.

With enable_server_backup = true, Terraform enables STACKIT Server Backup and a daily schedule for the VM boot volume. The default retention is 14 days. Cutover requires a fully available backup no older than 24 hours. Backup creation and status were validated against the real target; an in-place Server Backup restore remains a disruptive disaster-recovery operation and must be rehearsed in a separate recovery environment.

The Server Backup complements the PostgreSQL pre-restore dump. It does not replace database-level consistency checks or the application rollback procedure.

GOAL

Optimization

Return from the concrete migration example to the Migration Framework. Start optimization only after stable cutover, use representative production telemetry, implement one controlled change at a time, and validate its effect on reliability, performance, and cost.

MigrateOptimizeOverview In 7 trails

Optimize starts when workloads run on STACKIT and real operating data is available. The module converts post-cutover observations into measurable improvements for performance, stability, and cost efficiency.

Optimize is not a one-time task. It is an iterative cycle that can overlap with early stabilization and post-cutover care.

Many right-sizing and tuning decisions are only reliable under real load patterns. After cutover, teams can use production telemetry to separate assumptions from actual behavior.

  1. Collect runtime evidence: utilization, latency, error rates, throughput, and cost drivers.
  2. Identify bottlenecks and waste patterns at workload, platform, and data layers.
  3. Prioritize actions by business impact, risk reduction, and FinOps effect.
  4. Implement tuning changes in controlled increments.
  5. Validate outcomes against SLO, reliability, and cost targets.
  6. Feed lessons learned into future migration waves and operating standards.
  • Rightsizing: Align compute, storage, and network capacity with actual demand profiles.
  • Performance tuning: Improve latency and throughput through configuration, scaling, and architecture adjustments.
  • Reliability hardening: Reduce incident frequency through better resilience, observability, and failure handling.
  • FinOps controls: Improve cost transparency, remove waste, and optimize run-rate efficiency.
OPS

Continue the Same Reference Implementation

This asset continues the same Spring Boot and PostgreSQL reference implementation used for provisioning, migration, cutover, and stabilization. It does not introduce another example or repository. The existing Terraform variables, Ansible configuration, Observability instance, and validation workflows remain the technical baseline for Optimize.

The Optimize extension answers one practical question: how to detect overprovisioning or underprovisioning and then change VM or storage capacity through a controlled IaC workflow.

Code & registry github.com STACKIT CMF Rehost Spring Boot repository Continue with the same Terraform and Ansible reference implementation used by the preceding Rehost migration steps. Open the repository Rehost implementation asset

Use the dashboard to review infrastructure saturation, application health, request behavior, and alert history together before changing VM capacity.

Grafana dashboard for Rehost Spring Boot observability and VM rightsizing decisions
SAFE

Decide the Storage Path

In Rehost scenarios, CPU and memory are only one side of rightsizing. Storage performance can also become the limiting factor.

  • When to investigate storage: elevated I/O wait, unstable latency under write-heavy load, or throughput saturation despite available CPU.
  • What to select: a storage service plan and performance class that matches the observed IOPS and throughput profile.
  • Guidance: Block Storage service plans

Select the performance class before provisioning

Section titled “Select the performance class before provisioning”

A Block Storage performance class defines the maximum IOPS and throughput available to the complete volume. Application, database, operating-system, and backup access share this performance envelope. Select the class from measured peak demand, latency requirements, backup activity, and explicit growth headroom before creating the volume.

From the STACKIT docsService plans › Currently available Service Plans (performance classes)Source updated 22.04.2026 · copied 22.10.2026

The following table lists currently available performance classes for the EU01 region:

IOPS - Input/Output Operations per second

Throughput - Throughput in Megabytes per second

Thus, the classes used can be distinguished in detail based on the naming. Example: “Block Storage Premium - Performance Class 2” corresponds to SSD hard disks with max. 1000 IOPS and max. 100 Mbyte/s throughput.

What is this?

This section is copied from the STACKIT docs automatically, several times a day. It cannot be changed here. Changes belong in the STACKIT docs.

For the Rehost baseline, the operating system, Spring Boot application, and PostgreSQL data share the boot volume. Changing its performance class therefore requires a controlled replacement target:

  1. Select the new class from observed IOPS, throughput, latency, and I/O-wait data.
  2. Verify backup and database-level rollback readiness.
  3. Provision the replacement VM and boot volume through IaC with the selected class.
  4. Reapply the Ansible configuration and restore or migrate the workload data.
  5. Validate application behavior, data integrity, storage latency, backup coverage, and cost before switching.

Use a separate data volume when storage capacity or performance must evolve independently from the VM lifecycle. To change its performance class, create a new volume in the required availability model with sufficient capacity, stop writes, migrate and verify the data, switch the attachment or mount, and retain the source volume until acceptance and rollback gates have passed.

Migrate data from Block Storage

Treat storage checks as part of the same Optimize loop and validate latency, error behavior, recovery, and cost impact after any change.

STACKIT LogoSTACKIT Logo
Rehost Spring Boot with Terraform and Ansible STACKIT · Runbook Open asset ↗

The Replatform reference reuses this repository’s pinned Spring Music JAR and sample-data generator. Its sample walkthrough therefore needs this checkout and validated dump artifacts, but not a newly provisioned Rehost VM. Do not create another VM solely to generate the local sample.

For an actual migration from the Rehost VM to SKE and PostgreSQL Flex, verify that the VM is currently healthy, freeze its application writes, export its real PostgreSQL database and qualify that export. A historical successful Rehost apply does not establish current reachability or make the local sample equivalent to live VM data. Source export, acceptance and source failback need their own approved procedure.

Trail historyAdded Oct 4, 2026LWUpdatedNo updates · 1 bar = 1 week i
Maintainer
LWLukas WeberrußHead of STACKIT Cloud Migration Framework · STACKITOwnerActive 12 of the last 12 weeks · 58 updatesSTACKITwww.linkedin.com/in/lukas-weberruß-a360b081Contributed in STACKIT