Skip to content

Instantly share code, notes, and snippets.

@davexunit
Last active November 30, 2018 17:28
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save davexunit/db4b9d3e67902216fbdbc66cd9c6413e to your computer and use it in GitHub Desktop.
Save davexunit/db4b9d3e67902216fbdbc66cd9c6413e to your computer and use it in GitHub Desktop.
Functional, declarative CloudFormation template generation with Scheme - https://git.dthompson.us/guile-cloudformation.git
(use-modules (aws cloudformation)
(aws cloudformation ec2)
(aws cloudformation s3)
(aws cloudformation utils json)
(oop goops))
(define security-group
(make <security-group>
#:id 'security-group
#:group-description "CFN Test"
#:vpc-id "vpc-redacted"
#:security-group-egress (list
(make <security-group/egress>
#:ip-protocol "tcp"
#:cidr-ip "0.0.0.0/0"
#:from-port 22
#:to-port 22))
#:security-group-ingress (list
(make <security-group/ingress>
#:ip-protocol "tcp"
#:cidr-ip "0.0.0.0/0"
#:from-port 0
#:to-port 65535))))
(define ec2-instance
(make <instance>
#:id 'instance
#:image-id "ami-0bbe6b35405ecebdb"
#:key-name "dthompson"
#:instance-type "t3.nano"
#:security-group-ids (list security-group)
#:tags (list (make <tag> #:key "Name" #:value "CFN Test"))))
(define bucket
(make <bucket>
#:id 'bucket
#:bucket-name "foo.example.com"))
(define stack
(make <cloudformation-stack>
#:resources (list ec2-instance bucket)))
(write-json (to-json stack) (current-output-port))
(newline)
{
"AWSTemplateFormatVersion": "2010-09-09",
"Description": "",
"Resources": {
"InstanceREZCDF5WKEFG9SGFSCESS70T6ZSY2BMK": {
"Type": "AWS::EC2::Instance",
"Properties": {
"ImageId": "ami-0bbe6b35405ecebdb",
"InstanceType": "t3.nano",
"KeyName": "dthompson",
"SecurityGroupIds": [
{
"Ref": "SecurityGroup8X3C8Q24WAD2HQGP8XKPT1G7293NGWBQ"
}
],
"Tags": [
{
"Value": "CFN Test",
"Key": "Name"
}
]
}
},
"SecurityGroup8X3C8Q24WAD2HQGP8XKPT1G7293NGWBQ": {
"Type": "AWS::EC2::SecurityGroup",
"Properties": {
"GroupDescription": "CFN Test",
"SecurityGroupEgress": [
{
"CidrIp": "0.0.0.0/0",
"FromPort": 22,
"IpProtocol": "tcp",
"ToPort": 22
}
],
"SecurityGroupIngress": [
{
"CidrIp": "0.0.0.0/0",
"FromPort": 0,
"IpProtocol": "tcp",
"ToPort": 65535
}
],
"VpcId": "vpc-redacted"
}
},
"BucketG9XR4XPXK6MAJHDQ23AY3XYCPVCW76RP": {
"Type": "AWS::S3::Bucket",
"Properties": {
"BucketName": "foo.example.com"
}
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment