Skip to content
/ cfnpkl Public

Write Cloud Formation templates using the Pkl configuration language

License

Notifications You must be signed in to change notification settings

masp/cfnpkl

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

4 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

cfnpkl

cfnpkl is bindings for the Pkl language to generate CloudFormation templates instead of using JSON or YAML. Pkl provides features like:

  • Type safety
  • Code completion
  • Support for reusing templates
  • Defining functions for transforming templates
  • Modeling inputs to templates instead of the clunk Ref syntax

Getting Started

Prerequisites

Create an S3 bucket template

PklProject

dependencies {
  ["cfn"] { uri = "package:/masp/cfnpkl" }
}

mybucket.pkl

import "@cfn/aws/s3/Bucket.pkl"

Resources {
    ["Bucket"] = new Bucket {
        Properties {
            BucketName = "mybucket"
            AccelerateConfiguration {
                AccelerationStatus = "Enabled"
            }
        }
    }
}

Running pkl eval mybucket.pkl -f json will generate the following CloudFormation template:

{
  "Resources": {
    "Bucket": {
      "Type": "AWS::S3::Bucket",
      "Properties": {
        "BucketName": "mybucket",
        "AccelerateConfiguration": {
          "AccelerationStatus": "Enabled"
        }
      }
    }
  }
}

You can also generate the output in YAML:

Resources:
  Bucket:
    Type: AWS::S3::Bucket
    Properties:
      BucketName: mybucket
      AccelerateConfiguration:
        AccelerationStatus: Enabled

cfnpkl can warn you ahead of time if there's a typo in a property name or if you're missing a required property:

test.pkl

Resources {
    ["Bucket"] = new Bucket {
        Properties {
            BucketName = "mybucket"
            AccelerateConfiguration {
                AccelerationStatus = "Enable" // ERROR: only "Enabled" or "Disabled" allowed!
            }
        }
    }
}

Output

> pkl eval -f json examples/bucket.pkl
–– Pkl Error ––
Expected value of type `"Enabled"|"Suspended"`, but got `"Enable"`.

65 | AccelerationStatus: "Enabled" | "Suspended"
                         ^^^^^^^^^^^^^^^^^^^^^^^

TODO

  • Add support for all standard AWS resource providers. See AWS Resource Types
  • Add support for inputs to templates and calculated values
  • Add examples of reusable templates
  • Add automated testing to verify all generated templates are correct and produce valid CloudFormation templates.

About

Write Cloud Formation templates using the Pkl configuration language

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published