【问题标题】:Import Azure Automation runbook using Terraform使用 Terraform 导入 Azure 自动化 Runbook
【发布时间】:2018-08-10 17:17:46
【问题描述】:

任何人都可以帮助我的问题:我想使用 Terraform 从运行手册库中导入 azure 自动化帐户中的运行手册。在下面的示例中,我引用了一个 URI,但我想从 Runbook 库导入:

  resource "azurerm_automation_runbook" "example" {
  name                = "Get-AzureVMTutorial"
  location            = "${azurerm_resource_group.example.location}"
  resource_group_name = "${azurerm_resource_group.example.name}"
  account_name        = "${azurerm_automation_account.example.name}"
  log_verbose         = "true"
  log_progress        = "true"
  description         = "This is an example runbook"
  runbook_type        = "PowerShellWorkflow"
  publish_content_link {
  uri = "${var.runbooklink}"
  }
  }`

【问题讨论】:

  • 有人可以帮我看看吗..

标签: azure terraform terraform-provider-azure azure-runbook


【解决方案1】:

在门户中

自动化帐户 -> Runbooks -> 浏览库 -> 选择要导入的 Runbooks -> 查看源项目

复制网址

查看源代码项目将重定向到该特定 Runbook 的 URI(gallery.technet.microsoft.com 中的源代码)

对于上面的图片(例如 hello world for azure runbook ),它会将 URI 重定向到我

https://gallery.technet.microsoft.com/scriptcenter/The-Hello-World-of-Windows-81b69574/file/111354/1/Write-HelloWorld.ps1

尝试将其粘贴到您的代码中 (uri = "${var.runbooklink}")

resource "azurerm_automation_runbook" "demorunbook" {
  name                = "Write-HelloWorld"
  location            = "${azurerm_resource_group.development1.location}"
  resource_group_name = "${azurerm_resource_group.development1.name}"
  account_name        = "automationAccount1"
  log_verbose         = "true"
  log_progress        = "true"
  description         = "This is an example runbook"
  runbook_type        = "PowerShellWorkflow"
  publish_content_link {
  uri = "https://gallery.technet.microsoft.com/scriptcenter/The-Hello-World-of-Windows-81b69574/file/111354/1/Write-HelloWorld.ps1"
  }
  }

注意源代码中的 Runbook 名称应为您的 Runbook 名称的名称

【讨论】:

  • 您好 Jayendran,感谢您的回复。我将添加您提到的 URI,名称下会有什么:在我上面给出的代码中:name = "Get-AzureVMTutorial"
  • 我使用了 Uri 中的链接:gallery.technet.microsoft.com/scriptcenter/… 并在名称下输入了 Scheduled-Virtual-Machine-2162ac63 ..... 运行时出现错误:azurerm_automation_runbook.example:automation.RunbookClient#获取:响应请求失败:StatusCode=404 -- 原始错误:autorest/azure:服务返回错误。 Status=404 Code="ResourceNotFound" Message="找不到资源组 'TestRG' 下的资源 'Microsoft.Automation/automationAccounts/Testaccount/runbooks/Scheduled-Virtual-Machine-2162ac63'。"
  • @alok 很抱歉造成混淆,我已经更新了上面的答案。这对我来说很好。该名称应该是您尝试导入的 Runbook 的名称,并且 uri 应该包含实际的 .ps1 文件
  • 谢谢 jayendran,这行得通。你能告诉我如何在自动化帐户下使用 terraform 将 azurerm 计划与运行手册链接
  • @alok 我不知道。但是,您可以跟进这个类似的 GitHub 问题 github.com/terraform-providers/terraform-provider-azurerm/…。同时,请接受我的回答/赞成,因为您当前的问题已解决
猜你喜欢
  • 2022-01-08
  • 2019-05-17
  • 1970-01-01
  • 2018-08-30
  • 1970-01-01
  • 2017-02-15
  • 1970-01-01
  • 2016-06-22
  • 1970-01-01
相关资源
最近更新 更多