Link Search Menu Expand Document

Gradle

Enable the KloudFormation Gradle plugin

Add the plugin to your build.gradle.kts file.

Build script snippet for plugins DSL for Gradle 2.1 and later:

plugins {
    id("io.klouds.kloudformation.gradle.plugin") version "0.1.2"
}

Build script snippet for use in older Gradle versions or where dynamic configuration is required:

buildscript {
  repositories {
    maven {
      url = uri("https://plugins.gradle.org/m2/")
    }
  }
  dependencies {
    classpath("gradle.plugin.io.klouds.kloudformation.gradle.plugin:kloudformation-gradle-plugin:0.1.2")
  }
}
    
apply(plugin = "io.klouds.kloudformation.gradle.plugin")

This will provide your Gradle build with a new task called generateTemplate. Add this task to your main build flow.

When your project uses the Gradle Java plugin:

tasks["jar"].dependsOn("generateTemplate")

KloudFormation Gradle plugin configuration

Add the configuration to your build.gradle.kts file.

Configure the plugin to outline your template stack:

configure<KloudFormationConfiguration> {
    template = KloudFormationTemplate.create {
        val topicName = parameter<String>("TopicName")
        topic {
            topicName(topicName.ref())
        }
        queue()
        bucket {
            bucketName("myBucket")
        }
    }
}

The path and template format is also configurable.

The above configuration will produce the following template YAML in the default path of “build/generated/template/template.yaml”

AWSTemplateFormatVersion: "2010-09-09"
Parameters:
  TopicName:
    Type: "String"
Resources:
  Topic:
    Type: "AWS::SNS::Topic"
    Properties:
      TopicName:
        Ref: "TopicName"
  Queue:
    Type: "AWS::SQS::Queue"
  Bucket:
    Type: "AWS::S3::Bucket"
    Properties:
      BucketName: "myBucket"