fix(modal): Support non-main envs in Modal#629
Conversation
modal_workspace held the full URL slug rather than just the workspace name. Added modal_environment and a modal_workspace_slug local so each variable holds its correct semantic value.
📝 WalkthroughWalkthroughThis PR extends Modal workspace configuration to support environment-specific naming. A new ChangesModal Environment Variable Integration
Sequence DiagramNot applicable; this PR contains configuration and infrastructure variable updates without multi-component runtime interaction. Estimated code review effort🎯 2 (Simple) | ⏱️ ~12 minutes Possibly related PRs
Poem
🚥 Pre-merge checks | ✅ 5✅ Passed checks (5 passed)
✏️ Tip: You can configure your own custom pre-merge checks in the settings. ✨ Finishing Touches🧪 Generate unit tests (beta)
Tip 💬 Introducing Slack Agent: The best way for teams to turn conversations into code.Slack Agent is built on CodeRabbit's deep understanding of your code, so your team can collaborate across the entire SDLC without losing context.
Built for teams:
One agent for your entire SDLC. Right inside Slack. Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. Comment |
There was a problem hiding this comment.
Actionable comments posted: 1
🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.
Inline comments:
In `@terraform/environments/production/variables.tf`:
- Around line 75-84: Update the validation block for the Terraform variable
"modal_environment" to also reject colon and slash characters: modify the
existing validation condition in the variable "modal_environment" (currently
referencing var.sandbox_provider and length(var.modal_environment)) to
incorporate a regex check that ensures the value does not contain ":" or "/"
(e.g., using can(regex("^[^:/]+$", var.modal_environment)) in the condition when
sandbox_provider == "modal"), and update the error_message to something like
"modal_environment must not contain colons or slashes." so invalid endpoint
slugs are prevented.
🪄 Autofix (Beta)
Fix all unresolved CodeRabbit comments on this PR:
- Push a commit to this branch (recommended)
- Create a new PR with the fixes
ℹ️ Review info
⚙️ Run configuration
Configuration used: defaults
Review profile: CHILL
Plan: Pro
Run ID: 29cf18c9-edff-40e9-938f-637f10338315
📒 Files selected for processing (6)
docs/GETTING_STARTED.mdterraform/environments/production/locals.tfterraform/environments/production/modal.tfterraform/environments/production/terraform.tfvars.exampleterraform/environments/production/variables.tfterraform/environments/production/workers-control-plane.tf
|
|
||
| app_name = "open-inspect" | ||
| workspace = var.modal_workspace | ||
| workspace = local.modal_workspace_slug |
There was a problem hiding this comment.
[Automated Review]
The slug is plumbed into URL construction here, but modal deploy / modal secret create in terraform/modules/modal-app/scripts/{deploy,create-secrets}.sh are invoked without --env (and no MODAL_ENVIRONMENT is exported), so they deploy to the workspace's default environment regardless of var.modal_environment.
Concretely, with modal_environment = "production":
- This module's outputs and the worker's
MODAL_WORKSPACE→myworkspace-production--…modal.run - But
modal deploylands the app at the workspace default (typicallymain) →myworkspace--…modal.run - Result: every endpoint 404s.
Suggested fix:
- Add a
modal_environmentinput to themodal-appmodule. - Pass it as
MODAL_ENVIRONMENTin theenvironmentblocks ofnull_resource.modal_secretsandnull_resource.modal_deployinmodules/modal-app/main.tf— Modal CLI reads that var natively.
(Or alternatively, append--env "${MODAL_ENVIRONMENT}"in both scripts.)
Without this, the feature is half-wired for non-main envs — URLs point one place, deployment lands somewhere else.
ColeMurray
left a comment
There was a problem hiding this comment.
see comment regarding modal script
Summary
Modal has a hierarchy of workspaces -> environments. The default environment is
main. If you stick with that, the environment doesn't have any impact on Modal's URLs; however, if you use a non-default environment, e.g.,prod, that environment name is added into the URL. These changes support generating Modal's URL slug properly to support bothmainand non-default environments.Backwards compatibility
modal_environmentTerraform variable defaults tomainso projects that don't set it will not be impacted.Docs updated
docs/GETTING_STARTED.md— updatedterraform.tfvarsblockterraform/environments/production/terraform.tfvars.example— updated example to include the new variableSummary by CodeRabbit
Documentation
New Features