Azure Microsoft 监控代理无法使用 Terraform 进行预配

标签 azure terraform terraform-provider-azure

尝试使用 Terraform 安装 MMA 代理作为虚拟机部署的一部分。我确信失败是由于我正在使用的扩展的语法造成的,但我没有运气确定它应该是什么。代理会安装,但不会加入 Log Analytics 工作区。我将工作区 ID 和主键存储在 Key Vault 中,并在执行时将它们传递到 Terraform 中。从虚拟机上的扩展日志来看,它似乎正在获取正确的工作区 ID,但我无法判断它是否正确接收了 key 。以下是我使用的 Terraform 语法:

resource "azurerm_virtual_machine_extension" "lawks-test" {
  name = "MMA_${azurerm_virtual_machine.test.name}"
  location             = "${azurerm_resource_group.test.location}"
  resource_group_name  = "${azurerm_resource_group.test.name}"
  virtual_machine_name = "${azurerm_virtual_machine.test.name}"
  publisher            = "Microsoft.EnterpriseCloud.Monitoring"
  type                 = "MicrosoftMonitoringAgent"
  type_handler_version = "1.0"

  settings = <<SETTINGS
        {
          "workspaceId": "${data.terraform_remote_state.corerg.on_workspace_id}"
        }
        SETTINGS

  protected_settings = <<PROTECTED_SETTINGS
        {
          "workspaceKey": "${var.on_laws_key}"
        }
        PROTECTED_SETTINGS

下面是扩展日志文件之一中显示的内容:

11/19/2018 9:43:51 PM +00:00 Managed Service Identity extension (Microsoft.ManagedIdentity.ManagedIdentityExtensionForWindows) not found on this box, automaticManagement will be skipped on this box.
11/19/2018 9:43:51 PM +00:00 HandlerConfig found, default config will be override, CloudType changed to 1
11/19/2018 9:43:51 PM +00:00 GET http://169.254.169.254/metadata/instance?api-version=2017-08-01 with requestId 9a17250a-bfd0-4e4b-b9d3-aa4ceaf9007e
11/19/2018 9:43:52 PM +00:00 azureResourceId from metadata service.
11/19/2018 9:43:52 PM +00:00 automaticManagement not enabled.
11/19/2018 9:43:52 PM +00:00 systemWorkspace provision failed due to AutomaticManagementNotEnabled
11/19/2018 9:43:52 PM +00:00 only configSpecifiedWorkspace available.
11/19/2018 9:43:52 PM +00:00 SettingFile changed, re-apply configuration.
11/19/2018 9:43:52 PM +00:00 Adding workspace /subscriptions/<my_subscription_id>/resourcegroups/resource_group/providers/microsoft.operationalinsights/workspaces/my-workspace.
11/19/2018 9:43:53 PM +00:00 Unknown error during enable command : System.ArgumentException: Value does not fall within the expected range.
   at System.Dynamic.ComRuntimeHelpers.CheckThrowException(Int32 hresult, ExcepInfo& excepInfo, UInt32 argErr, String message)
   at CallSite.Target(Closure , CallSite , ComObject , String , String , Int32 )
   at System.Dynamic.UpdateDelegates.UpdateAndExecute4[T0,T1,T2,T3,TRet](CallSite site, T0 arg0, T1 arg1, T2 arg2, T3 arg3)
   at System.Dynamic.UpdateDelegates.UpdateAndExecuteVoid4[T0,T1,T2,T3](CallSite site, T0 arg0, T1 arg1, T2 arg2, T3 arg3)
   at Microsoft.EnterpriseCloud.Monitoring.MicrosoftMonitoringAgent.Extension.MMAConfigHelper.AddCloudWorkspace(String workspaceId, String workspaceKey, Nullable`1 cloudType)
   at Microsoft.EnterpriseCloud.Monitoring.MicrosoftMonitoringAgent.Extension.EnableProgram.Main(String[] args)

最佳答案

感谢各位的回复。我通过尝试手动安装发现了问题所在。 azurerm_log_analytics_workspace 资源有 2 个与 ID 相关的属性:

id - The Log Analytics Workspace ID

workspace_id - The Workspace (or Customer) ID for the Log Analytics Workspace

我错误地尝试使用“id”,这是错误的。一旦我使用了“workspace_id”属性,安装就可以正常工作...Terraform 代码的格式没有发生任何变化。

我经常发现 Terraform 缺乏的一件事是文档。

关于Azure Microsoft 监控代理无法使用 Terraform 进行预配,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/53395060/

相关文章:

powershell - Get-AzureLocation 未显示我的订阅有权访问的所有位置

azure - 地形 : How do I set the value of accessTokenAcceptedVersion to 2 for a Azure Service Principal?

Terraform 计划输出 : what is the encoding being used

Terraform 从 Packer 中制作的托管磁盘镜像创建 VM

azure - WinRM 与远程执行连接超时 - Azure Terraform

azure - 如何为 k8s 部署创建自定义 Azure 策略?

azure - 通过网络事件从 Azure 广告获取群组成员

azure - 有没有办法连接到 Azure SQL DB Premium 读取横向扩展中的特定只读副本?

python-3.x - 使用 Terraform remote-exec 运行简单的 Web 服务器

linux - 使用 python 脚本搜索 json 文件