Parameter parsing when using AWS SSM send-command from Terraform

aws-cliterraform

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 ${self.id} –document-name AWS->RunPowerShellScript –parameters commands='C:\Installers\bootstrap_test.ps1 >test'

when called in Terraform using:

provisioner "local-exec" {
command = "aws ssm send-command –instance-ids ${self.id} –document-name AWS-RunPowerShellScript –parameters commands='C:\Installers\bootstrap_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?

Best Answer

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

... --parameters commands='"C:\Installers\bootstrap_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}'"
Related Topic