简体   繁体   中英

azure runbook PowerShell script content is not importing in terraform properly

I have created azure automation account using terraform. I have save my existing runbook PowerShell script files in local. I have successfully uploaded all the script files at one time while creation of automation account with below code:

resource "azurerm_automation_runbook" "example" {
  for_each                = fileset("Azure_Runbooks/", "*")
  name                    = split(".", each.key)[0]
  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                 = file(format("%s%s", "Azure_Runbooks/", each.value)
} 

However, the content of the script file is not completely uploading and getting the error like below:

Error: Too many function arguments │ │ on AutomationAccount\main.tf line 58, in resource "azurerm_automation_runbook" "example": │ 58: content = file(format("%s%s"), "Azure_Runbooks/", each.value) │ ├──────────────── │ │ each.value will be known only after apply │ │ Function "file" expects only 1 argument(s)

Can some one please help to fix above issue.

Below is the correct code and I have fixed the issue:

resource "azurerm_automation_runbook" "example" {
  for_each                = fileset("Azure_Runbooks/", "*")
  name                    = split(".", each.key)[0]
  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                 = file(format("%s%s" , "Azure_Runbooks/" , each.key))
}

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM