Provisioning Hyperswitch infrastructure with Terraform and Terragrunt

Use Terraform modules to build the cloud foundation for a self-hosted Hyperswitch stack, and Terragrunt to run sandbox, test and production from one codebase with separate state.

On this page

Provisioning Hyperswitch infrastructure with Terraform and Terragrunt: what it covers and when teams need it

Teams that must build the cloud foundation for self-hosted Hyperswitch in their own accounts need infrastructure as code before the Helm install. Provisioning covers the network, the Kubernetes cluster, PostgreSQL, Redis, workload identities and the encryption keys the stack depends on. Keeping these in code lets the team reproduce the same layout for sandbox, integration test and production, and review each change before it reaches a live account. Terragrunt sits on top of the Terraform configuration and runs several environments from one codebase, so shared settings live in one place and only per-environment inputs differ. Juspay publishes reference Terraform modules for this work. Treat them as a starting point that the team reviews line by line, and confirm which module version matches the Hyperswitch release you plan to run, because this page does not assume any particular version.

The work is worth doing in-house when the platform team will recreate environments repeatedly, when auditors will ask how production infrastructure is changed and approved, or when a second region or cloud account is planned. The main decisions come early. Choose the tool, either Terraform or OpenTofu, and check that your modules and providers work with it. OpenTofu describes itself as a drop-in replacement for Terraform under the Mozilla Public License 2.0, and it encrypts state and plan files with key providers such as AWS KMS or GCP KMS. Its own documentation does not guarantee compatibility with future Terraform releases, so record the version you pin. Set the state backend and its access policy at the same time, because state files hold resource identifiers and may hold credentials such as database passwords.

Cost has three parts. Cloud resources recur every month and grow with node count, database class and replica count. Engineering time is largely one-time, covering module review, adaptation to your network standards and the first clean apply. Ongoing maintenance recurs as modules and providers change. When you request a quote from a partner, ask for the written scope to name which modules are reused, which are changed, how state and keys are handled, and how environment promotion is tested. Confirm the Kubernetes and database versions that your Hyperswitch release expects in the self-hosting documentation before you fix the cluster and database arguments in code.

How the provisioning layers stack from network to Helm install

The flow starts in a Terragrunt environment folder, which supplies inputs to the reusable Terraform modules for network, cluster, databases, cache, identities and keys. Those modules sit inside the client's cloud account, and the trust boundary marks where client-owned infrastructure ends. The Helm install of the Hyperswitch stack comes last, consuming the endpoints, secrets and KMS key references the earlier layers produced. Check that each layer's outputs exist before the next layer applies.

Environment folders feed Terraform modules that build the layers beneath the Helm install.

Which Terraform and state options fit your team's setup

This table compares the main choices for provisioning Hyperswitch infrastructure: which IaC binary to run, how to lay out environments, and how to store state. Read each row against your team's existing tooling, audit expectations and number of environments. The main takeaway is that the layout and state decisions are harder to reverse than the binary choice, so settle them before the first apply.

OptionFits whenTrade-off
Terraform binaryYour team already runs Terraform with a HashiCorp licence arrangement, and existing pipelines, modules and state depend on it.Upgrades follow HashiCorp's release line. Confirm the licence terms that apply to your use before you standardize on it.
OpenTofu binaryYou want a drop-in, open-source CLI under the Mozilla Public License 2.0 and your configurations are already compatible.Future Terraform features are not guaranteed to reach OpenTofu. Pin the version and test provider and module upgrades in a sandbox first.
Single root module with workspaces or variable filesYou run one or two environments with a small team and want the simplest code path to review.Environments share code paths, so a change meant for test can reach production. Limit this to small footprints and guard production applies.
Terragrunt stacks, one directory per environmentYou run sandbox, integration and production with different accounts, sizes or network ranges and want one codebase.Terragrunt adds a wrapper layer, configuration inheritance and its own version to maintain. Staff it with someone who can debug it.
Remote state backend with encryptionYour state holds database credentials, key references or network detail that must be protected at rest and access-controlled.Encryption keys become a dependency. Losing access to the key provider can block applies, so document key custody and recovery.
Local or unencrypted stateOnly for a short-lived proof of concept on a laptop with no real secrets.State can contain sensitive values in plain form. This is not a production path and will fail most assessor questions about key and data handling.

Why OpenTofu is a reasonable engine for these modules, and what to verify

OpenTofu is a reasonable engine for these modules because it is a drop-in replacement for Terraform that aims to preserve existing workflows and configurations, and it is licensed under the Mozilla Public License 2.0. It is under the stewardship of the Linux Foundation and was accepted to the CNCF at the Sandbox maturity level on April 23, 2025. The project was created by a group including Gruntwork, Spacelift and Harness in response to HashiCorp's switch to the Business Source License, so the license terms are the main reason many teams consider it. The latest release cited for this page is v1.13.1, released October 1, 2026. Confirm the current release on the OpenTofu releases page before you pin a version.

The compatibility claim has a limit you must plan for. The OpenTofu FAQ aims for feature parity with Terraform, but it says the community decides which features OpenTofu adopts, so compatibility with future Terraform releases is not guaranteed. Pin the engine version in your repository and in your CI image, and treat every engine upgrade as a change that needs its own test run. Run plan against each environment after the upgrade and review any diff in the network, cluster and database resources before applying. Also check the providers and modules you depend on, since the OpenTofu Registry is a separate index from the Terraform Registry and not every module is guaranteed to behave the same way.

State encryption is the control to evaluate first. OpenTofu can encrypt state and plan files at rest for local storage and remote backends, with key providers that include AWS KMS and GCP KMS, as well as PBKDF2, OpenBao and Azure Vault. State for this stack holds database credentials, generated keys and endpoints, so confirm that encryption is enabled, that the key provider matches your cloud, and that the key policy limits decryption to the pipeline roles. Test recovery as well: losing access to the KMS key can make the state unreadable. Review the state and plan encryption documentation before choosing a key provider.

Setting up the Terragrunt layout and first apply, step by step

This sequence takes a team from an empty repository to a sandbox environment whose network, cluster, database, cache, identities and keys are provisioned, checked and ready for the Hyperswitch Helm install. Each step closes with a check you can record before moving on.

  1. Back up existing state and code

    If you are moving an existing Terraform codebase, copy the configuration and every state file before changing anything, and record the backend settings in use. Confirm that the backup restores into a scratch directory and that a plan against it shows no changes. If your configurations read outputs from other stacks through the terraform_remote_state data source, plan extra time for that case, since OpenTofu's migration guide flags it as needing additional care. A fresh build on an empty repository can skip the state copy, but the team should still confirm there is no legacy state in any shared backend.

  2. Install OpenTofu and Terragrunt at pinned versions

    Install OpenTofu, which the migration overview describes as a drop-in replacement for Terraform, and Terragrunt on the engineers' workstations and the CI runner. Pin both versions in the repository, for example in a tool version file, so every run uses the same binaries. Run the version command on each machine and confirm the output matches the pin. Because OpenTofu does not guarantee compatibility with future Terraform releases, record the chosen version in your change log.

  3. Create one directory per environment with remote state

    Lay out a root directory with a shared configuration file and one directory per environment, such as sandbox, integration and production, each holding a small Terragrunt file that points at a shared module. Give every environment its own state location so a change in one cannot lock or overwrite another. If you want state and plan files encrypted at rest, configure OpenTofu's state encryption with a key provider your security team approves, such as a cloud KMS. Confirm the layout by running an initialization in the sandbox directory and checking that the state object appears in the expected bucket or backend.

  4. Pin Juspay reference module versions

    Reference the Hyperswitch Terraform modules by an exact version or commit rather than a moving branch, and record the matching Hyperswitch chart and application versions in the same file. Review the module inputs for network ranges, cluster version, database sizing, cache size, identity roles and key settings, and write each value into the sandbox environment file. Confirm the pins by checking that a second clone of the repository resolves to the same module revision.

  5. Review the plan across network, cluster and data layers

    Run a plan for the sandbox and read it in dependency order: network first, then the Kubernetes cluster and node groups, then the PostgreSQL instance, the Redis cache, the workload identities and the key resources. Check that subnets span the zones you intend, that no database or cache is planned with public access, and that identity permissions grant only what the module documents. Save the plan file and attach it to the change record. The step is complete when every resource you expected appears and nothing is marked for destruction without a reason you can name.

  6. Confirm state locking before the first apply

    Before applying, test that the state backend locks. Start a plan in one terminal, then attempt a second plan against the same environment from another session and confirm the second run waits or fails with a lock message. Release the lock and confirm the first run completes. A team that skips this check can corrupt state during parallel CI and manual runs, so record the result in the runbook. Confirm that only the CI service identity and a named break-glass role can force-unlock.

  7. Apply to sandbox and capture outputs

    Apply the saved plan to the sandbox environment only. Capture the outputs the Helm install needs, such as the cluster endpoint, database host, cache endpoint, service account bindings and key identifiers, and store them in a secure location, not in the repository. Confirm the apply finished without errors and that a follow-up plan reports no changes, which shows the state matches the code.

  8. Verify connectivity and outputs before the Helm install

    From a bastion or CI runner inside the network, confirm the Kubernetes API responds with the expected credentials, the database accepts a connection on the configured port with TLS if your policy requires it, and the cache answers a ping. Check that each output value matches the resource it names. Only when these checks pass should the team move to the Helm chart, because a failure in networking or identity is far cheaper to fix now than after the application pods are running.

Security controls to design into the Terraform code

These controls sit in the Terraform and Terragrunt code itself, so they are reviewed like any other change. Together they decide how much of the Hyperswitch stack, and which data, falls inside the PCI DSS scope your team has chosen. Confirm each one against that scope decision before the first environment is applied.

State file protection and encryption

The Terraform state holds resource attributes, including database endpoints and sometimes generated secrets, so it needs the same protection as the infrastructure it describes. Use a remote backend with encryption at rest, restricted access and versioning, and enable OpenTofu state encryption with a KMS key you control if you use OpenTofu. Check who can read state for each environment and whether state snapshots are retained and deleted on a defined schedule.

State encryption docs

Least-privilege roles for the apply pipeline

The identity that runs terraform apply should hold only the permissions needed for the modules in that environment, not a broad administrator role. Separate plan and apply roles, require approval for production applies, and scope each role to one account or project. Ask your cloud team to confirm which actions the cluster, database and key modules really need before the pipeline is granted them.

Key material kept out of code

Encryption keys, KMS key policies and the card vault master key material should be created or referenced by the infrastructure layer, never stored as variables or files in the repository. Terraform should reference key identifiers and let the key service hold the material. Document key custodians and key rotation ownership in the same change set, because a key defined in code is one that anyone with repository access can alter.

PostgreSQL and Redis network isolation

The PostgreSQL primary, replica and Redis endpoints should accept connections only from the subnets and security groups that run the Hyperswitch services. Define these rules in the network module, deny public access by default and block direct administrator access except through a controlled path. Verify after apply that the database and cache are not reachable from outside the cluster network and that the rules match your segmentation diagram.

Secrets not committed to Git

Database passwords, connector credentials and service tokens must not appear in .tfvars files, Terragrunt inputs or Helm values committed to the repository. Generate or store them in a secrets manager and pass references into the code. Add pre-commit and CI scanning for high-entropy strings, and confirm that plan output, which can echo sensitive values, is masked in pipeline logs and artifacts.

Reviewing module changes

Reference modules and Terragrunt configurations change over time, and a version bump can alter networking, encryption or database settings. Pin module versions, review every plan diff for security-relevant resources before merge, and require a second reviewer for changes to IAM, network rules, encryption and the card vault infrastructure. Record the reviewed plan with the change so auditors can trace what changed and who approved it.

Questions teams ask about Terraform and Terragrunt for Hyperswitch

What drives the cost of building the Terraform foundation for Hyperswitch?

The cost depends mainly on how many cloud components the foundation must cover and how many environments it must serve. Network, Kubernetes cluster, managed PostgreSQL, Redis, identities, keys and DNS each add design and testing work, and every additional environment adds configuration and verification. Engineering time is the largest component, paid either to your own staff or to a partner under a written scope. Cloud consumption for the resources themselves is a recurring cost billed by your provider, so ask any partner to separate one-time build work from recurring support and cloud spend in the quote.

How long does the Terraform and Terragrunt work take?

Duration is set by how many cloud accounts and environments are in scope, how much of the network and identity design is already decided, and how quickly approvals and access are granted. Teams that already run Terraform in their organization usually move faster than teams starting a first cloud foundation, because the review and state handling practices already exist. Before agreeing a timeline, confirm which environments must exist on day one, which provider services are already approved, and who signs off on changes to shared networking.

What must our team supply before provisioning starts?

You must supply the cloud accounts or subscriptions, administrative or deployment roles with the permissions the modules need, DNS zones, and a place to store Terraform state. Security and network teams need to approve CIDR ranges, egress paths and key ownership, and your change process must allow infrastructure code to be reviewed and applied. Name the people who approve production changes before work begins, because those approvals often decide the schedule more than the code does.

Can an in-house platform team build this without outside help?

Yes, a platform team with working knowledge of Terraform, Kubernetes networking and managed databases can build this foundation, and Juspay's reference modules give it a starting point. The difficulty is less the syntax than the decisions behind it: private networking, key custody, backup retention and access design. Teams with no recent cloud production experience usually benefit from a review of the design before applying it to production. Whichever path you choose, agree on who owns the code after handover.

How does Terragrunt keep environments separate?

Terragrunt keeps one codebase of Terraform modules and uses a per-environment configuration tree that supplies different inputs, such as account, region, instance sizes and naming, to the same modules. Each environment gets its own remote state location so a change in one cannot silently modify another. Production should use separate accounts or subscriptions where your policies require it, with stricter approvals and different credentials from sandbox and integration environments. Confirm the state backend and locking approach with your platform team before the first apply.

Does Terraform state need encryption, and what does OpenTofu offer?

Yes, state files often contain sensitive values such as database endpoints and generated credentials, so state should be encrypted at rest and access to it restricted. OpenTofu, which is licensed under the Mozilla Public License 2.0 and is a drop-in replacement for Terraform according to its website, encrypts state and plan files for local storage and remote backends with key providers including AWS KMS, GCP KMS, Azure Vault, OpenBao and PBKDF2. Confirm which tool your modules and CI pipelines target and which key provider your security team approves, because switching tools later adds a migration step.

What should we ask a partner to include in a quote for this work?

Ask for a written scope listing the cloud accounts, regions, environments and components covered, such as network, cluster, database, cache, identities and keys. Ask which Terraform or OpenTofu version and which module versions will be used, how state and secrets are stored, and what handover includes, such as documentation, runbooks and code ownership. Also ask what you must provide, what is excluded, how changes to scope are priced, and whether ongoing upgrades and support are quoted separately. Fixed-scope quotes are easiest to compare when every item is named.

Operating the Terraform estate after the first deployment

The Terraform layer needs the same operating discipline as the application, and the first thing to set up is drift detection: a scheduled plan against each Terragrunt environment that reports any difference between the code and the live network, cluster, databases, cache, identities and keys. Someone should be named to read those reports. A plan that shows changes nobody made is a signal that a console edit, a cloud-side default or a module upgrade has moved the estate away from its code, and it should be resolved before the next apply rather than overwritten blindly. Confirm with your cloud provider which managed resources can change outside Terraform, such as automatic version patches on the database or node pool, so you know which drift is expected.

Every change to this layer should go through a reviewed plan. Run terragrunt plan for each affected environment, attach the output to the pull request, and have a second engineer check replaced or destroyed resources in particular, since a replaced database or KMS key can take Hyperswitch data with it. Keep state encryption enabled on every environment, and confirm which key provider protects the state file and who holds permission to decrypt it. Infrastructure changes should pass through the same review path, branch protection and approvals as application changes, so no one can apply to production from a laptop.

Module upgrades and the Hyperswitch release must be planned together. Pin the reference modules to a tagged version, read their changelog for renamed inputs or resource moves, and test the new version in a non-production environment first. Check that the Hyperswitch release you plan to deploy is compatible with the infrastructure it runs on, including the Kubernetes version and PostgreSQL and Redis versions your modules provision. Argo CD then handles application releases from Git inside the cluster this layer creates, while Terraform owns the cluster and its supporting services. Agree on that boundary explicitly, so a Helm value change never waits on a Terraform apply and a cluster upgrade never lands during an application rollout.

How DeployOpen works on this

DeployOpen plans, implements, documents and supports self-hosted open-source platforms inside your own cloud accounts, data centers or air-gapped networks. For Hyperswitch infrastructure, that means agreeing the Terraform and Terragrunt layout in writing first, then building it in your accounts and handing over code, runbooks and evidence your own team can operate.

How we scope

  • Agree which cloud accounts, regions and environments the Terragrunt layout must cover before any code is written.
  • Confirm which Hyperswitch components, databases, cache and key services your stack needs, and which are out of scope.
  • Record state backend, access model, naming and tagging rules in the written scope, with deliverables and timelines agreed up front.

How we build

  • Write Terraform modules for the network, cluster, databases, cache, identities and keys, pinned to versions you approve.
  • Structure Terragrunt stacks so each environment reuses shared modules with separate state, inputs and approval gates.
  • Test plans and applies in a non-production environment, and review encryption of state and secrets before anything touches production.

How we hand over

  • Deliver the repository with module documentation, environment variables, a state recovery procedure and a tested change workflow.
  • Walk your platform and security teams through apply order, drift checks, access grants and how to roll back a failed change.
  • Document which controls and evidence your compliance and security reviewers can use, without DeployOpen issuing any audit or certification.

How we support

  • Offer ongoing support, module upgrades and continuous testing as a retainer, scoped separately from the build.
  • Plan upgrades of the OpenTofu version, provider versions and Hyperswitch release dependencies as a tracked change.
  • Confirm with your team who owns state, keys and cloud permissions after handover, and record that split in the runbook.

Sources and further reading

Talk to our team.

Tell us what you're working on, whether it's a deployment, an audit, a security test or a cyber range. You'll speak with an engineer who can help you scope it.

  • 30-minute call: free, with no obligation.
  • NDA on request: we can sign before you share details.
  • Clear next steps: a scope and plan after the call.