如何解决400错误:autorest/azure:服务返回错误,状态= 400代码="BadRequest"消息="不支持类别'StorageRead'

xpszyzbs  于 2023-06-24  发布在  其他
关注(0)|答案(2)|浏览(109)

我正在尝试为Azure中的存储帐户启用所有活动日志。这是代码块,这似乎是导致错误.

resource "azurerm_monitor_diagnostic_setting" "storage_account_logs" {
  name               = "storage-account-logs"
  target_resource_id = azurerm_storage_account.example.id
  storage_account_id = azurerm_storage_account.example.id

  enabled_log {
    category = "StorageRead"
    retention_policy {
      enabled = false
    }
  }
  enabled_log {
    category = "StorageWrite"
    retention_policy {
      enabled = false
    }
  }
  enabled_log {
    category = "StorageDelete"
    retention_policy {
      enabled = false
    }
  }
  metric {
    category = "AllMetrics"
    retention_policy {
      enabled = false
    }
  }
}

当我为StorageRead、StorageWrite或StorageDelete添加enabled_logs时,代码会出错。下面是我得到的错误:
错误:更新资源"/subscriptions//resourceGroups//providers/Microsoft. Storage/storageAccounts/"的监视器诊断设置"storage-account-logs":diagnosticsettings. DiagnosticSettingsClient #CreateOrUpdate:未能响应请求:StatusCode = 400--原始错误:autorest/azure:服务返回错误。Status = 400 Code ="BadRequest" Message ="Category 'StorageRead' is not supported." │ │ with azurerm_monitor_diagnostic_setting. storage_account_logs,│
在www.example.com第42行,在资源“azurerm_monitor_diagnostic_setting”“storage_account_logs”中:main.tf line 42, in resource "azurerm_monitor_diagnostic_setting" "storage_account_logs": │ 42: resource "azurerm_monitor_diagnostic_setting" "storage_account_logs" {

vawmfj5a

vawmfj5a1#

当我为StorageRead、StorageWrite或StorageDelete添加enabled_logs时,代码会出错。下面是我得到的错误:
我尝试使用Terraform启用存储帐户的诊断设置,但遇到了同样的错误。

为了启用StorageWrite,StorageRead and StorageDelete在存储帐户诊断设置.基本上,您可以在storage account中的storage account类型的不同级别创建诊断设置。

使用以下terraform代码启用存储帐户中的诊断设置。

provider "azurerm" {
   features{}
 }
 data "azurerm_storage_account" "venkatstorage" {
   name                = "venkatstoragetest"
   resource_group_name = "<resource_Name>"
 }
 resource "azurerm_monitor_diagnostic_setting" "storage_account_logs" {
   name               = "storage-account-logs"
   target_resource_id = azurerm_storage_account.venkatstoragetest.id
   storage_account_id = azurerm_storage_account.venkatstoragetest.id
   metric {
     category = "Transaction"
     retention_policy {
       enabled = false
     }
   }
 }

一旦启用存储帐户的诊断设置,然后启用特定资源(如blob)的度量。

provider "azurerm" {
  features{}
}
data "azurerm_storage_account" "venkatstorage" {
  name                = "venkatstoragetest"
  resource_group_name = "<resourcegroup>"
}

data "azurerm_log_analytics_workspace" "shakti-log-analytics" {
  name                = "shakti-log-analytics"
  resource_group_name = "shaktisingh-analytics"
}
 resource "azurerm_monitor_diagnostic_setting" "storage-account-logs" {
   name               = "storage-account-logs"
   target_resource_id = "${data.azurerm_storage_account.venkatstorage.id}/blobServices/default"
   log_analytics_workspace_id = data.azurerm_log_analytics_workspace.shakti-log-analytics.id
   log {
    category = "StorageRead"
    enabled  = true

    retention_policy {
      enabled = false
    }
   }
   
   log {
    category = "StorageWrite"
    enabled  = true

    retention_policy {
      enabled = false
    }
   }
   
   log {
    category = "StorageDelete"
    enabled  = true

    retention_policy {
      enabled = false
    }
   }

   metric {
     category = "Transaction"

     retention_policy {
       enabled = false
     }
   }
 }

Terraform申请:

bsxbgnwa

bsxbgnwa2#

如果我没有log_analytics_workspace,我将面临同样的问题。

相关问题