terraform provider your segment does not match

This is a generic error and can happy for different resource that you're trying to provision. especially thoes that requires segment aka /subscriptions/123456/resourceGroup/my-rg pattern.

In my case, trying to provision azurerm_mssql_database_extended_auditing_policy and i bump into this error:-  

Error: parsing "/subscriptions/subscription/resourceGroups/your-rg/providers/Microsoft.Sql/servers/sqlserver": parsing the SqlDatabase ID: the number of segments didn't match

* Segment 0 - this should be the literal value "subscriptions"
 * Segment 1 - this should be the UUID of the Azure Subscription
 * Segment 2 - this should be the literal value "resourceGroups"
 * Segment 3 - this should be the name of the Resource Group
 * Segment 4 - this should be the literal value "providers"
 * Segment 5 - this should be the name of the Resource Provider [for example 'Microsoft.Sql']
 * Segment 6 - this should be the literal value "servers"
 * Segment 7 - this should be the user specified value for this server [for example "serverValue"]
 * Segment 8 - this should be the literal value "databases"
 * Segment 9 - this should be the user specified value for this database [for example "databaseValue"]


This is the sample code below under 'azurerm_mssql_database_extended_auditing_policy'' instead  of database id, a database server id is. 

resource "azurerm_mssql_server" "example" {
  name                         = "example-sqlserver"
  resource_group_name          = azurerm_resource_group.example.name
  location                     = azurerm_resource_group.example.location
  version                      = "12.0"
  administrator_login          = "missadministrator"
  administrator_login_password = "AdminPassword123!"
}

resource "azurerm_mssql_database" "example" {
  name      = "example-db"
  server_id = azurerm_mssql_server.example.id
}

# wrong database_id subscription  given
resource "azurerm_mssql_database_extended_auditing_policy" "example" {
  database_id                             = azurerm_mssql_server.example.id
  storage_endpoint                        = azurerm_storage_account.example.primary_blob_endpoint
  storage_account_access_key              = azurerm_storage_account.example.primary_access_key
  storage_account_access_key_is_secondary = false
  retention_in_days                       = 6
}
## corrected
resource "azurerm_mssql_database_extended_auditing_policy" "example" {
  database_id                             = azurerm_mssql_database.example.id
  storage_endpoint                        = azurerm_storage_account.example.primary_blob_endpoint
  storage_account_access_key              = azurerm_storage_account.example.primary_access_key
  storage_account_access_key_is_secondary = false
  retention_in_days                       = 6
}

The fix is quite easy, just replace server id with database id. 




Comments

Popular posts from this blog

The specified initialization vector (IV) does not match the block size for this algorithm

NodeJS: Error: spawn EINVAL in window for node version 20.20 and 18.20