通过 Terraform 创建 Azure 自动化启动/停止解决方案



我正在尝试使用新的 Azure 自动化加载项 (https://learn.microsoft.com/en-us/azure/automation/automation-solution-vm-management( 将计算机设置为自动启动/停止,并由 Terraform 设置。

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

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

可以在此资源提供程序"azurerm_automation_job_schedule"中传递所需的参数。请注意以下代码中的参数属性,这就是我们传递所需参数的方式。您可以参考此链接了解更多详情。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]
}

相关内容

最新更新