如何确保永久执行存储帐户 Azure 策略的诊断设置?

How to ensure the diagnostic settings for storage accounts Azure policy is permanently enforced?

在一项可观察性计划的过程中,我想确保所有 Azure 存储帐户始终登录到一个特定的分析工作区。

我尝试通过分配 Azure 策略(“将存储帐户的诊断设置配置到 Log Analytics 工作区”)并创建修复任务来实现此目的。这导致整个订阅和所有存储帐户根据需要登录到同一工作区的一致“诊断设置”

我已经使用 terraform 分配策略和创建补救任务。这都类似于此处描述的解决方案:

遗憾的是,在初始创建后对诊断设置进行手动更改既不会被阻止也不会得到补救,尽管它们会被检测到并作为问题出现在“合规性”选项卡中。

如何确保 “将存储帐户的诊断设置配置到 Log Analytics 工作区” 策略永久执行?

我在我的环境中尝试了同样的方法,但它看起来很复杂或不可能。据我所知,也如本文所述Github Issue, It is not possible to remediate the existing resources automatically.For diagnostics settings as it has deployifnotexists effect, only the new resources get automatically remediated and existing resources have to be remediated manually or by PowerShell or CLI 脚本.

因此,要自动修复,您可以运行计划脚本使用 Task Schedulers or Cron Jobs or use .