面对错误的Terraform代码,用于将多本运行本导入Azure Automation帐户

发布于 2025-01-24 21:54:40 字数 1147 浏览 4 评论 0原文

我使用Terraform代码创建了Azure自动化帐户。我有多个Runbooks Powershell脚本保存在我的本地中。我正在使用for.east选项一次导入所有运行簿。但是在运行Terraform文件时,我会遇到一些错误。请在下面找到我的代码:

resource "azurerm_automation_runbook" "example" {
  for_each = fileset(".", "./Azure_Runbooks/*.ps1")
  name                    = ["${split("/", each.value)}"][1]
  location                = var.location
  resource_group_name     = var.resource_group
  automation_account_name = azurerm_automation_account.example.name
  log_verbose             = var.log_verbose
  log_progress            = var.log_progress
  runbook_type            = var.runbooktype
  content                 = filemd5("${each.value}")
}

Error:

Error: Invalid index
│
│   on AutomationAccount\main.tf line 51, in resource "azurerm_automation_runbook" "example":
│   51:   name                    = ["${split("/", each.value)}"][1]
│     ├────────────────
│     │ each.value will be known only after apply
│
│ The given key does not identify an element in this collection value: the given index is greater than   
│ or equal to the length of the collection.

有人可以帮助我如何使用Terraform代码上传所有现有的Runbook scrips到新创建的自动化帐户。

I have created the azure automation account using terraform code. I have multiple runbooks PowerShell scripts saved in my local. I am using for.each option to import all the runbooks at a time. But I am getting some errors while running the terraform file. Please find my code below:

resource "azurerm_automation_runbook" "example" {
  for_each = fileset(".", "./Azure_Runbooks/*.ps1")
  name                    = ["${split("/", each.value)}"][1]
  location                = var.location
  resource_group_name     = var.resource_group
  automation_account_name = azurerm_automation_account.example.name
  log_verbose             = var.log_verbose
  log_progress            = var.log_progress
  runbook_type            = var.runbooktype
  content                 = filemd5("${each.value}")
}

Error:

Error: Invalid index
│
│   on AutomationAccount\main.tf line 51, in resource "azurerm_automation_runbook" "example":
│   51:   name                    = ["${split("/", each.value)}"][1]
│     ├────────────────
│     │ each.value will be known only after apply
│
│ The given key does not identify an element in this collection value: the given index is greater than   
│ or equal to the length of the collection.

Can someone please help how I can upload all my existing runbook scrips to the newly created automation account using terraform code.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

不奢求什么 2025-01-31 21:54:41

您不需要列表中的列表。所以

 name                    = ["${split("/", each.value)}"][1]

应该不是

 name                    = split("/", each.value)[1]

You don't need list in a list. So instead of

 name                    = ["${split("/", each.value)}"][1]

it should be

 name                    = split("/", each.value)[1]
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文