![](/img/trans.png)
[英]How to pass a powershell command to AWS SSM Document/Run Command using Terraform?
[英]How can I run a powershell script on a target VM using Terraform's aws_ssm_document
如何使用 Terraform 的 aws_ssm_document 在目標 VM 上運行 powershell 腳本? AWS 在使用門戶的 aws_ssm_document 命令中具有AWS-RunPowerShellScript 。 如果我可以使用 powershell 腳本和 Terraform 文件 function 創建/運行此 aws_ssm_document,那將是理想的。
AWS-RunPowerShellScript文檔可用,因此應該可以使用傳遞 json 的aws_ssm_document創建文檔並使用aws_ssm_association將文檔應用到 VM。
{
"Document": {
"Hash": "2142e42a19e0955cc09e43600bf2e633df1917b69d2be9693737dfd62e0fdf61",
"HashType": "Sha256",
"Name": "AWS-RunPowerShellScript",
"Owner": "Amazon",
"CreatedDate": "2017-08-31T16:52:31.357000-04:00",
"Status": "Active",
"DocumentVersion": "1",
"Description": "Run a PowerShell script or specify the paths to scripts to run.",
"Parameters": [
{
"Name": "commands",
"Type": "StringList",
"Description": "(Required) Specify the commands to run or the paths to existing scripts on the instance."
},
{
"Name": "workingDirectory",
"Type": "String",
"Description": "(Optional) The path to the working directory on your instance.",
"DefaultValue": ""
},
{
"Name": "executionTimeout",
"Type": "String",
"Description": "(Optional) The time in seconds for a command to be completed before it is considered to have failed. Default is 3600 (1 hour). Maximum is 172800 (48 hours).",
"DefaultValue": "3600"
}
],
"PlatformTypes": [
"Windows",
"Linux",
"MacOS"
],
"DocumentType": "Command",
"SchemaVersion": "1.2",
"LatestVersion": "1",
"DefaultVersion": "1",
"DocumentFormat": "JSON",
"Tags": []
}
}
我需要一個在 Terraform 中使用AWS-RunPowerShellScript的示例。
您無法從 terraform 本地執行任何 SSM 運行命令。 這不受支持:
相反,您可以使用local-exec來執行 AWS CLI 的send-command 。 另一種可能性是 AWS SDK 做同樣的事情,但使用 lambda function 和aws_lambda_invocation 。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.