我正在尝试在存储帐户下创建 blob 存储,该存储帐户创建得很好,但是当我尝试为其创建诊断设置时。它显示存储帐户为“已禁用”,blob 容器为“已启用”。我希望这两个都启用。请提出建议。
resource "azurerm_monitor_diagnostic_setting" "core-diagnostic" {
name = "readwrite${random_string.random.result}"
target_resource_id = "${azurerm_storage_account.core.id}/blobServices/default/"
log_analytics_workspace_id = azurerm_log_analytics_workspace.core.id
log {
category = "StorageRead"
enabled = true
}
log {
category = "StorageWrite"
enabled = true
}
metric {
category = "Transaction"
enabled = true
retention_policy {
days = 5
enabled = true
}
}
}
使用 TF 在 azurerm_monitor_diagnostic_setting 下创建 Blob 和存储帐户
出现您遇到的问题是因为指定的目标资源旨在专门接收 blob 的更改,而不是整个存储帐户的更改。
要在 Terraform 中为 blob 和存储帐户配置诊断设置,需要两个资源:一个将目标资源设置为 blob,另一个设置为存储帐户。
我的地形配置
provider "azurerm" {
features {}
}
provider "random" {
}
resource "random_string" "random" {
length = 8
special = false
upper = false
}
resource "azurerm_resource_group" "example" {
name = "testvk-rg"
location = "East US"
}
resource "azurerm_storage_account" "core" {
name = "storageacc${random_string.random.result}"
resource_group_name = azurerm_resource_group.example.name
location = azurerm_resource_group.example.location
account_tier = "Standard"
account_replication_type = "LRS"
}
resource "azurerm_log_analytics_workspace" "core" {
name = "logvk-loganalytics"
location = azurerm_resource_group.example.location
resource_group_name = azurerm_resource_group.example.name
sku = "PerGB2018"
}
resource "azurerm_monitor_diagnostic_setting" "blob-diagnostic" {
name = "diag${random_string.random.result}"
target_resource_id = "${azurerm_storage_account.core.id}/blobServices/default/"
log_analytics_workspace_id = azurerm_log_analytics_workspace.core.id
enabled_log {
category_group = "audit"
}
metric {
category = "Capacity"
enabled = true
}
}
resource "azurerm_monitor_diagnostic_setting" "acc-diagnostic" {
name = "diagstorage${random_string.random.result}"
target_resource_id = azurerm_storage_account.core.id
log_analytics_workspace_id = azurerm_log_analytics_workspace.core.id
metric {
category = "Transaction"
enabled = true
}
}
部署成功: