'unable to upload multiple runbook files to the azure automation account using terraform

I have created azure automation account with the help of terraform and I have existing runbook PowerShell scripts which I need to import to azure automation account. I am trying for-each loop in the terraform to upload multiple scripts at time but it is not working:

Code:

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}")
}

while executing the terraform it is not showing any errors but it is not importing all the scripts which is there in my local. Please suggest me how I can import multiple PowerShell script files to upload to Azure automation account.



Solution 1:[1]

We can use code like this to solve your issue.

for_each = fileset("Azure_Runbooks/", "*")

above fileset syntax will import all the script files to azure automation account.

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1 rootShiv