Closed xiangyx closed 6 months ago
Hello,
While we are waiting for someone to take a look at this issue, today we tried doing a deployment to our production environment using Terraform after restoring the staging environment manually. Still, Terraform tried to delete the workspace without warning in the execution plan, as we saw on the staging posted above. Thankfully, this issue did not happen because we removed the delete permissions for the service principal on our production Log Analytics workspace before the trial.
Here is a digest of the Terraform plan
Nothing in the above should change the Log Analytics workspace.
The error messages we got are:
╷
│ Error: removing items provisioned by this Template Deployment: deleting Nested Resource "/subscriptions/***/resourceGroups/Sentinel/providers/Microsoft.OperationalInsights/workspaces/sentinel": resources.Client#DeleteByID: Failure sending request: StatusCode=403 -- Original Error: Code="AuthorizationFailed" Message="The client '***-***-***' with object id '***-***-***' does not have authorization to perform action 'Microsoft.OperationalInsights/workspaces/delete' over scope '/subscriptions/***/resourceGroups/Sentinel/providers/Microsoft.OperationalInsights/workspaces/sentinel' or the scope is invalid. If access was recently granted, please refresh your credentials."
│
│
╵
╷
│ Error: removing items provisioned by this Template Deployment: deleting Nested Resource "/subscriptions/***/resourceGroups/Sentinel/providers/Microsoft.OperationalInsights/workspaces/sentinel": resources.Client#DeleteByID: Failure sending request: StatusCode=403 -- Original Error: Code="AuthorizationFailed" Message="The client '***-***-***' with object id '***-***-***' does not have authorization to perform action 'Microsoft.OperationalInsights/workspaces/delete' over scope '/subscriptions/***/resourceGroups/Sentinel/providers/Microsoft.OperationalInsights/workspaces/sentinel' or the scope is invalid. If access was recently granted, please refresh your credentials."
│
│
╵
╷
│ Error: removing items provisioned by this Template Deployment: deleting Nested Resource "/subscriptions/***/resourceGroups/Sentinel/providers/Microsoft.OperationalInsights/workspaces/sentinel": resources.Client#DeleteByID: Failure sending request: StatusCode=403 -- Original Error: Code="AuthorizationFailed" Message="The client '***-***-***' with object id '***-***-***' does not have authorization to perform action 'Microsoft.OperationalInsights/workspaces/delete' over scope '/subscriptions/***/resourceGroups/Sentinel/providers/Microsoft.OperationalInsights/workspaces/sentinel' or the scope is invalid. If access was recently granted, please refresh your credentials."
│
│
╵
╷
│ Error: removing items provisioned by this Template Deployment: deleting Nested Resource "/subscriptions/***/resourceGroups/Sentinel/providers/Microsoft.OperationalInsights/workspaces/sentinel": resources.Client#DeleteByID: Failure sending request: StatusCode=403 -- Original Error: Code="AuthorizationFailed" Message="The client '***-***-***' with object id '***-***-***' does not have authorization to perform action 'Microsoft.OperationalInsights/workspaces/delete' over scope '/subscriptions/***/resourceGroups/Sentinel/providers/Microsoft.OperationalInsights/workspaces/sentinel' or the scope is invalid. If access was recently granted, please refresh your credentials."
│
│
╵
╷
│ Error: removing items provisioned by this Template Deployment: deleting Nested Resource "/subscriptions/***/resourceGroups/Sentinel/providers/Microsoft.OperationalInsights/workspaces/sentinel": resources.Client#DeleteByID: Failure sending request: StatusCode=403 -- Original Error: Code="AuthorizationFailed" Message="The client '***-***-***' with object id '***-***-***' does not have authorization to perform action 'Microsoft.OperationalInsights/workspaces/delete' over scope '/subscriptions/***/resourceGroups/Sentinel/providers/Microsoft.OperationalInsights/workspaces/sentinel' or the scope is invalid. If access was recently granted, please refresh your credentials."
│
│
╵
Again, we really want to know why and how Terraform tries to delete the workspace, and very much look forward to hearing anything on this issue.
We have discovered the root cause of this issue -
We were using deployment template(azurerm_resource_group_template_deployment
) to deploy log-parsers which had the Log Analytics workspace as nested resource and when that was deleted it also assumed it should delete everything contained in that template when it has the feature delete_nested_items_during_deletion=true
in the azurerm
provider.
To prevent the issue, set the flag to false
.
Thank everyone for taking the time to look into this issue!
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.
Is there an existing issue for this?
Community Note
Terraform Version
1.3.9
AzureRM Provider Version
3.100.0
Affected Resource(s)/Data Source(s)
azurerm_log_analytics_workspace; azurerm_log_analytics_solution
Terraform Configuration Files
Debug Output/Panic Output
Expected Behaviour
We expect only the parser and saved query to be deleted in a normal cleanup task, and the Log Analytics workspace and the Sentinel workspace on top it run as usual.
Deployments prior to this failure, in order from earliest to most recent, were
azurerm
from 3.99.0 to 3.100.0, successActual Behaviour
The Log Analysis workspace and the Sentinel workspace above it were both deleted, even though we had set the "prevent_destory = true" protection block in both resources.
Steps to Reproduce
We tried to reproduce the issue by simulating the deployment histories in the following steps:
azurerm
from version 3.99.0 to 3.100.0, runterraform init -upgrade
azurerm_resource_group_template_deployment.parser
andazurerm_log_analytics_query_pack_query.example
, then deploy byterraform apply
Unfortunately, the issue somehow did not get reproduced and it made us more worried about our current setup of using Terraform to manage our Sentinel infrastructure, as the consequence of the workspace getting deleted is terrible when this change is not present in the execution plan and bypasses protection layers. Therefore, by reporting on this issue, we want to learn more about the potential causes and recommendations for preventing such cases.
Important Factoids
No response
References
No response