Not able to create a virtual network rule when using azurerm_mssql_server

After deploying de new logical server with the option “public_network_access_enabled = true”, it seems not possible to add a virtual network rule. I use an additional code block for adding the virtual network rule as recommended by the documentation, but it fails.

Is there an option to include the creation of the network rule inside the de block of the server? Or is there an option to set public_network_access_enabled = false afterwards?

In that case i want to first create the logical server, then set the network rule and after that set “public_network_access_enabled to false”.

Code included below.

resource “azurerm_mssql_server” “sql_server_cdwh” {
name = server_name
resource_group_name = resorucegroupname
location = west europe
version = 12

public_network_access_enabled = false
}

resource “azurerm_mssql_virtual_network_rule” “sqldb_virtual_network_rule” {
name = virtual_network_rule_name
server_id = azurerm_mssql_server.sql_server_cdwh.id
subnet_id = data.azurerm_subnet.subnet_cf.id
}