GithubHelp home page GithubHelp logo

ggiallo28 / cft-simulator Goto Github PK

View Code? Open in Web Editor NEW

This project forked from dome9/cft-simulator

0.0 1.0 0.0 30 KB

An AWS CloudFormation Template simulator / debugger

License: BSD 3-Clause "New" or "Revised" License

JavaScript 100.00%

cft-simulator's Introduction

CFT-Simulator

A utility to simulate / debug complex Cloud Formation Templates.

Why should I care?

CFT have gone a long way from being a declarative blueprint for an AWS environment. Power users of AWS CloudFormation, often create CFTs which act like a software program - one that accepts parameters, process them according to logic and generates output.
This tool allows you to run an offline (= not executing the stack in AWS environment) simulation of the CFT according to various input parameters.
Now you can debug complex CFT and transform a generic template into a concrete plan with all parameters and conditions materialized.
It was created from our need for a pre-processor to allow running security assessments in Dome9's Clarity Visualization tool

What does it do?

This a work-in-progress. Currently it:

  • Parses the input file (JSON only)
  • Prompts the user for values for all parameters that are declared in the template (and were not provided as a CLI parameter)
  • Replaces all occurrences of the parameters with the user's values
  • Evaluates intrinsic functions: And, Or ,Not, Join, FindInMap, etc...
  • Evaluates all conditions according to user's input and functions evaluation
  • Deletes all nodes with false conditions and select the correct If option
  • Replaces Security Groups implicit references from Fn::GetAtt syntax to Ref which does not rely on runtime values hence more appropriate for static analysis

Requirements

  • NodeJs stable version 4.0.0 or later. (Can be downloaded from: here )

Installation

  1. Clone this repo into your local machine:

git clone https://github.com/Dome9/cft-simulator.git

  1. Navigate to the tool's folder:

cd cft-simulator

  1. Install the tool's dependencies:

npm install

  1. Verify that the tool/ dependencies are properly installed:

node cft-simulator.js --version

Running the tool

The tool receives mandatory command-line argument which is the path to the source CFT file (and optional parameters object) and writes a transformed JSON into the standard output. The tool will prompt the user to enter every parameter that is defined in the template but was not provided via the command line -p parameter.

Usage:

node cft-simulator.js -h

  Usage: index [options] <file>

  Options:

    -h, --help          output usage information
    -V, --version       output the version number
    -p, --params <env>  a JSON formatted object. surrounded with ' Example: -p '{"env":"prod","a":123}'


node cft-simulator.js -p '{"env":"prod", "port":80}' path/to/cft.json 

In order to write the result into a new file - just redirect the output into the desired file path. Example:

node index.js path/to/source.json > result.json

Executing custom processing logic

You can write your own processors to handle any specific logic for your choice. A good example is to write a custom processor for a custom resource.
See the sampleProcessor.js in processors folder.
Do not forget to uncomment the execution of this custom processor in cft-simulator.js

    // Your own custom processors here...
    var customProcessor = require("./processors/sampleProcessor");
    ret = customProcessor.process(ret);

Future Work

  • Support stacked CFT
  • Support YAML format
  • Proper evaluation of conditions (as long as they can be statically evaluated):
    • Implementation of native inner functions [DONE]
    • Minimal emulation of runtime properties
  • Better support for 'If' statements according to the evaluated conditions [DONE]

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.