Open simon-eon opened 2 weeks ago
Thanks for raising this issue. It's by service API design. Terraform would always keep align with the behavior of service API. For more usage problem, suggest file Azure Support Ticket on Azure.
Hi Neil,
Can you please document the workflow for how this resource has to be used, in the different authentication szenarios / settings enabled on the server. That you have to figure this out your self is just frustrating. I spent a lot time to figure this out, because i was not expecting an api behaving like this.
So i expect you add to the docs something like this: "When password user is enabled, you need to use that user to manage the created database. It is discouraged to use password user for desaster recovery only." "When using Entra ID Authentication the first admin being added is the owner of all databases created with this resource" "Please make sure you add an administrator befor adding any database, because otherwise the databse would be useless".
Yes i already have support ticket open.
BR Simon
Update: Together with the Microsoft Support we figured out how to solve the specific problem:
If you start by creating an the Server with both authentication methods, you will be forced to use that password user to initially grant permissions to other users for each database created through the API. So i would also recommend to not even create database through the API. The only reason i do this is, because i want to create server, admin, database and service connction with terraform in one go. And service connection needs the database to be created first.
When using Entra ID Authentication for a flexible server and there is no admin user created yet after creating the server, a database get's created with "azuresu" role. In that szenario the database is useless, since no other permissions can be granted on the database. When the user and the database is created in the same pipeline, it is random which role will be owner of the database.
To prevent this, databases should never be created with "azuresu" as the owner. One szenario would be, that the api allows to set a database user.
For now the documentation for the azurerm_postgresql_flexible_server_database should be adapted, to warn about this behavior and provide a workaround.
Is there an existing issue for this?
Community Note
Terraform Version
1.9.7
AzureRM Provider Version
v4.8.0
Affected Resource(s)/Data Source(s)
azurerm_postgresql_flexible_server_database
Terraform Configuration Files
Problem:
Workaround:
Debug Output/Panic Output
Expected Behaviour
A useless Database is never created. (Owner = azuresu) If there is no Entra ID Admin or the current user is not an admin user in the database an error should occur. If there are more Entra ID Admin, and there is no owner name provied through the api, an error should occur.
Actual Behaviour
Database is created, but useless.
Steps to Reproduce
terraform apply (creating database on a recently created db server)
Important Factoids
No response
References
No response