• Stars
    star
    209
  • Rank 188,280 (Top 4 %)
  • Language
    Ruby
  • License
    Apache License 2.0
  • Created over 10 years ago
  • Updated almost 2 years ago

Reviews

There are no reviews yet. Be the first to send feedback to the community and the maintainers!

Repository Details

Ruby DSL for creating Cloudformation templates

cloudformation-ruby-dsl

A Ruby DSL and helper utilities for building CloudFormation templates dynamically.

Written by Bazaarvoice: see the contributors page and the initial contributions for more details.

Motivation

CloudFormation templates often contain repeated stanzas, information which must be loaded from external sources, and other functionality that would be easier handled as code, instead of configuration.

Consider when a userdata script needs to be added to a CloudFormation template. Traditionally, you would re-write the script by hand in a valid JSON format. Using the DSL, you can specify the file containing the script and generate the correct information at runtime.

:UserData => base64(interpolate(file('userdata.sh')))

Additionally, CloudFormation templates are just massive JSON documents, making general readability and reusability an issue. The DSL allows not only a cleaner format (and comments!), but will also allow the same DSL template to be reused as needed.

Installation

Run gem install cloudformation-ruby-dsl to install system-wide.

To use in a specific project, add gem 'cloudformation-ruby-dsl' to your Gemfile, and then run bundle.

Releasing

See Releasing.

Contributing

See Contributing.

Usage

To convert existing JSON templates to use the DSL, run

cfntemplate-to-ruby [EXISTING_CFN] > [NEW_NAME.rb]

You may need to preface this with bundle exec if you installed via Bundler.

Make the resulting file executable (chmod +x [NEW_NAME.rb]). It can respond to the following subcommands (which are listed if you run without parameters):

  • expand: output the JSON template to the command line (takes optional --nopretty to minimize the output)
  • diff: compare an existing stack with your template. Produces following exit codes:
    0 - no differences, nothing to update
    1 - stack does not exist, template Validation error
    2 - there are differences between an existing stack and your template
  • validate: run validation against the stack definition
  • create: create a new stack from the output (takes optional --s3-bucket to upload the template to the specified S3 bucket prior to creating the stack)
  • update: update an existing stack from the output (takes optional --s3-bucket to upload the template to the specified S3 bucket prior to creating the stack). Produces following exit codes:
    0 - update finished successfully
    1 - no updates to perform, stack doesn't exist, unable to update immutable parameter or tag, AWS ServiceError exception
  • cancel-update: cancel updating a stack
  • delete: delete a stack (with prompt)
  • describe: get output of an existing stack and output it (takes optional --nopretty to minimize output)
  • describe-resource: given two arguments: stack-name and logical-resource-id, get output from a stack concerning the specific resource (takes optional --nopretty to minimize output)
  • get-template: get entire template output of an existing stack

Command line options similar to cloudformation commands, but parsed by the dsl.

  • --profile
  • --stack-name
  • --region
  • --parameters
  • --tag

Any other parameters are passed directly onto cloudformation. (--disable-rollback for instance)

Using the ruby scripts:

template.rb create --stack-name my_stack --parameters "BucketName=bucket-s3-static;SnsQueue=mysnsqueue"

Below are the various functions currently available in the DSL. See the example script for more usage information.

DSL Statements

Add the named object to the appropriate collection.

  • parameter(name, options) (may be marked :Immutable, which will raise error on a later change)
  • mapping(name, options)
  • condition(name, conditions)
  • resource(name, options)
  • output(name, options)
  • metadata(object)

CloudFormation Function Calls

Invoke an intrinsic CloudFormation function.

  • base64(value)
  • find_in_map(map, key, name)
  • get_att(resource, attribute)
  • get_azs(region)
  • split(delim, string)
  • join(delim, *list)
  • select(index, list)
  • ref(name)
  • import_value(value)
  • sub(sub_string)
  • sub(sub_string, var_map)

Intrinsic conditionals are also supported, with some syntactic sugar.

  • fn_not(condition)
  • fn_or(*condition_list)
  • fn_and(*condition_list)
  • fn_if(condition, value_if_true, value_if_false)
  • equal(lhsOperand, rhsOperand)
  • not_equal(lhsOperand, rhsOperand)

Reference a CloudFormation pseudo parameter.

  • aws_account_id()
  • aws_notification_arns()
  • aws_no_value()
  • aws_region()
  • aws_stack_id()
  • aws_stack_name()

Utility Functions

Additional capabilities for file inclusion, etc.

  • tag(tag_name, tag_options_hash): add tags to the stack, which are inherited by all resources in that stack. tag_options_hash includes :Value=>value and :Immutable=>true properties. tag(tag_value_hash) is deprecated and will be removed in a future version.
  • file(name): return the named file as a string, for further use
  • load_from_file(filename): load the named file by a given type; currently handles YAML, JSON, and Ruby
  • interpolate(string): embed CFN references into a string ({{ref('Service')}}) for later interpretation by the CFN engine
  • Table.load(filename): load a table from the listed file, which can then be turned into mappings (via get_map)

Default Region

The tool defaults to region us-east-1. To change this set either EC2_REGION or AWS_DEFAULT_REGION in your environment.

More Repositories

1

jolt

JSON to JSON transformation library written in Java.
Java
1,504
star
2

maven-process-plugin

Maven: start multiple processes in pre-integration-test phase in order.
Java
62
star
3

dropwizard-configurable-assets-bundle

An implementation of an AssetBundle for use in Dropwizard that allows user configuration.
Java
56
star
4

emodb

A distributed database with a built in streaming data platform
Java
56
star
5

swat-proxy

A node.js proxy server that makes injecting applications or prototype applications onto potential client websites easy.
JavaScript
51
star
6

HostedUIResources

Bazaarvoice Hosted UI Implementation Resources
Python
48
star
7

s3-upload-maven-plugin

Allows you to upload a file to S3 from maven
Java
39
star
8

scoutfile

A Node module for generating a scout file for a client-side JS app
JavaScript
34
star
9

jersey-hmac-auth

HMAC authentication for server and client
Java
31
star
10

ostrich

SOA Library
Java
27
star
11

jsonpps

Streaming JSON pretty printer
Java
22
star
12

rison

Rison encoder and decoder for the Jackson streaming JSON processor
Java
16
star
13

bv-android-sdk

Bazaarvoice Android SDK for Developers
Java
16
star
14

curator-extensions

Helpers that extend the functionality of curator.
Java
15
star
15

magento2-extension

The official Magento 2 extension for Bazaarvoice.
PHP
14
star
16

elasticsearch-hyperloglog

This repo will have a custom elasticsearch plugin which allows to do aggregation on stored binary representations of hyperloglogplus data structure.
Java
13
star
17

json-regex-difftool

A JSON to JSON diff tool
Python
13
star
18

dropwizard-redirect-bundle

A simple bundle for DropWizard that allows for HTTP redirects
Java
13
star
19

bv-ios-sdk

Bazaarvoice iOS SDK for Developers
Objective-C
13
star
20

python-hmac-auth

Python SDK for https://github.com/bazaarvoice/jersey-hmac-auth
Python
12
star
21

bv-ios-swift-sdk

Bazaarvoice's Swift SDK
Swift
11
star
22

dropwizard-webjars-bundle

Dropwizard bundle to make working with Webjars (http://webjars.org) easier.
Java
10
star
23

Bazaarvoice-Hello-World

A sample application using the Bazaarvoice API to show incoming product reviews animated on a Google Earth based globe
JavaScript
10
star
24

APITutorial

Tutorial for Javascript widget on Conversations API
HTML
9
star
25

stripe-ctf-2-vm

The Stripe Capture the Flag (CTF) 2 contest in a Virtualbox VM.
Shell
8
star
26

aws-cfn-custom-resource

A node.js library to help write CloudFormation custom resources.
JavaScript
8
star
27

dropwizard-caching-bundle

Response caching bundle for Dropwizard resources
Java
8
star
28

super-simple-workflow

Scala
8
star
29

bv-vger

Serverless team performance metrics application
JavaScript
7
star
30

cve-tools

Tools for dealing with CVE IDs and related vulnerability data from the National Vulnerability Database.
JavaScript
6
star
31

lassie

Java library that wraps the DataDog screenboard REST API.
Java
6
star
32

BVSnippets

Jquery plugin that injects BV snippets onto a page (i.e. a featured review, inline ratings, etc.)
JavaScript
6
star
33

awslocal

Partial implementation of AWS Java SDK that operates locally
Java
5
star
34

seo_sdk_php

Bazaarvoice SEO SDK for PHP
PHP
5
star
35

pr_releasenotes

Generate release notes from github pull requests
Ruby
5
star
36

s3repo-maven-plugin

Update an S3 YUM repository with artifacts from Maven.
Java
4
star
37

bv-ui-core

A Node module for common Bazaarvoice UI code.
JavaScript
4
star
38

s3repo-gradle-plugin

Plugin for Gradle to deploy to an S3 Yum repo
Java
4
star
39

bv-varnish-cache

A concrete example of how to use Varnish as caching solution in client side.
Perl
4
star
40

social-alerts-api

Bazaarvoice Social Alerts API allows 3rd-party E-mail Service Providers to implement connectors allowing Bazaarvoice to integrate its Interaction Suite with E-mail Provider's system very quickly.
Java
3
star
41

response-demo

Example implementation of the Bazaarvoice Response API using OAuth2
JavaScript
3
star
42

seo_sdk_java

Bazaarvoice SEO SDK for Java
HTML
2
star
43

unshackle

A JavaScript software release script runner.
JavaScript
2
star
44

commons-data-dao

BVCommons Data DAO
Java
2
star
45

export-tools

export-tools
JavaScript
2
star
46

cordova-plugin-bvsdk

JavaScript
2
star
47

api-analytics

API Analytics
CSS
1
star
48

cookiecutter-actions-demo

Demo CookieCutter template used for GitHub Actions Demo
Makefile
1
star
49

bv-ui-pixels-displayed

A module for detecting whether an element is visible.
JavaScript
1
star
50

Curations-API-Pixel-tutorial

Tutorial on how Curations API clients should implement the BV pixel
CSS
1
star
51

hackathon-craze2Hack-bot

JavaScript
1
star
52

api-submission-form

Tutorial to use a Conversation API response to dynamically set the sequence of HTML inputs on a submission form.
JavaScript
1
star