The Simplest Way to Make Rook and Terraform Work Like They Should

Published
Length
3 min read

Luis Felipe Dias

All posts

Rook and Terraform work together to build and manage Kubernetes storage clusters in production. Terraform sets up the base nodes and disks, while Rook runs Ceph inside Kubernetes. This pairing lets platform teams automate storage setup from start to finish. You can define cloud disks, cluster roles, and storage pools in one workflow. When teams run rook and terraform together, they avoid manual storage tasks. Every change goes through version control before it reaches the live cluster. How ro

Your coding agents run with your access.

Claude Code reaches prod with a developer's credentials, and approval prompts get clicked through. hoop.dev checks every query, masks sensitive data, and holds risky changes for a human.

Rook and Terraform work together to build and manage Kubernetes storage clusters in production. Terraform sets up the base nodes and disks, while Rook runs Ceph inside Kubernetes.

This pairing lets platform teams automate storage setup from start to finish. You can define cloud disks, cluster roles, and storage pools in one workflow. When teams run rook and terraform together, they avoid manual storage tasks. Every change goes through version control before it reaches the live cluster.

How rook and terraform share state and permissions

Terraform talks to the cloud API and the Kubernetes API during a run. It creates virtual machines, attaches raw block devices, and installs the Rook operator. Once the operator pods start, Rook takes over the raw disks. Rook formats the drives and builds the Ceph storage layer across the nodes.

To do this work, Terraform needs a strong Kubernetes service role. It must create namespaces, custom resource definitions, and role bindings for Rook. Rook then uses its own service accounts to watch the cluster state. It reads custom storage objects that Terraform applies to the Kubernetes API.

Data flows from your Terraform state file into the Kubernetes control plane. When an engineer updates a storage pool size, Terraform sends the new spec. The Kubernetes API stores that spec and alerts the Rook operator pod. Rook then talks to the Ceph daemons to adjust the storage pool.

Common failure modes in storage automation

Many teams hit trouble when Terraform tries to build everything in one step. Terraform might send Rook custom objects before the custom resource definitions exist. The Kubernetes API rejects the run because it does not know the object type. Teams fix this by splitting the operator install from the cluster setup.

Another big risk comes from broad tokens and shared service accounts. Teams often give the Terraform runner full cluster admin rights that never expire. If someone steals that token, they can wipe out all storage volumes. A bad state run can also delete active storage pools by mistake.

Terraform Security (tfsec, Checkov) + End-to-End Encryption: architecture patterns and best practices

Continue reading? Get the full guide.

Free. No spam. Unsubscribe anytime.

Unlogged changes cause drift between the live cluster and the state file. An engineer might log in to the cluster and fix a broken disk by hand. The next time Terraform runs, it overwrites that manual fix and breaks storage. Teams must track who runs commands against the Kubernetes API and Ceph tools.

Scoping roles and network paths for safer runs

You can prevent storage loss by scoping down the Terraform runner role. Give the runner permission to manage only the Rook namespace and its objects. Block the runner from deleting storage classes or persistent volume claims on its own. Require a human check before any destroy command runs against storage resources.

Lock down the network path between your automation runner and the cluster API. Do not expose the Kubernetes API server to the public internet. Route all Terraform plans and applies through a central point that logs every call. Tie every run to a specific user identity instead of a shared key.

You also need tight rules for the Rook toolbox pod during debug work. Engineers use this pod to check Ceph health and fix stuck placement groups. If you leave the toolbox open, anyone with pod rights can run raw storage commands. Gate these sessions by role and mask sensitive fields like emails or card numbers in output.

Govern statements and responses across databases and APIs

Good config and scoped roles are needed setup. They do not check single queries in flight or mask sensitive fields in returned rows. Across Postgres, MySQL, SQL Server, MongoDB, ClickHouse, Kubernetes APIs, SSH, and internal HTTP endpoints, hoop.dev runs beside each supported service as an open-source proxy, a sidecar for your database or API.

First, hoop.dev guardrails block banned queries before they run. Then hoop.dev data masking rewrites matched sensitive values in responses in memory. The audit trail records every statement and verdict per resource. Furthermore, hoop.dev holds SOC 2 Type II and is open source on GitHub.

Frequently asked questions

Should Terraform manage Rook custom resources directly?

Yes, but you should separate the operator setup from the storage cluster objects. Apply the operator and its custom resource definitions in an early stage first. Once the operator is ready, let a second stage apply the Ceph cluster and pool objects.

How do we stop Terraform from deleting live Rook storage pools?

Use lifecycle rules in your state setup to block destroy actions on storage objects. You should also scope the Kubernetes role so the runner cannot delete storage volumes. Always review the plan output before you approve any changes to production storage.

How should engineers run debug commands in the Rook toolbox?

Do not keep the toolbox pod running with open access for all cluster users. Grant short access tied to the engineer identity only when a storage alert fires. Log every command sent to the Ceph cluster so the team has a clear audit trail.

The query runs. The emails stay hidden.