大佬教程收集整理的这篇文章主要介绍了使用 terraform 为现有虚拟机启用 Azure Monitor,大佬教程大佬觉得挺不错的,现在分享给大家,也给大家做个参考。
要在现有 Vm 上启用 VMinsights,您需要拥有 VM 的数据源,然后部署存储帐户、日志分析工作区、日志分析解决方案、VM 操作系统的日志分析代理和操作系统的依赖代理虚拟机。
provider "azurerm" {
features {}
}
data "azurerm_virtual_machine" "example" {
name = "test1"
resource_group_name = "testgroup"# where your VM resides in your subscription
}
output "virtual_machine_id" {
value = data.azurerm_virtual_machine.example.id
}
resource "azurerm_storage_account" "main" {
name = "vminsightstest1234"
resource_group_name = data.azurerm_virtual_machine.example.resource_group_name # where your VM resides in your subscription
LOCATIOn = data.azurerm_virtual_machine.example.LOCATIOn # which region your VM resides
account_tier = "Standard"
account_Replication_type = "GRS"
}
resource "azurerm_log_analytics_workspace" "LAW" {
name = "vminsights-logAnalytics"
LOCATIOn = data.azurerm_virtual_machine.example.LOCATIOn #which region your VM resides
resource_group_name = data.azurerm_virtual_machine.example.resource_group_name # where your VM resides in your subscription
sku = "PerGB2018"
retention_in_days = 30
}
resource "azurerm_log_analytics_solution" "example" {
solution_name = "ContainerInsights"
LOCATIOn = data.azurerm_virtual_machine.example.LOCATIOn # which region your VM resides
resource_group_name = data.azurerm_virtual_machine.example.resource_group_name # where your VM resides in your subscription
workspace_resource_id = azurerm_log_analytics_workspace.LAW.id
workspace_name = azurerm_log_analytics_workspace.LAW.name
plan {
publisher = "Microsoft"
product = "OMSGallery/ContainerInsights"
}
}
# Agent for Linux
resource "azurerm_virtual_machine_extension" "OMS" {
name = "test-OMSExtension"
virtual_machine_id = data.azurerm_virtual_machine.example.id
publisher = "Microsoft.EnterpriseCloud.Monitoring"
type = "OmsAgentForLinux"
type_handler_version = "1.13"
auto_upgrade_minor_version = true
setTings = <<SETTinGS
{
"workspacEID" : "${azurerm_log_analytics_workspace.LAW.workspace_iD}"
}
SETTinGS
protected_setTings = <<PROTECTED_SETTinGS
{
"workspaceKey" : "${azurerm_log_analytics_workspace.LAW.priMary_shared_key}"
}
PROTECTED_SETTinGS
}
# Dependency Agent for Linux
resource "azurerm_virtual_machine_extension" "da" {
name = "DAExtension"
virtual_machine_id = data.azurerm_virtual_machine.example.id
publisher = "Microsoft.Azure.Monitoring.DependencyAgent"
type = "DependencyAgentLinux"
type_handler_version = "9.5"
auto_upgrade_minor_version = true
}
#Agent for Windows
resource "azurerm_virtual_machine_extension" "MMA" {
name = "test-MMAextension"
virtual_machine_id = data.azurerm_virtual_machine.example.id
publisher = "Microsoft.EnterpriseCloud.Monitoring"
type = "MicrosoftMonitoringAgent"
type_handler_version = "1.0"
auto_upgrade_minor_version = true
setTings = <<SETTinGS
{
"workspacEID" : "${azurerm_log_analytics_workspace.LAW.workspace_iD}"
}
SETTinGS
protected_setTings = <<PROTECTED_SETTinGS
{
"workspaceKey" : "${azurerm_log_analytics_workspace.LAW.priMary_shared_key}"
}
PROTECTED_SETTinGS
}
# Dependency Agent for Windows
resource "azurerm_virtual_machine_extension" "da" {
name = "DAExtension"
virtual_machine_id = data.azurerm_virtual_machine.example.id
publisher = "Microsoft.Azure.Monitoring.DependencyAgent"
type = "DependencyAgentWindows"
type_handler_version = "9.5"
auto_upgrade_minor_version = true
}
注意:根据您的操作系统要求添加监控代理和依赖代理。
我在实验室中为我创建的 Windows VM 测试了上述代码。
以上是大佬教程为你收集整理的使用 terraform 为现有虚拟机启用 Azure Monitor全部内容,希望文章能够帮你解决使用 terraform 为现有虚拟机启用 Azure Monitor所遇到的程序开发问题。
如果觉得大佬教程网站内容还不错,欢迎将大佬教程推荐给程序员好友。
本图文内容来源于网友网络收集整理提供,作为学习参考使用,版权属于原作者。
如您有任何意见或建议可联系处理。小编QQ:384754419,请注明来意。