首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >通过Terraform创建Azure自动化启动/停止解决方案

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

Stack Overflow用户
提问于 2018-10-05 00:16:18
回答 2查看 2.9K关注 0票数 3

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

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

EN

回答 2

Stack Overflow用户

发布于 2018-10-08 01:57:11

AzureRM提供程序可以管理runbooks的各个方面。如果您看过文档here。使用azurerm_automation_runbook和azurerm_automation_schedule,您可以创建和安排runbooks。Microsoft解决方案需要runbooks上的参数,我在提供程序中看不到任何用于添加参数的属性,因此这可能是不可能的。

票数 2
EN

Stack Overflow用户

发布于 2021-09-21 06:45:30

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

代码语言:javascript
复制
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”的完整代码

代码语言:javascript
复制
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]
}
票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/52651326

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档