How Zitadel configuration as code with Terraform works
Teams that have configured Zitadel by hand in the console eventually need the same changes applied to staging and production in a repeatable, reviewable way. The Zitadel Terraform provider applies configuration through Zitadel's APIs, and Terraform state records what was applied, so every later plan shows drift between the code and the live instance. The provider manages the objects that define your tenancy and access model: organizations, projects, applications, users and the grants that connect them. Before you write any module, confirm the registry source, provider version and resource names against the provider documentation, because the provider is published by Zitadel and its resource schemas can change between versions.
Some things should stay out of Terraform. Runtime sessions, end-user logins and the tokens issued during sign-in are produced by Zitadel as people use it, so they have no place in a configuration plan. Secrets such as application client secrets and service account keys should come from a secret store or be generated outside the code, because Terraform state can hold sensitive values in plain text. Decide early which team owns each boundary: identity engineers may own the shared organization and project objects, while application teams own their redirect URIs and environment-specific settings, reviewed through the same pull request process.
The provider configurations are published under Apache 2.0, even though Zitadel moved its core, Console and hosted login to the GNU Affero General Public License 3.0 with v3.0 on 31 March 2025, as described in the Zitadel blog post on the license change. Your team should still review the license obligations for the Zitadel core it runs, since that is a separate question from the configuration repository. Use a remote state backend that supports locking and access control, and keep separate state per environment so a staging apply cannot touch production objects. Confirm that the provider version pinned in your lock file matches the Zitadel release you run, and read the upgrade notes before changing either one.
What Zitadel configuration as code with Terraform needs first
Six items need to be confirmed before the first plan touches a Zitadel instance. Together they set the version, the database, the identity Terraform uses, the toolchain, where state lives and the network path to the API. Each card names the check to make and the team that usually owns it.
Zitadel instance at a tested version
Decide whether Terraform will target a self-hosted instance or Zitadel Cloud, then confirm the exact version your instance runs and check it against the provider's compatibility notes before the first plan. The latest published release is v4.19.5, dated 15 October 2026, but the version your team has tested is the one the pipeline should target. Platform engineering usually owns the instance and its upgrade schedule, so agree the target version with them in writing.
Zitadel releasesPostgreSQL within supported versions
Self-hosted Zitadel stores its data in PostgreSQL, and the supported range is versions 14 through 18. Confirm the major version, the database owner and the backup schedule before any Terraform run writes configuration, because a restore can roll organizations, projects and users back to an earlier point. Record the database version in the same change record as the Zitadel version. Database administrators usually own this item. If you use Zitadel Cloud, confirm with Zitadel which parts of this apply to you.
Zitadel database docsAdministrator identity for machine user
Terraform authenticates to Zitadel as a machine user, so an administrator with rights to create that user and grant it roles must run the initial setup. Confirm which administrator identity holds those rights, that it signs in with multi-factor authentication, and that its activity is logged outside the instance. Keep the machine user scoped to the organizations and projects it manages, and record who can rotate its key. Identity administrators usually own this step, and the security team should review the grants.
Terraform and provider pinned together
Pin the Terraform CLI version and the Zitadel provider version in version control, so every plan on a branch runs the same toolchain. Commit the lock file that records provider checksums, and review provider upgrades as code changes. Read the provider release notes against your Zitadel version before bumping either one. Platform engineering owns this repository and its pipeline, and the reviewers of infrastructure changes should approve provider bumps like any other dependency.
Remote state backend with locking
Terraform state can hold identifiers and sensitive values from the resources it manages, so store it in a remote backend that supports locking and encryption at rest. Confirm that concurrent applies block each other, that access to the state store is limited to the pipeline and named operators, and that earlier state versions can be recovered. Keep separate state for staging and production so a promotion never shares a state file. Security and platform teams usually own this item.
Network path and TLS certificate
The Terraform runner must reach the Zitadel API over HTTPS from wherever it runs, whether that is a CI runner, a bastion host or a private network segment. Confirm the route, firewall rules and any proxy settings, and confirm that the certificate Zitadel presents chains to a certificate authority the runner trusts. Test both from the exact runner image before the first plan, because certificate errors often appear only inside pipelines. Network engineering and the certificate owner usually share this item.
Self-hosting overviewHow a Terraform run reaches Zitadel and its state
The flow starts at the Git repository, where reviewed Zitadel configuration is merged, and the CI runner, which runs terraform plan and then terraform apply. At run time the runner takes a service account credential from the secrets store. Each environment has its own service account, its own remote state with locking, and its own Zitadel instance, so a staging run uses only staging credentials and state. The Zitadel provider calls the Zitadel API across the trust boundary between the runner and the instance. Before approving an apply, check that the plan names the environment you expect.
Each environment has its own state, service account and Zitadel instance.
Setting up Zitadel configuration as code with Terraform, step by step
This sequence moves one organization in a self-hosted Zitadel instance from console-managed configuration to Terraform-managed configuration. It covers the machine identity Terraform uses, how its secret is stored, version pinning, provider and backend setup, and importing existing objects. Each step ends with a check you can run before the next one starts.
Create a dedicated machine user for Terraform
A platform engineer creates a separate machine user in the target organization, used only by Terraform, so automation never runs under a person's account or the instance administrator. Assign the narrowest built-in role that can manage the objects in scope, such as projects, applications and users, and confirm that role against Zitadel's current role documentation before assigning it. Check: request a token for the machine user and list users in the target organization, which should succeed, then attempt an instance-level call, which should fail.
Generate the credential and store it outside the repository
The platform engineer generates the machine user's key in Zitadel, downloads it once, and uploads it to the secrets manager your team already operates. Limit read access to the pipeline runner identity and the few maintainers who need it, and delete any local copy after upload. Keep the key out of the Git repository, the Terraform working directory and CI logs. Check: search the repository history and the working directory for the key material, and confirm that only the approved runner identity can retrieve the secret from the manager.
Pin the Zitadel provider and Terraform versions
The engineer sets an exact Terraform core version and an exact Zitadel provider version in the configuration, then commits the dependency lock file so every run resolves the same provider build. Choose a provider version that matches the Zitadel release you run, and confirm the pairing in the Zitadel releases on GitHub before you commit. Upgrades then go through their own reviewed change and run against staging first. Check: initialize on a clean checkout and confirm the lock file does not change.
Configure the provider with the instance domain and credential
The engineer adds the provider block with your instance domain and reads the machine key from the secrets manager through a variable or environment reference, marking it sensitive so it stays out of code and plan output. Point the configuration at the target organization. Run a plan once with a deliberately wrong key, then restore the correct one. Check: the wrong-key run stops with an authentication error before any change is proposed, and the correct key produces a plan that reads the organization without errors.
Configure a remote backend with locking and encryption
The engineer moves state out of the local working directory into a remote backend that supports both locking and encryption at rest, such as an object store or database your platform team already runs. Confirm with the team which backend offers locking in your setup, and keep separate state for staging and production so the two never share state. Restrict access to the pipeline and the maintainers. Check: start a plan in one session, then start a second plan against the same state, which should wait on or fail on the lock until the first run finishes.
Import existing console objects and confirm a clean plan
Staging already holds organizations, projects, applications and users created in the console. The engineer writes resource blocks that match each object, then imports them into state so Terraform manages them without recreating them. Use the import identifier format from the provider documentation for your pinned version, since it varies by resource type. No apply runs until the plan has been reviewed. Check: the first plan after import shows no changes to existing objects, and any intended change appears only in a later, separately reviewed plan.
Which Zitadel objects map to which Terraform resources
This table compares the Zitadel objects you manage as code with how each one appears in Terraform, and what to settle before writing configuration. Read each row from left to right: the concept, what it holds, how your code refers to it, and the decision to make first. The main takeaway is that instance and organization choices sit above everything else, so settle them before any project or user resources depend on them.
| Zitadel concept | What it contains | How Terraform references it | What to decide first |
|---|---|---|---|
| Instance | A virtual tenant with full data isolation, holding the organizations and instance settings | Managed in a separate state from org-level code; confirm the resource and import ID in the provider docs | Instance count, domain names, and who can change instance-level settings |
| Organization | A container inside the instance where projects and users live | Other resources take its ID as an input; confirm the attribute name and import ID format in the provider docs | Whether one organization covers all staff or each customer gets one |
| Project | Groups applications, roles and grants within one organization | Referenced by ID from application, role and grant resources; confirm the import ID in the provider docs | Whether each product or environment gets its own project |
| Roles and grants | Roles defined on a project, and grants that give other organizations access to it | Role keys and grant IDs feed other resources; confirm which attribute each one exposes | Role naming, who receives each grant, and how grants are reviewed |
| Application | OIDC or SAML client with redirect URIs, logout URIs, token and client authentication settings | Linked to its project by ID; confirm the import ID and review redirect changes in each plan | Client type, grant types, redirect URIs for each environment, and where secrets live |
| User | A person or service identity inside an organization, with login name, email and profile fields | Map each user to a stable key kept in code; confirm the lookup and import ID in the provider docs | Which attribute matches a person across staging and production, such as email or an external ID |
Keeping Terraform state safe when it holds identity data
Treat the Terraform state for Zitadel as a copy of your identity configuration. State records the attributes Terraform reads back from each resource it manages, so it can hold user emails, application client details and organization identifiers. Some provider values, such as generated client secrets, may also land in state, so confirm with the Zitadel provider documentation which attributes are marked sensitive before you decide who can read the file. Store state in a remote backend that your security team already reviews, keep it out of Git and off laptops, and grant read access to state at the same level as the administrator role that writes to Zitadel. Enable encryption at rest in the backend and confirm that connections to it use TLS. Turn on the backend's locking as well, so two concurrent applies cannot write conflicting state to the same file.
Split access by job. The pipeline that runs terraform apply needs write access to state and to the service account key it uses, while people who review plans usually need read access to plan output only. Saved plan files can contain the same sensitive values as state, so store them with the same restrictions and do not paste full plan output into chat or tickets. Scope the Zitadel service account to the organizations and projects it manages, so a leaked credential cannot reach the whole instance. If a state file is copied or lost, act in this order: rotate the service account key and any client secret that appears in the state, review what your Zitadel instance logs for use of those credentials, restore state from the backend's version history if the file was lost, and record the incident for your compliance evidence. Confirm with your backend vendor how versioning and restore work before you need them.
Renaming a resource in code also changes its address in state. If you rename a Terraform resource block, or move it into a module, without recording the move, Terraform matches the new address against state, finds nothing, and plans to destroy the old object and create a new one. For an application or a service account, that delete can disable a live sign-in flow until the replacement exists and its client details reach the consuming application. Record each move with a moved block or terraform state mv, then check that the plan reports a move with no destroy. Test the change in staging first, reading the plan line by line for any destroy on an application, project or organization. Also confirm which identifier the provider uses for each object, because changing that identifier can force replacement even when the code change looks small.
Promoting identity configuration from staging to production
This model gives each environment its own Zitadel instance. The instance is the tenant boundary, so staging and production share no users, clients or instance settings. The same Terraform module is applied to both, with a different variable file for each. It offers the strongest isolation of the three models, and the cost is running two deployments.
- Promoted: the module source, the provider version pin and the resource definitions for organizations, projects, applications and roles. The same commit is applied to production only after staging has been verified.
- Environment-specific: issuer domains, redirect and post-logout URIs, client identifiers, client secrets, service account keys and the state backend for each instance. Keep these in each environment's variable file or secret store, outside the shared module.
- Review: a merged change applies to staging first, then a separate approval applies the same commit to production. Keep the plan output from both runs with the change record.
- Blast radius: a wrong application client in staging cannot reach production users or production clients, because the instance is the isolation boundary. A wrong change that reaches production affects every organization in that instance, so the production approval step carries the most weight.
- Trade-off: two deployments mean two upgrade cycles, two sets of backups and two monitoring setups, and variable files can drift apart over time. Confirm per-instance resource needs and any instance-level limits in the Zitadel deployment documentation before choosing this model.
Check that the staging and production variable files differ only in the keys you listed, and that a production plan shows no unexpected changes before the first apply.
This model runs staging and production as two Zitadel organizations inside one instance. Projects, users and applications live inside an organization, so the same module can create matching resources in both, with the organization identifier set by a variable. The two environments share the instance, which means they share instance-level settings and one deployment to operate.
- Promoted: the module and the project, application and role definitions, applied with the organization as a variable. A clear naming convention, such as the illustrative pair
payments-stagingandpayments-prod, makes it obvious which organization a plan targets. - Environment-specific: organization identifiers, domains and redirect URIs for each application, client secrets, identity provider links and user data. Users created in staging organizations never appear in production organizations.
- Review: the same pull request and plan review as any Terraform change, with the plan header showing the target organization. Scope the provider credential for each organization to the management role it needs, if your Zitadel setup supports that split.
- Blast radius: a wrong client in the staging organization stays in that organization. A change to instance-level settings, such as login policy or branding, reaches both environments at once, so manage those resources in a separate module with a stricter review.
- Trade-off: one deployment costs less to run and upgrade, but staging and production sit inside one tenant boundary, so a credential or administrator with instance-wide reach can touch both. Confirm how organization permissions and instance-level settings are scoped in the Zitadel documentation before you rely on them.
Check that the naming convention is enforced in code, so a copied variable file cannot point a production plan at the staging organization.
This model keeps one repository and one module, with a Terraform workspace or separate state for each environment. The pipeline plans every change, applies it to staging, and holds production behind an approval gate that applies the same reviewed commit. It is the simplest model to version and audit, but its safety depends on the gate and on credentials kept separate for each environment.
- Promoted: the same commit, planned once per workspace. A variable file for each environment, such as
staging.tfvarsandproduction.tfvars, carries the differences, and the code does not branch by environment. - Environment-specific: workspace variables, provider credentials, domains, redirect URIs and client secrets. Store secrets in the CI secret store or a secrets manager, so the repository holds references and no values.
- Review: a pull request produces a plan for each workspace, a reviewer approves the plan, and the merge triggers the staging apply. The production apply runs only after a named approver accepts the staging result.
- Blast radius: the gate and per-workspace credentials limit damage, but one pipeline with one broad credential can reach both environments. Give the production workspace its own credential, restrict who can trigger its apply, and protect the main branch.
- Trade-off: one repository is easy to review and audit, and drift appears in the next plan. A mis-selected workspace or a shared state key can still send a change to the wrong environment. Confirm how the provider authenticates per workspace, and check any instance-level limits in the Zitadel deployment documentation.
Check that the production apply job fails when the workspace name and the variable file do not match, and test that rule with a deliberate mismatch in staging.
Security controls for the Terraform service account
The Terraform service account can create, change and delete identity configuration across an organization, so it deserves the same care as a production administrator. The six controls below cover who holds the account, how its credentials are stored and rotated, what leaks into logs, who approves changes, how drift is detected and how the account is retired. Confirm each setting against the Zitadel and provider versions you pin before you rely on it.
Least-privilege roles for the machine user
Create a dedicated machine user for Terraform and grant it only the roles its configuration needs, inside one organization it manages. Avoid instance-level administrator roles, because a leaked key with those rights can reach every organization in the instance. Confirm the role names in the Zitadel release you run before writing the grant. Ask whether the provider needs write access to users, projects or applications, and remove any grant it does not use.
Organizations conceptRotated credentials in a secrets store
Keep the machine user's key out of the repository, shared CI variables and plan artifacts. Store it in a secrets store with access limited to the pipeline runner that needs it, and rotate it on a schedule you write down. Shorter lifetimes limit the damage from a leak, so use a short rotation window if the provider and your Zitadel version support it. Confirm which credential types the provider supports in the version you pin before you design the rotation.
Keeping secrets out of logs and plans
Plan output and CI logs often show resource attributes such as user names and email addresses, which are personal data. Mark sensitive variables and outputs so Terraform hides them in CLI output, avoid debug flags in the pipeline, and set log retention and viewer access on the CI platform. Treat saved plan files and state as sensitive too, because they can hold the same values in full. Confirm with a test user what actually appears in logs before you widen access.
Separating plan approval from apply
Let one identity produce a plan, a different reviewer approve it and a third step apply exactly that saved plan. Applying a fresh plan after approval can change what the reviewer signed off on, so the apply job should consume the reviewed plan file. Restrict who can trigger the apply stage through protected branches or environment approvals, if your CI platform offers them. Record the commit and plan identifier each apply used, so the audit trail links each approval to a change.
Auditing API changes against Git
Changes made in the Zitadel console or through the API bypass the repository, so the configuration in Git can drift from the live system. Run a scheduled plan that should show no changes, and treat every proposed change as drift to explain before the next apply. Check that the event history for the machine user matches the commits and approvals in your pipeline. Ask which events your Zitadel version records and how long they are kept.
Retiring the machine user
When a pipeline is retired, decide whether its managed Zitadel objects should be destroyed or handed to another pipeline, and update state to match before the account goes. A run that finds managed objects missing from state can try to recreate them. Then revoke its keys, remove its grants, and disable or delete the machine user. Delete the secret copies and CI variables, and confirm no other job still references the account. Keep the final plan and audit records for the period your own policy sets.
Why Terraform applies to Zitadel fail or drift
This table lists the failures that commonly block or distort Terraform runs against Zitadel, with the likely cause, a check to run and a fix for each. Read each row from the symptom down, and run the check before changing any code or state. Many failures trace back to one of three things: a change made outside code, a version or permission mismatch, or a state operation that was not reviewed.
| Symptom | Likely cause | Check | Fix |
|---|---|---|---|
| Plan shows in-place changes to an app or project nobody changed in code | Someone edited the object in the Zitadel console, so state and live config differ | Run a refresh-only plan to list changed attributes, then ask who edited the console | Reapply from code to restore declared values, or move the change into code and review it |
| Import succeeds but later plans want to replace or change imported objects | Config arguments do not match what the provider reads back, or write-only fields such as secrets are missing from the import | Plan right after import and compare each flagged attribute with the provider documentation for that resource | Align config with the imported values, and ignore only fields the provider cannot read back |
| Plan errors or unexpected diffs after upgrading Zitadel or the provider | Provider release does not match the Zitadel version it calls, so API fields differ | Compare the provider pin in required_providers with the Zitadel version and the provider release notes | Pin both versions, test the pair in staging, and upgrade production only after it passes |
| Permission denied on create, read or update for a resource that Terraform manages | The machine user behind the provider lacks the role for that resource type or scope | Check the role granted to the service account at instance and organization level against each resource in the plan | Grant the smallest role that covers the planned resources, separately for staging and production |
| Staging apply overwrites production redirect URIs, or sign-in fails after promotion | Redirect URI values are hardcoded or shared between environments in the module or variables | Diff the redirect and post-logout URI variables for each workspace or environment file | Move redirect URIs into per-environment variables, keep application names identical, and confirm the target workspace before apply |
| Run fails at start with a lock error and no apply is running | A previous run was killed or timed out and left the state lock held | Read the lock ID and holder from the error, then confirm no pipeline or colleague is still applying | Release it with terraform force-unlock using that lock ID, then run a plan before any apply |
| Plan proposes destroying and recreating an app, project or org after a code rename | Terraform tracks resources by address, so a renamed block looks like a delete plus a create | Find the old and new addresses in the plan and check whether the Zitadel object is kept | Add a moved block or run terraform state mv before planning, and stop if the plan shows a delete you did not expect |
What does Zitadel configuration as code with Terraform cost and require?
What makes a Zitadel Terraform engagement cost more or less?
Cost follows how much identity configuration exists and how many places it must land. The main drivers are the number of Zitadel organizations and projects, the applications and role grants in each, the identity providers configured per organization, the number of environments (typically staging and production), and how many objects already exist in the console that must be imported into code without being recreated. Quoted work usually splits into one-time items (inventory, module design, import, pipeline setup, promotion runbook) and recurring items (configuration changes, provider and Zitadel upgrades, reviews). Your own costs include CI runners, a state backend and the Zitadel plan or infrastructure you run. DeployOpen does not publish prices. A quote follows a written scope, so count the items above before you ask.
How long does importing Zitadel configuration into Terraform take?
Duration is set by the same inventory that drives cost, plus how clean the existing console setup is and how many approvals the promotion path requires. The work usually runs in phases: inventory and import of existing objects, module and state design, a working staging environment, then a reviewed promotion to production. Each phase depends on client access being ready, so an administrator account, a CI runner and a state backend available early shorten the path. Fixed-scope engagements agree timelines in writing before work starts, and DeployOpen does not publish a standard duration. Ask for the phase list, the client dependencies and the acceptance steps in the written scope, and confirm with your change board when production changes can be scheduled.
What does our team need to provide for this work?
Your team provides five things. First, an administrator in Zitadel with rights to create the service account and the organizations or projects in scope. Second, a CI pipeline with a runner that can reach the Zitadel API and run terraform plan and terraform apply in each environment. Third, a remote state backend with locking, encryption and access limits, with one state per environment. Fourth, a secrets store for the service account key and any values the pipeline reads, so credentials stay out of the repository. Fifth, a named approver for production plans, who reviews the plan output before apply runs. Confirm these with your security team early, because the service account's permissions define what the code can change.
Can our internal platform team run Zitadel Terraform configuration alone?
Yes, if the team already has the skills below and enough capacity to build and maintain the pipeline. The skills are Terraform module design and state handling, an understanding of Zitadel's model of instances, organizations, projects and grants, OpenID Connect and SAML basics so the code expresses applications correctly, CI/CD and secrets handling, and enough operational knowledge to run Zitadel itself, including PostgreSQL if you self-host. Plan for a learning period on Zitadel's resource model before the first production change. Many teams start with one environment and one organization, prove the import and promotion path, then extend it. Bring in outside help where the team lacks a skill or capacity, and confirm which parts you will own after handover.
Does the Zitadel license or plan change what this work costs?
Your Zitadel license and plan are separate from the configuration work, but they shape what that work targets. Since Zitadel v3.0 on 31 March 2025, the core, Console and hosted login are licensed under AGPL 3.0, while APIs, SDKs, examples, documentation, Helm charts and Terraform configurations stay Apache 2.0. Zitadel Cloud lists a Free plan at US$0 per month with 100 daily active users, a Pro plan at US$100 per month including 25,000 daily active users, and an Enterprise plan with custom pricing for self-hosted or cloud deployments, which adds custom support agreements and technical account management. Review the Zitadel pricing page for current terms. Have your legal team confirm how AGPL 3.0 applies to any changes you make, and include your chosen deployment model in the written scope.
Does DeployOpen supply the Terraform code, review and ongoing changes?
Yes, each can be in scope, and each is agreed separately in the written scope. DeployOpen can write the Terraform code for organizations, projects, applications, identity providers and users, along with the environment layout, the pipeline definitions and the promotion runbook, and document how each part works. A review of existing code or a change set can be a defined deliverable, with findings and fixes listed. Ongoing changes, upgrades and continuous support are available as retainers, so changes after go-live can continue under an agreed arrangement. Engagements are fixed-scope, with deliverables and timelines agreed in writing before work starts. Confirm in the scope who holds the repository, the state and any credentials at handover.
What usually goes wrong when promoting Zitadel configuration to production?
The most common problem is drift: someone changes an application or policy in the console, and the next apply either reverts that change or fails. Other frequent problems include environment values such as redirect URIs, domains and client IDs hard-coded into shared modules, so staging settings reach production; a production plan applied from an unreviewed branch; a service account with broader permissions than the code needs; and imported objects that Terraform plans to recreate because the import was incomplete, which can disrupt sign-in for live applications. Guard against these with one state per environment, variables for each environment, a plan reviewed by a named approver, restricted console edits and a scheduled drift check. Test the promotion path in staging before the first production change.
How DeployOpen scopes and delivers Zitadel configuration as code
DeployOpen plans and implements Zitadel configuration as code inside your own infrastructure, so organizations, projects, applications and users are described in Terraform files your team can review. The work is agreed in a written, fixed scope before it starts, and it covers the service account, state handling and the path from staging to production. Ongoing support and upgrades are available as a retainer.
How we scope
- The written scope lists which Zitadel instances, organizations and projects the Terraform code will manage.
- It names which applications, roles, grants and user records are in or out of code management.
- We confirm your Zitadel release and PostgreSQL version, which Zitadel supports from 14 through 18.
How we build
- Terraform configuration is written against the Zitadel provider, with service account credentials kept out of the code.
- Remote state storage and access rules are designed with your security team before the first apply.
- Staging and production run as separate environments, with changes promoted through the same reviewed code path.
How we hand over
- You receive the Terraform repository, module layout, variable reference and a runbook for planned changes.
- A walkthrough covers how to review plans, handle state and promote changes from staging to production.
- Documentation covers the service account setup, its role assignments and where its credentials are stored.
How we support
- Ongoing support, upgrades and continuous testing are available as retainers after handover.
- Provider version pinning and Zitadel upgrades are reviewed against the Terraform code before rollout.
- Git change history gives your compliance team evidence of who changed which identity settings, and when.

