klothoplatform / klotho

Klotho - write AWS applications at lightning speed
https://klo.dev
Apache License 2.0
1.12k stars 38 forks source link

Construct Template Enhancements #993

Closed DavidSeptimus-Klotho closed 3 weeks ago

DavidSeptimus-Klotho commented 4 weeks ago

This PR make substantial enhancements to construct templates

Features

Interpolation enhancements

prop1: '{{ toUpper .Inputs.Input1 }}'
prop2: '${inputs:Input1}-{{ .Inputs.Input1 }}-${resources:[{{ .Inputs.Name }}]}'
prop3: '{{ if .Inputs.ReadOnly }}readonly{{ else }}readwrite{{ end }}'

Input rule enhancements

input_rules:
  - for_each: '{{ .Select "inputs.Routes" }}'
    prefix: '{{ toLower (replace `[^\w]` "-"  .Selected.Value.Path) }}'
    do:
      resources:
        ...
input_rules:
  - if: {{ .Inputs.SomeBool }}
    then:
      resources:
        Resource1:
        ...
      rules:
        - for_each: {{ .Select "inputs.DependentInput" }}
          do: ...

Structured Inputs

Structured inputs are now supported using the same syntax as resource template properties. Notably, model inputs are not available and resource refs (e.g. resource:Id#property are not supported)

No validation enhancements were made to this functionality -- that will be a separate effort, so most validation declared in templates is still ignored.

Inputs:
  HeathCheck:
    type: map
    properties:
      Protocol:
        type: string
        required: true
        allowed_values:
          - TCP
          - UDP
          - HTTPS
          - HTTP
      Port:
        type: int
        default_value: 80
      Path:
        type: string
        default_value: /health