Skip to content

StuPro-TOSCAna/cloudformation-builder

 
 

Repository files navigation

cloudformation-builder

Build Status Codacy Badge codecov

CloudFormation-Builder is a Java 8 DSL for creating AWS CloudFormation templates.

Quick Start

Dependency

Use jitpack to import this project as a maven dependency.

<dependency>
    <groupId>com.github.StuPro-TOSCAna</groupId>
    <artifactId>cloudformation-builder</artifactId>
    <version>{releaseVersion/commitHash}</version>
</dependency>

Use a release version or simply the hash of a commit to specify the version.

Example

CloudFormation templates are built within a so-called Module. This module gets filled with all the CloudFormation resources needed to build the template.

The following is a quick example on how a CloudFormation template is built with the CloudFormation Builder:

class Ec2withEbsModule extends Module {
    public void build() {
        this.template.setDescription("Ec2 block device mapping");

        EC2EBSBlockDevice ec2EBSBlockDeviceA = new EC2EBSBlockDevice()
                .volumeType("io1")
                .iops(200)
                .deleteOnTermination(false)
                .volumeSize("20");
        EC2BlockDeviceMapping ec2BlockDeviceMappingA = new EC2BlockDeviceMapping()
                .deviceName("/dev/sdm")
                .ebs(ec2EBSBlockDeviceA);

        EC2BlockDeviceMapping ec2BlockDeviceMappingB = new EC2BlockDeviceMapping()
                .deviceName("/dev/sdk")
                .noDevice(false);

        resource(Instance.class, "MyEC2Instance")
                .imageId("ami-79fd7eee")
                .keyName("testkey")
                .blockDeviceMappings(ec2BlockDeviceMappingA, ec2BlockDeviceMappingB);
    }
}

Note: The example is taken from the InstanceTest. See /src/test/java/com/scaleset/cfbuilder/ for more tests containing examples that you can use.

This Ec2withEbsModule results in the following CloudFormation template:

AWSTemplateFormatVersion: "2010-09-09"
Description: "Ec2 block device mapping"
Resources:
  MyEC2Instance:
    Type: "AWS::EC2::Instance"
    Properties:
      ImageId: "ami-79fd7eee"
      KeyName: "testkey"
      BlockDeviceMappings:
      - DeviceName: "/dev/sdm"
        Ebs:
          DeleteOnTermination: false
          Iops: 200
          VolumeSize: "20"
          VolumeType: "io1"
      - DeviceName: "/dev/sdk"
        NoDevice: false

Contributing

See our contribution guidelines for detailed information on how to contribute to the cloudformation-builder.

Tools

Tools that are used in this project.

License

CloudFormation-Builder is licensed under the Apache License 2.0.

About

Java DSL for creating AWS CloudFormation templates

Resources

License

Stars

Watchers

Forks

Packages

No packages published

Languages

  • Java 100.0%