hashicorp / terraform-provider-azurerm

Terraform provider for Azure Resource Manager
https://registry.terraform.io/providers/hashicorp/azurerm/latest/docs
Mozilla Public License 2.0
4.6k stars 4.65k forks source link

Migrate from deprecated extended_auditing_policy to azurerm_mssql_server_extended_auditing_policy is not working #13903

Closed MelleD closed 3 years ago

MelleD commented 3 years ago

Community Note

Terraform (and AzureRM Provider) Version

2.82.0

Affected Resource(s)

Terraform Configuration Files

Try to migrate from

resource "azurerm_mssql_server" "sql_server" {
  extended_auditing_policy {
    log_monitoring_enabled                  = true
  }
}

to

resource "azurerm_mssql_server" "sql_server" {

}

resource "azurerm_mssql_server_extended_auditing_policy" "sql_server_policy" {
server_id                               = azurerm_mssql_server.sql_server.id
log_monitoring_enabled                  = true
}

Expected Behaviour

Inline block is removed and new resource is created.

Actual Behaviour

Inline block have to removed manually in state file.

see https://github.com/hashicorp/terraform-provider-azurerm/issues/9170

/extendedAuditingSettings/Default\" already exists - to be managed via Terraform this resource needs to be imported into the State. Please see the resource documentation for \"azurerm_mssql_server_extended_auditing_policy\"

aristosvo commented 3 years ago

Hi @MelleD, in the documentation this is already explained:

The Server Extended Auditing Policy Can be set inline here as well as with the mssql_server_extended_auditing_policy resource resource. You can only use one or the other and using both will cause a conflict.

When both the inline removal and the creation of the new resource is done in the same run, this causes conflict. I believe this is the problem you are facing here, could that be possible?

It's not that big of a deal, but could you please close your older issues or limit your journey to one issue, to improve handling a bit? Thanks in advance!

MelleD commented 3 years ago

Yes that's the issue. Then i will try it with 2 runs, good option. Thanks :)

MelleD commented 3 years ago

@aristosvo it's not working: The first run don't destroy/remove the inline block. I removed the inline block:

    "No changes. Your infrastructure matches the configuration.", 
    "", 
    "Terraform has compared your real infrastructure against your configuration", 
    "and found no differences, so no changes are needed."
aristosvo commented 3 years ago

Sorry! Can you try extended_auditing_policy = []/extended_auditing_policy []? This should signal it should remove the setting at all. I'm not behind my desk so don't know which of the two it is, but one of these should work😬

MelleD commented 3 years ago

Ok let's try :)

MelleD commented 3 years ago

extended_auditing_policy = [] is working. Thanks :)

github-actions[bot] commented 2 years ago

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. If you have found a problem that seems similar to this, please open a new issue and complete the issue template so we can capture all the details necessary to investigate further.