简体   繁体   English

如何使用 Terraform 的 aws_ssm_document 在目标 VM 上运行 powershell 脚本

[英]How can I run a powershell script on a target VM using Terraform's aws_ssm_document

How can I run a powershell script on a target VM using Terraform's aws_ssm_document?如何使用 Terraform 的 aws_ssm_document 在目标 VM 上运行 powershell 脚本? AWS has AWS-RunPowerShellScript in what looks like a aws_ssm_document command using the portal. AWS 在使用门户的 aws_ssm_document 命令中具有AWS-RunPowerShellScript It would be ideal if I could create/run this aws_ssm_document using a powershell script and the Terraform file function.如果我可以使用 powershell 脚本和 Terraform 文件 function 创建/运行此 aws_ssm_document,那将是理想的。

The AWS-RunPowerShellScript document is available, so it should be possible to use the aws_ssm_document passing json, to create a document and aws_ssm_association to apply the document to a VM. 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": []
    }
}

I need an example using AWS-RunPowerShellScript in Terraform.我需要一个在 Terraform 中使用AWS-RunPowerShellScript的示例。

You can't execute any SSM run commands from terraform natively.您无法从 terraform 本地执行任何 SSM 运行命令。 This is not supported :不受支持

Instead, you can use local-exec to execute AWS CLI's send-command .相反,您可以使用local-exec来执行 AWS CLI 的send-command The other possibility is AWS SDK to do same, but using a lambda function with aws_lambda_invocation .另一种可能性是 AWS SDK 做同样的事情,但使用 lambda function 和aws_lambda_invocation

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 如何使用 Terraform 将 powershell 命令传递给 AWS SSM 文档/运行命令? - How to pass a powershell command to AWS SSM Document/Run Command using Terraform? AWS SSM RunCommand - RunRemoteScript 文档出现问题,以使用参数运行 PowerShell 脚本 - AWS SSM RunCommand - Issue with RunRemoteScript Document to run PowerShell script with parameters 如何使用 Terraform 创建 AWS SSM 文档 Package - How to create an AWS SSM Document Package using Terraform 如何从AWS SSM文档中正确引用Powershell脚本? - How do I properly reference a Powershell script from an AWS SSM document? 使用 terraform,无法将 SSM 文档添加到 aws_cloudwatch_event_target - Using terraform, unable to add SSM document to aws_cloudwatch_event_target 如何使用 Terraform 在 AWS SSM 参数中存储三元素元组? - How can I store a three element tuple in AWS SSM parameter with Terraform? 如何使用 Terraform 传递 AssumeRole 并将 SSM 文档与 EC2 关联 - How to pass AssumeRole and associate SSM Document with EC2 using Terraform 如何每天执行 AWS SSM 自动化文档脚本? - How to execute AWS SSM automation document script daily? 我在哪里/如何在 AWS SSM 自动化文档中定义 NotificationConfig? - Where/how do I define a NotificationConfig in an AWS SSM Automation document? 如何使用 CloudFormation 创建具有 DocumentType 包的“AWS::SSM::Document” - How to create an 'AWS::SSM::Document' with DocumentType of Package using CloudFormation
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM