Reputation: 5048
How can I run a powershell script on a target VM using Terraform's aws_ssm_document ? AWS has AWS-RunPowerShellScript in what looks like a aws_ssm_document command using the portal. It would be ideal if I could create/run this aws_ssm_document using a powershell script and the Terraform file function.
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.
{
"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.
Upvotes: 0
Views: 1466
Reputation: 238837
You can't execute any SSM run commands from terraform natively. This is not supported:
Instead, you can use local-exec to execute AWS CLI's send-command. The other possibility is AWS SDK to do same, but using a lambda function with aws_lambda_invocation.
Upvotes: 2