Prerequisites
- A dev tenant that Terraform already manages, as in Import the dev tenant into Terraform.
- A CI pipeline that runs Terraform for the new environment, as in Running QA and production.
1. Create the tenant
Create the tenant in the portal and generate its Management API secret key. Don’t configure anything else in it. Store the key, the tenant ID, the host, and any secret values, such assendgrid_api_key, as secrets for the QA pipeline, as in Running QA and production. Don’t keep the key on your machine.
2. Create the folder
Createenvs/qa and copy in only main.tf, variables.tf, terraform.tfvars, and .terraform.lock.hcl from envs/dev. The lock file keeps QA on the same provider version as dev.
Don’t copy the .terraform folder, any terraform.tfstate files, imports.tf, or tfplan. State belongs to one tenant. Copying it would make Terraform think QA already has dev’s resources.
If you use a backend, change its key in envs/qa/main.tf so QA gets its own state, such as authsignal/qa.tfstate. If QA and production state is kept in a separate bucket, change bucket too. With HCP Terraform, change the workspace name in the cloud block, such as to authsignal-qa. Otherwise QA shares dev’s workspace and state. Then set the QA values.
terraform.tfvars still has dev’s values, so check every line. Take extra care with the web addresses. Authsignal sends each one-time code to email_otp_webhook_url, so if it still has dev’s address, the new tenant sends its users’ codes to dev. Any address in passkey_expected_origins can sign users in to the tenant with their passkeys, so list only the new environment’s own addresses.
3. Import the theme
Every tenant already has a theme, and the provider can’t create one, so it has to be imported. Everything else is created, since a new tenant has no authenticator configurations, flows, or message overrides.4. Plan
Commitenvs/qa, including imports.tf, and open a pull request. After it merges, run the QA pipeline. With the example module, the plan shows:
- The four additions are the two authenticators, the flow, and the message overrides.
- The theme is both the import and the change. The new tenant has the default theme, so Terraform imports it and updates it to match dev in one step. It is marked
(imported from "theme")in the plan.
5. Apply
Approve the apply in the pipeline. Then deleteenvs/qa/imports.tf and merge that too. The import is done, so the block isn’t needed any more.
Verify
Run the QA pipeline again. Its plan should reportNo changes. Test sign-in on the new tenant.
Follow the same steps for production. When dev, QA, and production all report No changes, they are aligned.
