petoju / terraform-provider-mysql

Terraform MySQL provider – unofficial fork
https://registry.terraform.io/providers/petoju/mysql
Mozilla Public License 2.0
63 stars 40 forks source link

Add support for CREATE AADUSER to mysql_user resource #77

Closed kratkyzobak closed 1 year ago

kratkyzobak commented 1 year ago

Supports creating users authorized by AzureAD tokens instead of passwords https://learn.microsoft.com/en-us/azure/mysql/flexible-server/concepts-azure-ad-authentication

Although aad_auth is MySQL plugin and there is theoretical possibility to use CREATE USER ... IDENTIFIED WITH 'aad_auth' AS 'AADUser:objectid:upn:objectname', this is currently not documented solution. As aad_auth is in public preview only, there is no guarantee this command would work.

Therefore I tried to follow documentation and implement Microsoft specific CREATE AADUSER command as much as possible complying with documentation.

What this PR can do:

resource mysql_user {
    user = "someuser" # name used to login to MySQL - in Microsoft's documentation it's alias (CREATE AADUSER x AS alias)
    auth_plugin = "aad_auth"
    aad_identity = "some.user@exampe.onmicrosoft.com"
}

Leads to CREATE AADUSER 'some.user@exampe.onmicrosoft.com'@'localhost' AS 'someuser'

Only thing, where I depend on authentication data is in import, where I parse it back to aad_identity

I did not wrote any tests of auth_plugin = aad_auth since I don't know if there is any possibility to run them in pipeline then as CREATE AADUSER is supported only in Azure managed servers.

I'm aware, that code is not nice, I tried above explain why. If you think, it can be improoved, please show me direction and I will try to do my best.

petoju commented 1 year ago

Released in v3.0.35