Server Bug Fix: Parameter parsing when using AWS SSM send-command from Terraform

Original Source Link

I am using AWS SSM send-command to run a PowerShell script on an AWS instance.

The following commanad works fine in a command shell but when called in Terraform gets an error.

aws ssm send-command –instance-ids ${} –document-name AWS->RunPowerShellScript –parameters commands=’C:Installersbootstrap_test.ps1 >test’

when called in Terraform using:

provisioner “local-exec” {
command = “aws ssm send-command –instance-ids ${} –document-name AWS-RunPowerShellScript –parameters commands=’C:Installersbootstrap_test.ps1 test’ –output-s3-bucket-name ellucian-ecrm-lab –output-s3-key-prefix bootstraplogs”

The error returned is:

exit status 255. Output: usage: aws [options] [ …] [parameters]
To see help text, you can run:

aws help
aws help
aws help

Unknown options: test’

So I don’t thing Terraform is parsing the string the way AWS needs it. what can I do to format this string correctly in Terraform?

Try by double quoting the commands, e.g.:

... --parameters commands='"C:Installersbootstrap_test.ps1 > test"'

Here is the example with the loop:

aws ssm send-command --instance-ids "i-01234" --document-name "AWS-RunPowerShellScript" --query "Command.CommandId" --output text --parameters commands='"While ($i -le 100) {$i; $i += 1}"'

Or the opposite, e.g.

--parameters commands="'While ($i -le 100) {$i; $i += 1}'"

Tagged : /

Leave a Reply

Your email address will not be published. Required fields are marked *