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

add try function in output #19

Closed
wants to merge 1 commit into from

Conversation

wad-hongsumin
Copy link

Exception handling so that it can be used even if there is no result

@wad-hongsumin wad-hongsumin changed the title Update main.tf add try function in output Jul 10, 2024
@rquadling
Copy link
Member

Hi. Thank you for this. Do you have an example where the AWS output is not valid JSON?

@rquadling
Copy link
Member

Also, if, somehow, there is content returned that is not valid JSON, would the value be enough to show?

Would this be a good option?

try(jsondecode(data.local_file.awscli_results_file.content), data.local_file.awscli_results_file.content)

@horststumpf
Copy link

Hi, the
"aws ec2 create-tags"
has no output.

@rquadling
Copy link
Member

@horststumpf Brilliant. Thank you for that.

@rquadling
Copy link
Member

I've introduced 2 new outputs.

output.result_raw = string and output.result_was_decoded = bool.

I suspect these may not be needed much, but rather than attempt to massage broken data, either the data COULD be decoded (and so you can use it), or it was not decoded and you can access the raw value and do your own manipulation as you see fit.

Hopefully that's enough to handle the "bad path" for invalid JSON.

v7.0.0 hopefully coming out today.

Also had to reduce the tests a little as I've not got a public target I can do any interactions with (read only of course).

@rquadling
Copy link
Member

Thank you @wad-hongsumin. I've incorporated your PR into v7.0.0 and added 2 new outputs to allow non JSON results from the AWS CLI to be accessible as a fallback.

@rquadling rquadling closed this Aug 6, 2024
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 this pull request may close these issues.

3 participants