-
I'm working with PKL and Cloudformation and I'm really happy with how easy PKL makes it to make slight customisations on a base solution. However, I'm trying to work out how to model Cloudformation intrinsic functions in a way that would allow the YAML renderer to work. I'm happy to write custom renderers - I'm just not sure of the best approach. So how would I model in PKL something like:
Where for a PKL class like:
Here I'm doing a simple version where "!Sub" is on a single line, but to create the multi-line example above would require another structure that I'm not quite sure how to construct. |
Beta Was this translation helpful? Give feedback.
Replies: 1 comment 2 replies
-
This snippet is a YAML explicit tag, followed by a seq: !Sub
- String
- Var1Name: Var1Value
Var2Name: Var2Value Right now, our YAML renderer doesn't support directly rendering YAML explicit tags (although you can do whatever you want with a RenderDirective). So, the better option for Pkl is to render the something like the first snippet, because this is a regular map, where the key is "Fn::Sub", and the value is a seq. The first snippet can be represented in Pkl like so: `Fn::Sub` {
"String"
new {
["Var1Name"] = "Var1Value"
["Var2Name"] = "Var2Value"
}
} By the way, a pattern you can use here is to define a class that uses a fixed property to define the output, and top-level properties as input parameters: class Sub {
/// The value to be substituted
hidden value: String
/// Key-value pairs of things to be substituted by CloudFormation.
hidden params: Mapping<String, Any>?
fixed `Fn::Sub` = new Listing {
value
when (params != null) {
params
}
}
} Then usage like so: InstanceSecurityGroup {
Type = "AWS::EC2::SecurityGroup"
Properties {
GroupDescription = new Sub { value = "SSH security group for ${AWS::StackName}" }
}
} This produces: InstanceSecurityGroup:
Type: AWS::EC2::SecurityGroup
Properties:
GroupDescription:
Fn::Sub:
- SSH security group for ${AWS::StackName} Also: are you aware of Rain? It's a tool created by AWS for CloudFormation, and they already have support for Pkl, thanks to @ericzbeard. Might be worth trying that out! |
Beta Was this translation helpful? Give feedback.
This snippet is a YAML explicit tag, followed by a seq:
Right now, our YAML renderer doesn't support directly rendering YAML explicit tags (although you can do whatever you want with a RenderDirective).
So, the better option for Pkl is to render the something like the first snippet, because this is a regular map, where the key is "Fn::Sub", and the value is a seq.
The first snippet can be represented in Pkl like so:
By the way, a pattern you can use here is to define a class that uses a fixed property to define the output, and t…