-
Notifications
You must be signed in to change notification settings - Fork 60
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
Proposals to make it easier to use #18
Comments
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 :) To your specific points:
|
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). |
That seems nice and easy for the user. Thanks! |
@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 |
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 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
vscode extension that could auto detect json and allow converting all or specific jsons to policy documents
A repl command where you can run the command without stdin and then paste the json to get the output
Easier to remember command name
Perhaps using alias commands like
Run command in a module and have it convert all json policies to data policy documents
Would be interested in hearing the owner and community's thoughts on these. Thank you.
The text was updated successfully, but these errors were encountered: