Azure failover groups

i have managed to construct two sql servers each with their own elastic pools
i then create a failover group
as i add databases to the first server and include it in the failover group then all is well
but when i try to delete the database it can not remove it from the secondary server as it was not created by terraform but my microsoft failover.

I understand the documentation makes mention of this and that i should ‘create the resource if i want terraform to manage it’ butwithout an example I dont really understand what it wants me to do.

Has anyone else done this and could they explain what they want me to do to manage databases in failover groups through terraform alone?

thanks

I was using modules.

When I use resources with count it seems to work properly.

Imma put this down to modules and a pinch of me not having a clue what I’m doing.

I wasnt overly happy with not really understanding how I got it to work - so I tinkered around a bit more and found the solution. (not sure how to mark answers as solved here neither).

I was bamboozled by the advice presented by Terraform on their help docs:

NOTE: The failover group will create a secondary database for each database listed in databases . If the secondary databases need to be managed through Terraform, they should be defined as resources and a dependency added to the failover group to ensure the secondary databases are created first.

I believe this is wrong, It should read:

NOTE: The failover group will create a secondary database for each database listed in databases . If the secondary databases need to be managed through Terraform, they should be defined as resources and a dependency added to the secondary databases to ensure the failover group is created first.

As Microsoft creats the secondary database automatically, it makes sense to define the secondary database in the script to rely on the failover group having been built first - and therefore create the secondary databases. Terraform will then see they are built and register them in the state file without Terraform actually being responsibile for directly building them.

Tada!