Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Escape for pulumi config set on Windows CMD and PowerShell #2062

Closed
guitarrapc opened this issue Dec 2, 2019 · 3 comments · Fixed by #2068
Closed

Escape for pulumi config set on Windows CMD and PowerShell #2062

guitarrapc opened this issue Dec 2, 2019 · 3 comments · Fixed by #2068
Assignees
Milestone

Comments

@guitarrapc
Copy link

TL;DR

pulumi config set data '{"active": true, "nums": [1,2,3]}' works on bash, but not on CMD and PowerShell.

CMD and PowerShell requires additional escape.

pulumi config set data "{""active"""": true, ""nums"""": [1,2,3]}"

Actual behavior

Document told pulumi config set data '{"active": true, "nums": [1,2,3]}' to set JSON to the config.

REF: https://www.pulumi.com/docs/intro/concepts/programming-model/#config

Running on Bash will set valid JSON to the config.

$ pulumi config set data '{"active": true, "nums": [1,2,3]}'
$ pulumi config
# result with bash
data         {"active": true, "nums": [1,2,3]}

However CMD will result error as follows.

CMD> pulumi config set data '{"active": true, "nums": [1,2,3]}'

Configuration values can be accessed when a stack is being deployed and used to configure behavior.
If a value is not present on the command line, pulumi will prompt for the value. Multi-line values
may be set by piping a file to standard in.

The `--path` flag can be used to set a value inside a map or list:

    - `pulumi config set --path outer.inner value` will set the value of `outer` to a map `inner: value`.
    - `pulumi config set --path names[0] a` will set the value to a list with the first item `a`.

Usage:
  pulumi config set <key> [value] [flags]

PowerShell will not return error, but register invalid JSON, as key missing double quote.

PS> pulumi config set data '{"active": true, "nums": [1,2,3]}'
PS> pulumi config
data         {active: true, nums: [1,2,3]}

Workaround

You need escape JSON key with additional double quote for both CMD and PowerShell.

  • begin: 2 double quote ""
  • end: 4 double quote """"

PowerShell's JSON string should be quote with ' for simplify problem. Double quote requires additional escape:(

CMD> pulumi config set data "{""active"""": true, ""nums"""": [1,2,3]}"
CMD> pulumi config
data         {"active": true, "nums": [1,2,3]}
PS> pulumi config set data '{""active"""": true, ""nums"""": [1,2,3]}'
PS> pulumi config
data         {"active": true, "nums": [1,2,3]}

Expected behavior

This may not a Pulumi problem but CMD and PowerShell shell design.
Additional note to a doc would be appreciated.

PowerShell argument would be fixable...?

@justinvp justinvp transferred this issue from pulumi/pulumi Dec 2, 2019
@justinvp
Copy link
Member

justinvp commented Dec 2, 2019

Thanks for letting us know about this @guitarrapc! Most of our command line snippets in the docs are for a Unix shell like bash, but we could certainly do a better job showing the equivalent PowerShell/CMD commands for Windows. I've transferred the issue to the docs repo.

Note that in this particular case, we have a new feature we recently added (and still need to document more prominently) that could help set this structured config data without having to specify it as JSON.

pulumi config set --path data.active true
pulumi config set --path data.nums[0] 1
pulumi config set --path data.nums[1] 2
pulumi config set --path data.nums[2] 3

@guitarrapc
Copy link
Author

thanks justinvp! New feature seems bririant!
YAML and structured access way like that is very useful.

@justinvp
Copy link
Member

justinvp commented Dec 2, 2019

I went ahead and updated this particular example to demonstrate the new structured config functionality: #2068

@justinvp justinvp self-assigned this Dec 2, 2019
@justinvp justinvp added this to the 0.30 milestone Dec 2, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants