You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
The expected behavior for a terraform plan is to see the IP ranges that are pulled from the bash script.
Actual Behavior
Refreshing Terraform state in-memory prior to plan...
The refreshed state will be used to calculate this plan, but will not be
persisted to local or remote state storage.
data.external.bless-bastions: Refreshing state...
Error: command "bash" produced invalid JSON: json: cannot unmarshal array into Go value of type string
Steps to Reproduce
terraform apply
References
I've seen a couple of closed issues similar to this, but none specially cover the use case of ingesting a JSON array as the data source's result. Instead I've seen people trying to provide an array to the external script.
The text was updated successfully, but these errors were encountered:
I have a very similar use case. I needed to return a list of objects. Here was my solution to this problem; utilizing a base64 result.
The first thing I needed to do was return my result from the script in a format acceptable to the external data source.
i.e.
{"key": "value"}
For my solution, I returned the json object base64 encoded as the value of the external data source result. Giving me something like this.
{"base64": "eyJuYW1lIjogImpvbiJ9Cg=="}
And then in terraform we can use base64decode() and jsondecode() on the result with a local variable and use our json result without a problem.
Using your example, it would look something like this:
# bastion-ips.sh# Query for the addresses
IPV4_ADDRESSES=$(curl -s "${URL_IPV4}"| jq '[.SomeKey[] | .Address]')
IPV6_ADDRESSES=$(curl -s "${URL_IPV6}"| jq '[.SomeKey[] | .Address]')# Output the addresses for terraform# get the raw output from jq and base64 encode it;
base64_result=$(jq -r -n \ --argjson ipv4 "${IPV4_ADDRESSES}" \ --argjson ipv6 "${IPV6_ADDRESSES}" \'{"ipv4":$ipv4,"ipv6":$ipv6}'| base64 --wrap=0)# We need --wrap=0 here to prevent multi-line base64 output# Return KV output with value as base64 result of our json.
jq -c -n --arg base64_result "$base64_result"'{"base64": $base64_result}'
Terraform Version
Affected Resource(s)
Terraform Configuration Files
Given the following Terraform:
and the following redacted script snippet:
And the script's output (with actual ranges redacted):
Expected Behavior
The expected behavior for a
terraform plan
is to see the IP ranges that are pulled from the bash script.Actual Behavior
Steps to Reproduce
terraform apply
References
I've seen a couple of closed issues similar to this, but none specially cover the use case of ingesting a JSON array as the data source's result. Instead I've seen people trying to provide an array to the external script.
The text was updated successfully, but these errors were encountered: