如何使用Terraform将powershell命令传递给AWS SSM文档/运行命令



我正试图利用AWS RunPowerShellScript SSM文档并通过它传递一个命令,以便在Windows EC2实例上运行。我很难弄清楚如何将下面的命令传递给Terraform。

命令powershell.exe -ExecutionPolicy Bypass -file "C:aws1-start-ebs-snapshot.ps1"

我需要使用下面的SSM文档在EC2实例上运行该命令。

resource "aws_ssm_document" "run_powershell_cmd" {
name          = "AWS-RunPowerShellScript"
document_type = "Command"
}

以下对我有效:

resource aws_ssm_document run_powershell_cmd {
name          = "run_powershell_cmd"
document_type = "Command"
content = <<DOC
{
"schemaVersion": "1.2",
"description": "execute pwsh command",
"parameters": {
},
"runtimeConfig": {
"aws:runPowerShellScript": {
"properties": [
{
"id": "0.aws:runPowerShellScript",
"runCommand": ["powershell.exe -ExecutionPolicy Bypass -file 'C:\aws\1-start-ebs-snapshot.ps1'"]
}
]
}
}
}
DOC
}

最新更新