-
Notifications
You must be signed in to change notification settings - Fork 4.7k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Error: cannot configure extended_auditing_policy
in secondary create mode for Database: (Name "database" / Server Name "sql_server" / Resource Group "resource_group")
#13774
Comments
@jadamsHCBB Thanks for raising this issue! Is it possible to add a simpler reproduction scenario which reflect the desired configuration? Or at least a simplified configuration as used on step 4? At this moment I'm flying a bit blind on what the actual configuration is you'd like to have. |
Yes of course. Updated with a simple implementation. The important thing to note is that it seems the issues is stemming from this being a "Secondary" create_mode database based on our primary. Which, that seems to be where the extended_audit_policy is being inherited from. So I did an import of said policy, then ran an apply and it gave me this error. |
Indeed, secondary databases inherit their extended auditing policy from their primary. If not explicitly necessary, I wouldn't change it tbh, and also not import it. See also the documentation. Is scenario below as it is before step 3? provider "azurerm" {
features {}
}
variable "secondary_location" {
type = string
default = "northeurope"
}
resource "azurerm_resource_group" "main" {
name = "jadams-example"
location = "westeurope"
}
resource "azurerm_mssql_server" "main" {
name = "sqlserver-jadams-example"
resource_group_name = azurerm_resource_group.main.name
location = azurerm_resource_group.main.location
version = "12.0"
administrator_login = "missadministrator"
administrator_login_password = "AdminPassword123!"
}
resource "azurerm_mssql_database" "main" {
name = "db-main"
server_id = azurerm_mssql_server.main.id
}
resource "azurerm_storage_account" "main" {
name = "jadamsexample"
resource_group_name = azurerm_resource_group.main.name
location = azurerm_resource_group.main.location
account_tier = "Standard"
account_replication_type = "LRS"
}
resource "azurerm_mssql_database_extended_auditing_policy" "main" {
database_id = azurerm_mssql_database.main.id
storage_endpoint = azurerm_storage_account.main.primary_blob_endpoint
storage_account_access_key = azurerm_storage_account.main.primary_access_key
storage_account_access_key_is_secondary = false
retention_in_days = 6
}
resource "azurerm_mssql_server" "secondary" {
name = "sqlserver-jadams-example-secondary"
resource_group_name = azurerm_resource_group.main.name
location = var.secondary_location
version = "12.0"
administrator_login = "missadministrator"
administrator_login_password = "AdminPassword123!"
}
resource "azurerm_mssql_database" "secondary" {
name = "db-secondary"
server_id = azurerm_mssql_server.secondary.id
create_mode = "Secondary"
creation_source_database_id = azurerm_mssql_database.main.id
} |
Yeah that is basically how I have it all set up. Also like to note, even before importing the audit policy, I still got the same error. That is why I ended up importing it to see if it would resolve the issue. |
I can't reproduce it with configuration like above, I'm not even allowed to change the auditing policy on the secondary. There must be something missing..! When I add this to the configuration above, I get an error:
Error: But I cannot import it and then change this resource, it errors out on the change. Final attempt is done by adding Unless you've new information, this issue is not reproducible and works as expected at my side. |
Oh. I see both my databases have the same exact name but just on separate servers. One being "sql-server-main" next being "gr-sql-server-main". Both databases are named "database". Would this have any effect here? |
That wouldn't effect any of this. |
Okay one final update. I added my almost exact configuration. Its a bit complex but maybe will help determine what I did wrong. Perhaps its attempting to do something I am not aware of? Because as I said, the plan only attempts to update tags as expected here. Edit: Added the audit policy block as well for the main server-1 database. |
So I found this commit and I see the intended behavior. If its marked as secondary create mode then it throws this error. Which I am sure is intended when creating or destroying a resource. But what if I am attempting to manage an imported resource? I originally imported these resources using the above root/module structure. The extended audit policy using "Storage" is the thing causing the error. Also, when I do a Also, sorry for all the confusion. |
So, to summarise/rephrase your problem:
I'm pretty sure we can fix this one way or another! I'll check your resource setup and push a possible fix, or explain how you can modify your state. |
Yup that is exactly it! Thank you so much for all the help! |
Found it, fix is submitted! It didn't depend on the import in the end, it depends on the behavior of the API which seems changed. It is also affecting non-imported secondary databases updates. |
Thanks a bunch! Really appreciate it. |
@jadamsHCBB Thanks for your patience as well! I almost gave up tbh, proud we've nailed it together👍🏽 |
This functionality has been released in v2.82.0 of the Terraform Provider. Please see the Terraform documentation on provider versioning or reach out if you need any assistance upgrading. For further feature requests or bug reports with this functionality, please create a new GitHub issue following the template. Thank you! |
I'm going to lock this issue because it has been closed for 30 days ⏳. This helps our maintainers find and focus on the active issues. |
Error output:
Error: cannot configure "extended_auditing_policy" in secondary create mode for Database: (Name "database" / Server Name "sql_server" / Resource Group "resource_group") │ │ with module.sql-server.azurerm_mssql_database.main["database"], │ on ../../modules/sql-server/main.tf line 30, in resource "azurerm_mssql_database" "main": │ 30: resource "azurerm_mssql_database" "main" {
Community Note
Terraform (and AzureRM Provider) Version
Affected Resource(s)
azurerm_mssql_database
Terraform Configuration Files
Server-1 Root
Server-2 Root
SQL-Server Module
Debug Output
Panic Output
Expected Behaviour
Per the Terraform Plan, the only thing that should change are some tags on apply. (Plan looks clean).
Actual Behaviour
When I run an apply, I get the above error.
Steps to Reproduce
Configure Terraform for Azure SQL Databases
Extended Audit policy is configured outside of Terraform
Import extended_audit_policy for said database
terraform apply
error above
Important Factoids
References
The text was updated successfully, but these errors were encountered: