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?

  • 1
    i managed to get aws command working by escaping the quotes using backslash "\" – krisdigitx Jun 20 '16 at 11:13
  • @krisdigitx Can you expand on this? I tried this approach but got this error: Error parsing parameter '--parameters': Expected: ',', received: '"' for input: – Pixel Elephant Jan 4 '17 at 19:01

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}'"

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.