org-formation / org-formation-cli

Better than landingzones!
MIT License
1.41k stars 131 forks source link

Feature request: !StringJson function #473

Open zaro0508 opened 1 year ago

zaro0508 commented 1 year ago

Subject

I would like a function that's the opposite of !JsonString to support my use cases. The general use case is to convert a string to a json object then pass it to a cloudformation or TemplatingContext parameter.

Use cases

These use cases are derived from the Templating context example in the docs:

Read ports in from a file, convert the string to a json list object and then pass it to the ports parameter:

SecurityGroupExample:
  Type: update-stacks
  Template: ./security-group.njk
  StackName: SecurityGroupExample
  Parameter:
    ports: !StringJson 
      - !Readfile "ports.json"

Get data from a REST API endpoint, convert the string to a json dictionary object and then pass it to the hounds TemplatingContext parameter:

DogsExample:
  Type: update-stacks
  Template: ./dogs.njk
  StackName: DogsExample
  TemplatingContext:
    hounds: !StringJson 
      - !Cmd "wget -qO-  https://dog.ceo/api/breed/hound/list"
OlafConijn commented 1 year ago

have you tried:

SecurityGroupExample:
  Type: update-stacks
  Template: ./security-group.njk
  StackName: SecurityGroupExample
  Parameter:
    ports: !Include "ports.json"

I dont think this will help with the !Cmd "wget -qO- https://dog.ceo/api/breed/hound/list" though....

zaro0508 commented 1 year ago

I have not tried !Include in that context @OlafConijn. I will investigate that.

I dont think this will help with the !Cmd "wget -qO- https://dog.ceo/api/breed/hound/list" though....

If !Cmd doesn't work then how about a new org-formation !Request function would basically do a "curl -X GET https://dog.ceo/api/breed/hound/list"? This is how it would work..

Get data from a REST API endpoint, convert the string to a json dictionary object and then pass it to the hounds TemplatingContext parameter:

DogsExample:
  Type: update-stacks
  Template: ./dogs.njk
  StackName: DogsExample
  TemplatingContext:
    hounds: !StringJson 
      - !Request "https://dog.ceo/api/breed/hound/list"