Terraform Heroku Provider是否支持Dyno资源?部署方式咨询
Great question—let's break this down clearly:
Yes, you do need to deploy your application code (either manually or via automation) after setting up the infrastructure with Terraform. Here's why and what your options are:
1. Terraform's Heroku Provider Focus
The Terraform Heroku Provider is designed to manage infrastructure-level resources on Heroku, like:
- Your application instance
- Attached add-ons (databases, caching, etc.)
- Pipeline configurations
- Buildpack assignments
- Environment variables
It does not handle application code deployment or dyno activation. Dynos only start once Heroku has a deployable "slug" (the packaged version of your app generated after building your code), which requires your code to be pushed to Heroku first.
2. Why Your Dyno Isn't Starting
You've set the heroku/nodejs buildpack, but Heroku has no code to build into a slug. Without a slug, there's nothing for the dyno to run—so it stays inactive, even if all other infrastructure is configured correctly.
3. Beyond Manual Deployment: Automation Options
If you want to avoid manual git push heroku main, here are a few automated approaches to pair with Terraform:
- Use the
heroku_slugresource: This Terraform resource lets you deploy a pre-built slug directly (you'll need to build the slug locally or in a CI pipeline first, then host it at a public URL). Example snippet:resource "heroku_slug" "app_slug" { app = heroku_app.my_app.name process = "web" url = "https://example.com/my-built-slug.tgz" } - Integrate with CI/CD: After running
terraform apply, trigger a CI workflow (like GitHub Actions, GitLab CI) that pushes your code to Heroku's Git remote or uses the Heroku API to deploy. You can output the Heroku app's Git URL from Terraform to feed into your CI tool. - Script the git push: Add a post-apply script to your Terraform workflow that runs
git push $(terraform output heroku_git_url) mainto automate the code push right after infrastructure is set up.
4. Pipeline Note
Your Heroku pipeline will manage promotion between environments (e.g., staging → production), but it still relies on each environment having a deployed slug first. The pipeline doesn't handle initial code deployment—it just moves existing slugs between stages.
内容的提问来源于stack exchange,提问作者Ahmad Ferdous

