azure - 如何从本地和天蓝色的 terraform 在天蓝色中执行 PowerShell 文件
问题描述
我想从本地和天蓝色的 terraform 执行存储在 Azure 存储帐户上的 PowerShell 文件。
我在我的 terraform 脚本中包含了配置程序来执行 PowerShell 文件
resource "azurerm_automation_account" "my_acc" {
name = "AUT-ACCOUNT-586"
location = "${azurerm_resource_group.rg_obj.location}"
resource_group_name = "${azurerm_resource_group.rg_obj.name}"
sku_name = "Basic"
provisioner "local-exec" {
command = "http://${azurerm_storage_account.storageaccount.name}.blob.core.windows.net/${azurerm_storage_container.blobstorage.name}/Import-PowerShell-Modules.ps1"
interpreter = ["PowerShell","-Command"]
}
}
我希望 PowerShell 文件能够被执行。
输出为 术语“ http://MyStorage.blob.core.windows.net/scripts/Import-PowerShell-Modules.ps1 ”未被识别为 cmdlet、函数、脚本文件或可运行程序的名称。检查名称的拼写,或者如果包含路径,请验证路径是否正确并重试。在 line:1 char:1 + http://MyStorage.blob.core.windows.net/scripts/Import-PowerShell ... + ~~~~~~~~~~~~~~~~~~~ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ + CategoryInfo : ObjectNotFound: ( http://MyStorage...ell-Modules.ps1:String ) [], CommandNotFoundException + FullyQualifiedErrorId : CommandNotFoundException。收到错误。
解决方案
您收到的错误意味着您在 local-exec 配置程序中使用的命令不是 PowerShell 命令。
执行本地存储的 PowerShell 脚本。您可以使用如下代码:
provisioner "local-exec" {
command = "powershell -file ./test.ps1"
}
您可以使用文件的相对路径或绝对路径。命令powershell -file
在这里显示:
-File Runs the specified script in the local scope ("dot-sourced"), so that the functions and variables that the script creates are available in the current session. Enter the script file path and any parameters. File must be the last parameter in the command, because all characters typed after the File parameter name are interpreted as the script file path followed by the script parameters.
所以我建议如果你想执行存储在 Azure 存储帐户中的 PowerShell 脚本,你最好下载脚本或在本地创建一个脚本来下载脚本的内容并执行它。
推荐阅读
- sql - OBIEE-如何显示所选日期的最后 4 个星期日的数据
- ios - 我可以在 UIScrollView (Swift) 中实现弹性图像标题吗?
- python - 在 N 个带有 N 个参数的数组上调用 func.outer
- sql-server - 从其他表中的数据和用户定义的约束条件创建表
- database - NoSQL 中的数据库聚合是什么?
- javascript - VUE 组件中的 Javascript 变量
- arrays - 如何在kotlin中的地图内添加列表
- php - 简单的 HTML DOM - 如何通过包含 TD 文本来获取特定的 TR
- angular - Angular (7) 组件只接受 html 文件
- nginx - 通过 nginx 作为代理连接到 AWS Neptune 服务器