Skip to content

Instantly share code, notes, and snippets.

@Duologic
Created February 22, 2025 13:34
Show Gist options
  • Save Duologic/ee63b0aa2786f356ee3d074b3b6d7c96 to your computer and use it in GitHub Desktop.
Save Duologic/ee63b0aa2786f356ee3d074b3b6d7c96 to your computer and use it in GitHub Desktop.
Trying out different constructor options.
{
resource:: {
// 1: Render resource with manifest function
route53: {
new(name):
{
local this = self,
manifest(key=self.name):: {
resource+: {
route53+: {
[key]: this,
},
},
},
}
+ self.withName(name),
withName(name):
{ name: name },
withZoneId(zoneid):
{ zoneid: zoneid },
},
// 2: Render resource seperately
new(key, resource): {
resource+: {
[resource.type]+: {
[key]: resource,
},
},
},
s3: {
new(name):
{ type:: 's3' }
+ self.withName(name),
withName(name):
{ name: name },
withZoneId(zoneid):
{ zoneid: zoneid },
},
// 3: Render resource inline
ec2: {
new(key, name):
{
local this = self,
resource+: {
ec2+: {
[key]: this.spec,
},
},
spec:: {},
}
+ self.withName(name),
withName(name):
{ spec+: { name: name } },
withZoneId(zoneid):
{ spec+: { zoneid: zoneid } },
},
},
local resource = self.resource,
out:
// 1:
(
resource.route53.new('mydomain')
+ resource.route53.withZoneId(2000)
).manifest('mykey')
// 2:
+ resource.new(
'mykey',
resource.s3.new('mybucket')
+ resource.s3.withZoneId(1000)
)
// 3:
+ (
resource.ec2.new('mykey', 'myinstance')
+ resource.ec2.withZoneId(3000)
),
}.out
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment