如何在 terraform 中为 Azure Automatiuon 中的更新管理创建计划

问题描述

社区。 我正在尝试使用 terraform 在 Azure 自动化中自动化更新管理器,但我找不到有关以下 2 点的信息:

  1. 为更新创建的时间表不起作用。我认为问题在于缺少定义哪些机器需要更新等的运行手册。
  2. 找不到有关如何为特定资源组中的所有计算机自动启用此更新管理的信息。

这是我完成的 terraform 代码

#Creates automation account
resource "azurerm_automation_account" "aa" {
  name                = local.autoac
  location            = local.region
  resource_group_name = local.rg

  sku_name = "Basic"

  tags = {
    environment = "test"
  }
}

#Creates the schedule for updates
resource "azurerm_automation_schedule" "std-update" {
  name                    = "Weekly-Sunday-6am"
  resource_group_name     = local.rg
  automation_account_name = azurerm_automation_account.aa.name
  frequency               = "Week"
  interval                = 1
  timezone                = "Europe/Berlin"
  start_time              = "2021-04-28T18:00:15+02:00"
  description             = "Standard schedule for updates"
  week_days               = ["Sunday"]
}

#Creates log analitycs workspace 
resource "azurerm_log_analytics_workspace" "law" {
  name                = local.lawname
  location            = local.region
  resource_group_name = local.rg
  sku                 = "PerGB2018"
  retention_in_days   = 30

  tags = {
    environment = "test"
  }
}

# Link automation account to a Log Analytics Workspace.
resource "azurerm_log_analytics_linked_service" "autoacc_linked_log_workspace" {
  resource_group_name = local.rg
  workspace_id        = azurerm_log_analytics_workspace.law.id
  read_access_id      = azurerm_automation_account.aa.id
}

# Add Updates workspace solution to log analytics
resource "azurerm_log_analytics_solution" "law_solution_updates" {
  resource_group_name   = local.rg
  location              = local.region

  solution_name         = "Updates"
  workspace_resource_id = azurerm_log_analytics_workspace.law.id
  workspace_name        = azurerm_log_analytics_workspace.law.name

  plan {
    publisher = "Microsoft"
    product   = "OMSgallery/Updates"
  }
}

关于问题的更新。 我发现在更新管理中创建更新计划的选项在 terraform 中尚不可用。这就是为什么我们只需要从 terraform 配置中创建的 ARM 模板的方式来做到这一点。 在上一条评论的帮助下,我能够创建以下时间表:

#Creates schedule for windows VM to update Monthly on 3rd Sunday
 
resource "azurerm_template_deployment" "windows-prod-3rd-Sunday" {
      name                = "windows-prod-3rd-Sunday"
      resource_group_name = local.rg

      template_body = <<DEPLOY
      {
        "$schema": "https://schema.management.azure.com/schemas/2015-01-01/deploymentTemplate.json#","contentVersion": "1.0.0.0","resources": [
          {
              "apiVersion": "2017-05-15-preview","type": "Microsoft.Automation/automationAccounts/softwareUpdateConfigurations","name": "${azurerm_automation_account.aa.name}/windows-prod-3rd-Sunday","properties": {
                  "updateConfiguration": {
                      "operatingSystem": "Windows","duration": "PT${local.update_max_hours}H","windows": {
                          "excludedKbNumbers": [
                          ],"includedUpdateClassifications": "${local.update_classifications}","rebootSetting": "${local.update_reboot_settings}"
                      },"targets": {
                        "azureQueries": [
                          {
                            "scope": [
                              "/subscriptions/${local.subscriptionid}/resourceGroups/${local.rg}","/subscriptions/${local.subscriptionid}/resourceGroups/${local.rg}","/subscriptions/${local.subscriptionid}/resourceGroups/${local.rg}"
                            ],"tagSettings": {
                              "tags": {
                                "environment": [
                                  "Prod"
                                ],"updatedate": [
                                  "3rd_Sunday"
                                ]
                              },"filterOperator": "All"
                            },"locations": [
                              "West Europe"
                            ]
                          }
                        ]
                      }
                  },"scheduleInfo": {
                      "frequency": "Month","startTime": "${local.update_date}T${local.update_time}:00+00:00","timeZone":  "${local.update_timezone}","interval": 1,"advancedSchedule": {
                          "monthlyOccurrences": [
                              {
                                "occurrence": "${local.sunday_3}","day": "${local.update_day}"
                              }
                          ]
                      }
                  }
              }
          }
        ]
      }
DEPLOY

      deployment_mode = "Incremental"
    }

解决方法

暂无找到可以解决该程序问题的有效方法,小编努力寻找整理中!

如果你已经找到好的解决方法,欢迎将解决方案带上本链接一起发送给小编。

小编邮箱:dio#foxmail.com (将#修改为@)

相关问答

Selenium Web驱动程序和Java。元素在(x,y)点处不可单击。其...
Python-如何使用点“。” 访问字典成员?
Java 字符串是不可变的。到底是什么意思?
Java中的“ final”关键字如何工作?(我仍然可以修改对象。...
“loop:”在Java代码中。这是什么,为什么要编译?
java.lang.ClassNotFoundException:sun.jdbc.odbc.JdbcOdbc...