Code Monkey home page Code Monkey logo

clj-cloud-gen's Introduction

clj-cloud-gen

A clojure library and application to create and deploy Amazon Web Services cloudformation templates.
The json declaritve cloudformation is verbose and obfucates complicated layouts. By using function graphs and clojure's ablity to succiently decribe a data schema the specification of the infrastructure is much readable, maintable, adaptable

It is import to set certian environment variables

in a .lein-env or profiles.clj file

{
:cf-template-bucket-uri "https://s3.amazonaws.com/cf-templates-replace-me-us-east-1/test-ci-devops"
:cf-stack-name  "devops-ci"
:cf-bucket-name "cf-templates-replace-me-us-east-1"
:cf-object-name  "test-ci-devops"
:cf-template-path "cloudformation/test_result.json"
}

Usage

(ns clj-cloud-gen.cloud-specification
  (:require [plumbing.core :as p :refer [fnk]]
            [plumbing.graph :as graph]))

(def static-cfgs
  {
   :gateway {:default-gateway {}}

   :internet {:default-connection {:vpc-id :devops
                                   :internet-gateway-id :default-gateway}}

   :route-table {:public-table {:vpc-id :devops}
                 :private-table {:vpc-id :devops}}

   :route {:public-route {:depends-on :default-connection
                          :route-table-id :public-table
                          :destination-cidr-block "0.0.0.0/0"
                          :gateway-id :default-gateway}
           :private-route {:route-table-id :private-table
                           :destination-cidr-block "0.0.0.0/0"
                           :instance-id :nat-node}}

   :subnet-route-table {:private-subnet-route {:subnet-id :private-subnet
                                               :route-table-id :private-table}
                        :public-subnet-route  {:subnet-id :public-subnet
                                               :route-table-id :public-table}}

   :ip {:nat-ip-address {:depends-on :default-connection
                         :domain "vpc"
                         :instance-id :nat-node}}
   })

(def parameteric-cfgs
  {:format
   (p/fnk [])

   :vpc
   (p/fnk [mappings]
          {:devops {:cidr-block (-> mappings :subnet-config :vpc :cidr)}})

   :subnet
   (p/fnk [parameters mappings]
          {:public-subnet {:vpc-id :devops :cidr-block (-> mappings :subnet-config :public :cidr)}
           :private-subnet {:vpc-id :devops :cidr-block (-> mappings :subnet-config :private :cidr)}})

   :security-group
   (p/fnk [parameters]
          (let [{:keys [ssh-from]} parameters]
            {:web {:vpc-id :devops :group-description "Enable  SSH access from anywhere"
                   :security-group-ingress [{:ip-protocol "tcp" :from-port "22" :to-port "22" :cidr-ip ssh-from}
                                            {:ip-protocol "tcp" :from-port "80" :to-port "80" :cidr-ip "0.0.0.0/0"}
                                            {:ip-protocol "tcp" :from-port "443":to-port "443" :cidr-ip "0.0.0.0/0"}]}
             :nat  {:vpc-id :devops :group-description "NAT "
                    :security-group-ingress [{:ip-protocol "icmp" :from-port "-1" :to-port "-1" :cidr-ip "0.0.0.0/0"}
                                             {:ip-protocol "tcp" :from-port "22" :to-port "22" :cidr-ip ssh-from}
                                             {:ip-protocol "tcp" :from-port "80" :to-port "80" :cidr-ip "0.0.0.0/0"}
                                             {:ip-protocol "tcp" :from-port "443":to-port "443" :cidr-ip "0.0.0.0/0"}]}
             :database {:vpc-id :devops :group-description "Pass all traffic"
                        :security-group-ingress [{:ip-protocol "tcp" :from-port "3306" :to-port "3306" :cidr-ip "0.0.0.0/0"}]}
             }))

   :node
   (p/fnk [parameters subnet mappings security-group]
          {:web-node  {:key-name (-> parameters :key-name)
                       :instance-type "c3.large"
                       :subnet-id :private-subnet
                       :private-ip-address (-> mappings :subnet-config :private :default :ip :private)
                       :source-dest-check "false"
                       :image-id  (-> mappings :image :web-node :ami)
                       :security-group-ids [:web]}
           :nat-node {:key-name (-> parameters :key-name)
                      :instance-type (-> parameters :instance-type)
                      :subnet-id :public-subnet
                      :private-ip-address (-> mappings :subnet-config :public :nat :ip :private)
                      :source-dest-check "false"
                      :security-group-ids [:nat]
                      :image-id  (-> mappings :image :nat-node :ami)}})

   :volume
   (p/fnk [parameters mappings]
          {:default-volume {:size  (-> mappings :image-id :web-node :volume :size)
                            :depends-on :web-node
                            :availability-zone (-> mappings :availability-zone)}})

   :volume-attachment
   (p/fnk [mappings]
          {:instance-mount-point {:instance-id :web-node
                                  :volume-id :default-volume
                                  :device (-> mappings :image :web-node :volume :mount-point)}})
   :resources
   (p/fnk [vpc subnet internet gateway route-table route security-group node ip volume volume-attachment subnet-route-table :as args]
          args
          )
   }
  )
                                                
(def json-template (assemble-cloudformation parameteric-cfgs static-cfgs test-cfgs))                                                

License

Copyright © 2015 Matthew Burns All rights reserved.

Distributed under the Eclipse Public License either version 1.0 or (at your option) any later version.

clj-cloud-gen's People

Contributors

mateoconfeugo avatar

Stargazers

Alexander Dean avatar

Watchers

 avatar James Cloos avatar

Forkers

dwatkins4782

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.