1.0.24 • Published 4 years ago

yaml-blaster v1.0.24

Weekly downloads
9
License
MIT
Repository
github
Last release
4 years ago

YAML-Blaster - Framework for processing YAML templates

This was created to ease the pain of having to use a giant single-file AWS Cloudformation template by allowing variable replacement, file loading, and loops.

Table of Contents

Installation

npm

$ npm install -g yaml-blaster

Usage

CLI

Assuming your project looks like this

project
|
+-- template.yaml
|
+-- data.yaml

From the project directory just run

$ yaml-blaster \
  -i template.yaml \  # The input template
  -d data.yaml        # A configuration file

Or from anywwhere run

$ yaml-blaster \
  -i /full/path/to/project/template.yaml \
  -d /full/path/to/project/data.yaml

To save the output to a file

$ yaml-blaster \
  -i template.yaml \
  -d data.yaml \
  -o processed.yaml

Features

Simple Variable replacement

Syntax: {{variable}} - Replace variables in the template

template.yaml

AWSTemplateFormatVersion: '2010-09-09'
Resources:
  MyS3Bucket:
    Type: AWS::S3::Bucket
    Properties:
      BucketName: {{name}}

data.yaml

name: my-bucket-name

run

$ yaml-blaster \
  -i template.yaml \
  -d data.yaml

output

AWSTemplateFormatVersion: '2010-09-09'
Resources:
  MyS3Bucket:
    Type: AWS::S3::Bucket
    Properties:
      BucketName: my-bucket-name

Load a file

Syntax: {{file:relative/path}} - load a file and replace it in the template

Using top-level data scope

By default, any variables in the loaded snippet will be replaced using the top-level scope of the data file.

project structure

project
|
+-- template.yaml
|
+-- data.yaml
|
+-- snippets
   |
   +-- bucket.yaml

template.yaml

AWSTemplateFormatVersion: '2010-09-09'
Resources:
  {{file:sub-templates/bucket.yaml}}

snippets/bucket.yaml

{{logicalName}}:
  Type: AWS::S3::Bucket
  Properties:
    BucketName: {{bucketName}}

data.yaml

logicalName: MyS3Bucket
bucketName: my-s3-bucket

output

AWSTemplateFormatVersion: '2010-09-09'
Resources:
  MyS3Bucket:
    Type: AWS::S3::Bucket
    Properties:
      BucketName:my-s3-bucket

Using specific data scope

Syntax: {{path.to.value, file:relative/path}} - load a file and replace variables under a specific scope

project structure

project
|
+-- template.yaml
|
+-- data.yaml
|
+-- snippets
   |
   +-- bucket.yaml

template.yaml

AWSTemplateFormatVersion: '2010-09-09'
Resources:
  {{bucket1, file:sub-templates/bucket.yaml}}
  {{bucket2, file:sub-templates/bucket.yaml}}

snippets/bucket.yaml

{{logicalName}}:
  Type: AWS::S3::Bucket
  Properties:
    BucketName: {{bucketName}}

data.yaml

bucket1:
  logicalName: MyFirstS3Bucket
  bucketName: my-s3-bucket-1
bucket2:
  logicalName: MySecondS3Bucket
  bucketName: my-s3-bucket-2

output

AWSTemplateFormatVersion: '2010-09-09'
Resources:
  MyFirstS3Bucket:
    Type: AWS::S3::Bucket
    Properties:
      BucketName: my-s3-bucket-1
  MySecondS3Bucket:
    Type: AWS::S3::Bucket
    Properties:
      BucketName: my-s3-bucket-2

Loops

Syntax: {{for:path.to.array, file:relative/path}} - add n number of instances of a snippet by referring to an array in the data file

project structure

project
|
+-- template.yaml
|
+-- data.yaml
|
+-- snippets
   |
   +-- bucket.yaml

template.yaml

AWSTemplateFormatVersion: '2010-09-09'
Resources:
  {{for:buckets, file:sub-templates/bucket.yaml}}

snippets/bucket.yaml

{{logicalName}}:
  Type: AWS::S3::Bucket
  Properties:
    BucketName: {{bucketName}}

data.yaml

buckets:
  - logicalName: MyFirstS3Bucket
    bucketName: my-s3-bucket-1
  - logicalName: MySecondS3Bucket
    bucketName: my-s3-bucket-2

output

AWSTemplateFormatVersion: '2010-09-09'
Resources:
  MyFirstS3Bucket:
    Type: AWS::S3::Bucket
    Properties:
      BucketName: my-s3-bucket-1
  MySecondS3Bucket:
    Type: AWS::S3::Bucket
    Properties:
      BucketName: my-s3-bucket-2
1.0.24

4 years ago

1.0.23

4 years ago

1.0.22

4 years ago

1.0.21

4 years ago

1.0.20

4 years ago

1.0.19

4 years ago

1.0.2

4 years ago

1.0.18

4 years ago

1.0.17

4 years ago

1.0.16

4 years ago

1.0.8

4 years ago

1.0.7

4 years ago

1.0.5

4 years ago

1.0.4

4 years ago

1.0.3

4 years ago

1.0.10

4 years ago

1.0.14

4 years ago

1.0.13

4 years ago

1.0.12

4 years ago

1.0.0

4 years ago