Closed nitrocode closed 3 years ago
Hi @nitrocode, thanks for the feedback!
I've had similar thoughts in the past and experimented with them (e.g. in the context of looking at #14 and #15). The big blocker was that it's a lot harder to rewrite terraform code than JSON and there's a lot less library support for it :) If someone in the community has some experience parsing and manipulating terraform code, I'd be happy about some pointers or a call to get me started in the right direction.
To your specific points:
alias ijtt="iam-policy-json-to-terraform"
while true; do
echo "Copy policy json and hit ENTER"
read
pbpaste | iam-policy-json-to-terraform | pbcopy
done
This works for OS X, on Linux you'd need to replace pbcopy
and pbpaste
with xclip
and xsel
Maybe the easiest solution would be to prompt the user if there is an empty stdout.
$ iam-policy-json-to-terraform
No stdout was detected. Please paste json directly here.
(iam-policy-json-to-terraform) $ {"Statement":[{"Effect":"Allow","Action":["ec2:Describe*"],"Resource":"*"}]}
data "aws_iam_policy_document" "policy" {
statement {
sid = ""
effect = "Allow"
resources = ["*"]
actions = ["ec2:Describe*"]
}
}
$
Thanks for the idea - I tried this out just now in this commit - presenting a usage message if the STDIN is a terminal (indicating interactive usage). What do you think?
That seems nice and easy for the user. Thanks!
Released this in 1.8.0.
Closing this one since I think all the other thoughts in here are discussed or already covered in other issues (e.g #15 for rewriting entire terraform documents). If I missed anything, feel free to comment and remind me :)
@flosell am I doing this incorrectly ?
$ iam-policy-json-to-terraform
Paste a valid IAM policy and press the EOF afterwards.
Alternatively, you can pipe input directly into the command.
> {"Statement":[{"Effect":"Allow","Action":["ec2:Describe*"],"Resource":"*"}]}
EOF
^C
Oh, with EOF I mean the end-of-file character, not the actual EOF
string.
Should be CTRL-d on Mac and Linux, CTRL-z on windows.
Ah ok that worked for me! Could you also allow it so all it works by simply clicking enter? The EOF wasn't intuitive for me.
Also sometimes, I want to run the command multiple times. If I hit enter and it dumped out the valid terraform code and showed the >
prompt again until I did a CTRL-c, that would be convenient.
It would also be nice to document the CTRL-d portion.
$ iam-policy-json-to-terraform
Paste a valid IAM policy and press the EOF afterwards.
Alternatively, you can pipe input directly into the command.
Press enter to translate and re-enter the prompt.
Press CTRL + d on OSX or Linux and CTRL + z on Windows to translate and exit the prompt.
Press CTRL + c to exit the prompt.
> {"Statement":[{"Effect":"Allow","Action":["ec2:Describe*"],"Resource":"*"}]}
data "aws_iam_policy_document" "policy" {
statement {
sid = ""
effect = "Allow"
resources = ["*"]
actions = ["ec2:Describe*"]
}
}
(I pressed enter so it translated the above and re-entered the prompt)
> {"Statement":[{"Effect":"Deny","Action":["ec2:Describe*"],"Resource":"*"}]}
data "aws_iam_policy_document" "policy" {
statement {
sid = ""
effect = "Deny"
resources = ["*"]
actions = ["ec2:Describe*"]
}
}
But no biggie. Thanks again for adding the above change and showing me how it works.
I often use vscode to update terraform. When I see json, I usually have to copy the json to my clipboard, open my terminal, and begin with the following command.
Then hit enter, paste from my clipboard, hit enter, type
EOF
, and hit enter again.It's a bit painful but I've done it so many times that I've almost stopped forgetting the order of the hyphenated command (was it policy then json or json then policy?).
Here are some suggestions to make this easier
Easier to remember command name
Perhaps using alias commands like
Would be interested in hearing the owner and community's thoughts on these. Thank you.