3

我正在尝试使用新的 Azure 自动化插件(https://docs.microsoft.com/en-us/azure/automation/automation-solution-vm-management)将机器设置为自动启动/停止这是由 Terraform 设置的。

我可以创建自动化帐户,但我不知道如何创建启停功能,有人可以帮忙填空吗?

4

2 回答 2

2

AzureRM 提供程序可以管理运行手册的各个方面。如果您在此处查看文档。使用 azurerm_automation_runbook 和 azurerm_automation_schedule 可以创建和计划运行手册。Microsoft 解决方案需要运行手册上的参数,我在提供程序中看不到任何属性来添加参数,因此这可能是不可能的。

于 2018-10-07T17:57:11.027 回答
0

您可以在此资源提供程序“azurerm_automation_job_schedule”中传递所需的参数。请注意以下代码中的 Parameters 属性,这是我们传递所需参数的方式。您可以参考此链接了解更多详情。https://registry.terraform.io/providers/hashicorp/azurerm/latest/docs/resources/automation_job_schedule

resource "azurerm_automation_job_schedule" "startvm_sched" {
  resource_group_name     = "IndraTestRG"
  automation_account_name = "testautomation"
  schedule_name           = azurerm_automation_schedule.scheduledstartvm.name
  runbook_name            = azurerm_automation_runbook.startstopvmrunbook.name
   parameters = {
    action        = "Start"
  }
  depends_on = [azurerm_automation_schedule.scheduledstartvm]
}

以下是 VM 启动/停止作业计划资源提供程序“azurerm_automation_schedule”和“azurerm_automation_job_schedule”的完整代码

resource "azurerm_automation_schedule" "scheduledstartvm" {
  name                    = "StartVM"
  resource_group_name     = "IndraTestRG"
  automation_account_name = "testautomation"
  frequency               = "Day"
  interval                = 1
  timezone                = "America/Chicago"
  start_time              = "2021-09-20T13:00:00Z"
  description             = "Run every day"
}

resource "azurerm_automation_job_schedule" "startvm_sched" {
  resource_group_name     = "IndraTestRG"
  automation_account_name = "testautomation"
  schedule_name           = azurerm_automation_schedule.scheduledstartvm.name
  runbook_name            = azurerm_automation_runbook.startstopvmrunbook.name
   parameters = {
    action        = "Start"
  }
  depends_on = [azurerm_automation_schedule.scheduledstartvm]
}

resource "azurerm_automation_schedule" "scheduledstopvm" {
  name                    = "StopVM"
  resource_group_name     = "IndraTestRG"
  automation_account_name = "testautomation"
  frequency               = "Day"
  interval                = 1
  timezone                = "America/Chicago"
  start_time              = "2021-09-20T10:30:00Z"
  description             = "Run every day"
}

resource "azurerm_automation_job_schedule" "stopvm_sched" {
  resource_group_name     = "IndraTestRG"
  automation_account_name = "testautomation"
  schedule_name           = azurerm_automation_schedule.scheduledstopvm.name
  runbook_name            = azurerm_automation_runbook.startstopvmrunbook.name
  parameters = {
    action        = "Stop"
  }
  depends_on = [azurerm_automation_schedule.scheduledstopvm]
}
于 2021-09-21T06:45:29.907 回答