code: def terraform_external_data(function):
      
      @wraps(function)
      def wrapper(*args, **kwargs):
          query = json.loads(sys.stdin.read())
          validate(query)
          try:
              result = function(query, *args, **kwargs)
          except Exception as e:
              # Terraform wants one-line errors so we catch all exceptions and trim down to just the message (no trace).
              error('{}: {}'.format(type(e).__name__, e))
          validate(result)
          sys.stdout.write(json.dumps(result))
      return wrapper
docs: Query data is received on stdin as a JSON object.
      Result data must be returned on stdout as a JSON object.
  
      The wrapped function must expect its first positional argument to be a dictionary of the query data.