I have two resources azurerm_storage_account
and azurerm_cosmosdb_account
created in a resource group my-rg.
I also have a azurerm_management_lock
set to ReadOnly at my-rg level.
resource "azurerm_storage_account" "main" {
name = "my-storage"
resource_group_name = azurerm_resource_group.main.name
...
}
resource "azurerm_cosmosdb_account" "main" {
name = "my-cosmosdb"
resource_group_name = azurerm_resource_group.main.name
...
}
resource "azurerm_resource_group" "main" {
name = "my-rg"
...
}
resource "azurerm_management_lock" "resource-group-level" {
name = "terraform-managed-resources"
scope = azurerm_resource_group.main.id
lock_level = "ReadOnly"
}
When I run terraform apply
I run into that errors :
Error: [ERROR] Unable to List Write keys for CosmosDB Account "my-cosmosdb": documentdb.DatabaseAccountsClient#ListKeys: Failure sending request: StatusCode=409 -- Original Error: autorest/azure: Service returned an error. Status= Code="ScopeLocked" Message="The scope '/subscriptions/xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx/resourceGroups/my-rg/providers/Microsoft.DocumentDB/databaseAccounts/my-cosmosdb' cannot perform write operation because following scope(s) are locked: '/subscriptions/xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx/resourceGroups/my-rg'. Please remove the lock and try again."
Error: building Queues Client: retrieving Account Key: Listing Keys for Storage Account "my-storage" (Resource Group "my-rg"): storage.AccountsClient#ListKeys: Failure sending request: StatusCode=409 -- Original Error: autorest/azure: Service returned an error. Status= Code="ScopeLocked" Message="The scope '/subscriptions/xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx/resourceGroups/my-rg/providers/Microsoft.Storage/storageAccounts/my-storage' cannot perform write operation because following scope(s) are locked: '/subscriptions/xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx/resourceGroups/my-rg'. Please remove the lock and try again."
What should I do in order to allow terraform apply
to be run without removing the lock manually?
Note that this is a simplified example and I have many more resources that aren't impacted by this lock. I only have listed the resources involved in the Error log.