I am trying to create a new Azure CosmosDB account in terraform account using:
create_mode = "Restore"
Basically I am trying to restore from an existing DB, and the code needs another input attribute, of the source DB:
"source_cosmosdb_account_id" = "/subscriptions/33f91226-e87e-4cdf67a1dae4e/providers/Microsoft.DocumentDB/locations/westeu/restorableDatabaseAccounts/test-source-db-name"
I am following the format indicated by the docs:
The example is /subscriptions/{subscriptionId}/providers/Microsoft.DocumentDB/locations/{location}/restorableDatabaseAccounts/{restorableDatabaseAccountName}
However when I apply the code, I get the following error:
Code="BadRequest" Message="Failed to parse uri
/subscriptions/33f91226-e87e-4ca1dae4e/providers/Microsoft.DocumentDB/locations/westeu/restorableDatabaseAccounts/test-source-db-name
The issue seems to be the way I write the location inside the source ID, but I can’t find any relevant info on how is the correct way.
I would really appreciate an example of source_cosmosdb_account_id if anyone did this successfully in terraform.
Thanks
Configuration used:
backup = [
{
type = "Continuous"
interval_in_minutes = null
retention_in_hours = null
storage_redundancy = null
}
]
restore = [
{
"source_cosmosdb_account_id" = "/subscriptions/33f6-e87e-4cdf-9480-7b1dae/providers/Microsoft.DocumentDB/locations/westeu/restorableDatabaseAccounts/test-source-db-name"
"restore_timestamp_in_utc" = "2022-11-18T14:00:00.00Z"
"database" = []
}
]
2
Answers
I tried to reproduce the issue in my environment.
I got the same error ,
Failed to parse uri /subscriptions/xxxx/providers/Microsoft.DocumentDB/locations/westeu/restorableDatabaseAccounts/test-source-db-name
with:
If I tried with
westeu
as the location you gave , in my case I am getting below error , as it must be westeurope as supported by azure .Also please check
azure portal , powershell,Azure CLI , ARM template
as in restore-account-continuous-backup | Microsoft LearnWith
azurerm
provider , i can only read it through below with continuous backup type :Output:
Try checking the same with azapi_resource block in terraform :
as it requires parameters like api version , source account id which has to come from cosmosdb_restorable_database_accounts
list and must form uri like
https://management.azure.com/subscriptions/subid/providers/Microsoft.DocumentDB/locations/West US/restorableDatabaseAccounts/d9b2xxx10d?api-version=2022-05-15
which is compatible in api resource.I’ve recently faced same issue and discovered that terraform documentation is outdated.
You need to have create_mode = "Restore"
Backup should be configured like this
Format
/subscriptions/{subscriptionId}/providers/Microsoft.DocumentDB/locations/{location}/restorableDatabaseAccounts/{restorableDatabaseAccountName}
is not correct
Try with
/subscriptions/{subscriptionId}/providers/Microsoft.DocumentDB/locations/{location}/restorableDatabaseAccounts/{**instanceId**}
You can find cosmos instanceId in json view