Open Uvindu96 opened 3 years ago
Hi @Uvindu96
This looks similar, meaning you can probably fix it by enabling the SystemAssigned Identity on mssql_server
:
resource "azurerm_mssql_server" "serverx" {
...
identity {
type = "SystemAssigned"
}
...
}
After that, you can probably also remove storage_account_access_key
from the azurerm_mssql_server_extended_auditing_policy
. This whole operation means you'd change from key based authorization to a Identity based authentication/authorization.
It's a bit weird this doesn't work the old way anymore though! Do you have firewall rules on the storage account maybe?
@mbfrahry I was able to enable the mange identity to sql server, but now I'm having a new issue and now it's giving me following error. Please note that I have already enabled the server level auditing logs.
Error: waiting for creation of MsSql Server "sql-asgrndv2-main-rndv2-eastus2-002" Extended Auditing Policy (Resource Group "rg-asgrndv2-main-rndv2-eastus2-002"): Code="BlobAuditingInsufficientStorageAccountPermissions" Message="Insufficient read or write permissions on storage account 'st**ecurity****prod'. Add permissions to the server Identity to the storage account."
Looks like something similer to this issue azurerm_mssql_server_extended_auditing_policy does not correctly set up access to storage account
@yupwei68 Do you have any idea on this issue ? And may I know what are the special permissions required to enable the auditing logs, after enabling the mange identity to the sql server ? I have already provided the Storage Blob Data Contributor
permissions.
Hi @Uvindu96! Have you tried the solution for that mentioned issue, assigning a role on the storage account?
resource "azurerm_role_assignment" "write_permissions_server" {
scope = azurerm_storage_account.storage_accountx.id
role_definition_name = "Storage Blob Data Contributor"
principal_id = azurerm_mssql_server.serverx.identity.0.principal_id
}
Assignment should be done before creating the mssql_extended_auditing_policy
, like:
resource "azurerm_mssql_server_extended_auditing_policy" "mssql_extended_auditing_policy" {
depends_on = [ azurerm_role_assignment.write_permissions_server ]
...
}
@aristosvo I'm using a azure AD group, and I'm adding the sql manage identity as a member to that AD group. I have gave the Storage Blob Data Contributor
role permissions to that AD group. And assign it to the storage account, So in this way it should work right ?
This is my Terraform configuration. Please note that manage identity type is System Assigned.
module "mssql-server" {
source = "/home/uvindu/RndDBs/module2/"
db_server_administrator_login = var.mssql_db_administrator_login
db_server_administrator_login_password = var.mssql_db_administrator_login_password
default_tags = local.default_tags
environment = var.environment
location = var.location
application_name = var.application_name_main
padding = var.padding
project = var.project
resource_group_name = module.resource-group.resource_group_name
mssql_identity_type = var.server_mssql_identity_type
depends_on = [
module.resource-group
]
}
# Add manage identity to storage account
module "add-group-member" {
source = "/home/uvindu/RndDBs/module5/"
group_object_id = var.ad_group_object_id
member_object_id = module.mssql-server.azurerm_mssql_server_identity_object_id
depends_on = [
module.mssql-server
]
}
module "sql-server-audit-logs" {
source = "/home/uvindu/RndDBs/module3/"
mssql_server_id = module.mssql-server.azurerm_mssql_server_id
mssql_storage_account_primary_blob_endpoint = var.log_archival_storage_account_primary_blob_endpoint
retention_in_days = 365
depends_on = [
module.mssql-server,
module.add-group-member
]
}
Hi @Uvindu96, it is hard to validate your setup from a distance. Based on the error message it is an authentication problem, an other possibility is that it might be a network issue (but the error message doesn't indicate that).
It would probably be easiest if you could validate the solution as suggested and work from there. That would be my approach at least, checking the network is the other option.
Terraform (and AzureRM Provider) Version
Expected behavior
We have configured the SQL server and databases using terraform. And recently I was trying to increase the db short term backup retention period using terraform. Once the retention period is set it should be able to update the db short term backup retention time.
Actual behavior
When I trying to apply the changes it gives me the following error.
Since I'm not doing any changes to db auditing policy this error is strange. I'm only making changes in
azurerm_mssql_database
resource. Is there any solution for this ?Following are the terraform resources that we are using.
azurerm_mysql_server
azurerm_mssql_database