I recently worked on an infrastructure deployment using Terraform + Azure, and I hit a problem that made my head spin for hours. Everything in my code looked logically perfect, yet the deployment kept failing. Only later I discovered that it was not a “code issue” but a dependency issue and it taught me a valuable Terraform lesson.
Let me share that journey, so nobody else loses hours like I did.
🔥 The Setup
I was provisioning multiple resources using Terraform, including:
- Azure Redis Cache
- Azure App Service, which needed the Redis connection string as an environment variable
On paper, the flow looked simple:
Create Redis → get connection string → use it in App Service
But reality had other plans.
❗ The Unexpected Failure
Whenever I ran terraform apply, the Redis creation started…
But while Redis was still provisioning (and Azure Redis usually takes time), Terraform tried to create the App Service immediately.
As a result:
Error: Redis endpoint not found
I double-checked the code multiple time everything looked correct!
So why was it failing?
🧠 The Hidden Reason Terraform Doesn't Automatically Wait
Terraform executes resources in parallel by default to speed up deployment.
It only waits for dependencies if they are explicitly defined.
Even though I used Redis output inside the App Service configuration, Terraform didn’t treat it as a strict dependency and started creating both resources simultaneously.
Redis was still provisioning → App Service needed Redis → App Service failed.
That was the missing piece.
🔧 The Fix depends_on
I added an explicit dependency in the App Service resource:
depends_on = [
azurerm_redis_cache.redis
]
And boom Terraform waited for Redis to finish provisioning before creating the App Service. Deployment succeeded. 💯
🏷 What I Learned
Here’s the takeaway from this experience:
Without depends_on
|
With depends_on
|
|---|---|
| Terraform runs resources in parallel | Terraform respects resource order |
| May fail if referenced resource isn’t ready | Ensures resource readiness before execution |
| Hidden debugging headaches | Clear creation sequence |
Terraform is smart, but not psychic it won’t guess resource order unless we tell it.
✔ Final Thoughts
This issue took me hours to understand, but it taught me something crucial:
Terraform isn't just “writing infra as code” it’s also about controlling resource orchestration.
Next time you are creating interdependent services:
- If one resource must finish before another starts → use
depends_on - Don’t assume Terraform will wait automatically
💬 Your Turn
Did you ever face something similar with Terraform parallel execution or Azure resource delays?
I’d love to hear your war stories and fixes!
Top comments (0)