Search code examples
cmdhashicorp-vault

Write a *nix command on Windows cmd prompt


I am trying to execute this *nix command found here on cmd prompt:

vault write aws/roles/my-role \
        credential_type=iam_user \
        policy_document=-<<EOF
{
  "Version": "2012-10-17",
  "Statement": [
    {
      "Sid": "Stmt1426528957000",
      "Effect": "Allow",
      "Action": [
        "ec2:*"
      ],
      "Resource": [
        "*"
      ]
    }
  ]
}
EOF

So far, i have tried different combinations/variations such as writing the command on a single line such as this:

C:\Users\user-name>vault write aws/roles/my-role credential_type=iam_user policy_document={"Version": "2012-10-17","Statement": [{"Sid": "Stmt1426528957000","Effect": "Allow","Action": ["ec2:*"],"Resource": ["*"]}]}
Failed to parse K=V data: invalid key/value pair "2012-10-17,Statement:": format must be key=value

or on multiple lines such as this:

C:\Users\user-name>vault write aws/roles/my-role ^
More? credential_type=iam_user ^
More? policy_document=-^<^<EOF ^
More? { ^
More? ^"Version^" : ^"2012-10-17^", ^
More? ^"Statement^" : [ ^
More? { ^
More? ^"Sid^" : ^"Stmt1426528957000^", ^
More? ^"Effect^" : ^"Allow^", ^
More? ^"Action^" : [ ^
More? ^"ec2:*^" ^
More? ], ^
More? ^"Resource^": [ ^
More? ^"*^" ^
More? ] ^
More? } ^
More? ] ^
More? } ^
More? EOF
Failed to parse K=V data: invalid key/value pair "{": format must be key=value

Note 1: It works on Git Bash, i am just curious how to get it to work on cmd prompt.

Note 2:

C:\Users\user-name>where vault
C:\ProgramData\chocolatey\bin\vault.exe

$ which vault
/c/ProgramData/chocolatey/bin/vault

Solution

  • in cmd this seemed to have worked:

    vault write aws/roles/test-role credential_type=iam_user policy_document={\"Version\":\"2012-10-17\",\"Statement\":[{\"Sid\":\"Stmt1426528957000\",\"Effect\":\"Allow\",\"Action\":[\"ec2:*\"],\"Resource\":[\"*\"]}]}
    

    Success! Data written to: aws/roles/test-role

    I've removed spaces from json, escaped every double quote character and put everything in one line.