【问题标题】:How can I run a powershell script on a target VM using Terraform's aws_ssm_document如何使用 Terraform 的 aws_ssm_document 在目标 VM 上运行 powershell 脚本
【发布时间】:2021-04-04 22:47:43
【问题描述】:

如何使用 Terraform 的 aws_ssm_document 在目标 VM 上运行 powershell 脚本? AWS 有 AWS-RunPowerShellScript,看起来像使用门户的 aws_ssm_document 命令。 如果我可以使用 powershell 脚本和 Terraform 文件函数创建/运行这个 aws_ssm_document,那将是理想的。

AWS-RunPowerShellScript 文档可用,因此应该可以使用 aws_ssm_document 传递 json 来创建文档和 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 的示例。

【问题讨论】:

    标签: amazon-web-services amazon-ec2 terraform


    【解决方案1】:

    您无法从 terraform 本地执行任何 SSM 运行命令。这是不支持

    相反,您可以使用 local-exec 来执行 AWS CLI 的 send-command。另一种可能性是 AWS SDK 也可以这样做,但使用带有 aws_lambda_invocation 的 lambda 函数。

    【讨论】:

      猜你喜欢
      • 2019-12-07
      • 2021-09-17
      • 1970-01-01
      • 1970-01-01
      • 2020-06-01
      • 2021-06-14
      • 2018-05-13
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多