Hey everyone! I'm dealing with some Azure SQL instances that go into sleep mode when they're inactive. This means I have to manually wake them up to allow Terraform to check their state, which is pretty tedious. I want to automate the process of waking these instances when I'm running Terraform scripts. Is there a built-in way in Terraform to handle this, or would it be better to create a pre-task using PowerShell to wake them up? Any tips or tricks would be appreciated!
3 Answers
You might want to consider building this automation into your Azure DevOps pipelines. That way, it can run before your Terraform scripts execute.
To wake up your sleepy databases, you can utilize various methods that typically involve connecting to the database and handling any errors that arise. One trick is to use Terraform to check the status of transparent data encryption; this can wake the database up. The TF argument you want is `transparent_data_encryption_enabled`. Just a heads up: waking the database isn't instant and might take anywhere from 30 seconds to 2 minutes depending on your setup.
You could try using a null provider to check if your database exists and poke it awake if it does. That might help automate the process a bit.
I could see that working, but could you provide a bit more detail? I'm still getting the hang of Terraform.
Thanks for the tip on the TDE check! I've had colleagues wait ages just to figure out it was an asleep SQL instance slowing things down.