external data source with a ruby script

397 views
Skip to first unread message

Vikas Kumar

unread,
Feb 27, 2017, 12:58:22 AM2/27/17
to Terraform
Hey All,

This link shows how to use vars passed by external data source in a bash script.

#!/bin/bash
eval "$(jq -r '@sh "FOO=\(.foo) BAZ=\(.baz)"')"


What would be the ruby equivalent of this?

Cheers,
Vikas

David Adams

unread,
Feb 27, 2017, 11:03:53 AM2/27/17
to terrafo...@googlegroups.com
All that bash is doing is reading in the query values into variables, though since bash doesn't know JSON natively, it's convoluted.

In Ruby it would be more straightforward:

    #!/usr/bin/env ruby
    require 'json'
    data = JSON.parse(STDIN.read)

Then if the vars passed were `foo` and `bar`, they would be available to ruby as `data['foo']` and `data['bar']`.

--
This mailing list is governed under the HashiCorp Community Guidelines - https://www.hashicorp.com/community-guidelines.html. Behavior in violation of those guidelines may result in your removal from this mailing list.
 
GitHub Issues: https://github.com/hashicorp/terraform/issues
IRC: #terraform-tool on Freenode
---
You received this message because you are subscribed to the Google Groups "Terraform" group.
To unsubscribe from this group and stop receiving emails from it, send an email to terraform-tool+unsubscribe@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/terraform-tool/54f60a88-fb7e-441e-a316-2798811390d0%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Vikas Kumar

unread,
Feb 27, 2017, 4:58:18 PM2/27/17
to Terraform
Perfect !!

Thanks a ton David. I am not very well versed with Ruby, but growing steadily :)

Cheers,
Vikas


On Tuesday, 28 February 2017 03:03:53 UTC+11, David Adams wrote:
All that bash is doing is reading in the query values into variables, though since bash doesn't know JSON natively, it's convoluted.

In Ruby it would be more straightforward:

    #!/usr/bin/env ruby
    require 'json'
    data = JSON.parse(STDIN.read)

Then if the vars passed were `foo` and `bar`, they would be available to ruby as `data['foo']` and `data['bar']`.
On Sun, Feb 26, 2017 at 11:58 PM, Vikas Kumar <vika...@gmail.com> wrote:
Hey All,

This link shows how to use vars passed by external data source in a bash script.

#!/bin/bash
eval "$(jq -r '@sh "FOO=\(.foo) BAZ=\(.baz)"')"


What would be the ruby equivalent of this?

Cheers,
Vikas

--
This mailing list is governed under the HashiCorp Community Guidelines - https://www.hashicorp.com/community-guidelines.html. Behavior in violation of those guidelines may result in your removal from this mailing list.
 
GitHub Issues: https://github.com/hashicorp/terraform/issues
IRC: #terraform-tool on Freenode
---
You received this message because you are subscribed to the Google Groups "Terraform" group.
To unsubscribe from this group and stop receiving emails from it, send an email to terraform-too...@googlegroups.com.
Reply all
Reply to author
Forward
0 new messages