Running a python script in terraform as external data source and recieving invalid JSON Errors

I am executing an extermal python script and on its execution terraform is throwing " Program: /usr/bin/python3.9
Result Error: json: cannot unmarshal object into Go value of type string" while parsing the below JSON Object:

result_data = {
‘a’: {
‘vpcblock’: {
‘vpcBlock’: ‘’,
‘pub1’: ‘’,
‘pub2’: ‘’,
‘pri1’: ‘’,
‘pri2’: ‘’,
‘availabilityZones’: {
‘az1’: ‘us-east-1a’,
‘az2’: ‘us-east-1b’

How can I pass complex JSON output produced by a program further.

Hi @mehakt99,

This error seems to arise because your availabilityZones property has an object rather than a string, and this data source supports only strings.

You would therefore need to either correct the output to match what the data source requires, or to use a different data source that has behavior that better suits what you are trying to do.

One way to make this work within the requirements of the existing data source is to set availabilityZones to a string containing a JSON representation of your nested object – that is, a JSON string containing a nested JSON document – and then use the jsondecode function elsewhere in your module to recover that underlying data structure. Encoding JSON inside other JSON is an unusual thing to do, but would work to pass nested data structures through this data source despite it not being designed to support that.