3

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?

Brian Walsh
  • 43
  • 1
  • 7
  • 1
    i managed to get aws command working by escaping the quotes using backslash "\" – krisdigitx Jun 20 '16 at 11:13
  • 1
    @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 04 '17 at 19:01
  • `--parameters commands="\"${COMMAND}\""` Where COMMAND is a double quoted string containing the actual command ie: `"C:\Installers\bootstrap_test.ps1 >test"`? – thoroc Jan 29 '20 at 15:57

1 Answers1

0

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}'"
kenorb
  • 5,943
  • 1
  • 44
  • 53