formatron 0.1.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- data/.coveralls.yml +1 -0
- data/.gitignore +12 -0
- data/.rspec +2 -0
- data/.rubocop.yml +3 -0
- data/.simplecov +7 -0
- data/.travis.yml +17 -0
- data/CODE_OF_CONDUCT.md +13 -0
- data/Gemfile +6 -0
- data/Guardfile +16 -0
- data/LICENSE.txt +21 -0
- data/README.md +93 -0
- data/Rakefile +16 -0
- data/bin/console +14 -0
- data/bin/setup +7 -0
- data/exe/formatron +20 -0
- data/formatron.gemspec +52 -0
- data/lib/formatron.rb +357 -0
- data/lib/formatron/aws.rb +197 -0
- data/lib/formatron/chef.rb +156 -0
- data/lib/formatron/chef/berkshelf.rb +55 -0
- data/lib/formatron/chef/keys.rb +48 -0
- data/lib/formatron/chef/knife.rb +169 -0
- data/lib/formatron/chef_clients.rb +73 -0
- data/lib/formatron/cli.rb +33 -0
- data/lib/formatron/cli/completion.rb +26 -0
- data/lib/formatron/cli/deploy.rb +57 -0
- data/lib/formatron/cli/destroy.rb +57 -0
- data/lib/formatron/cli/generators/bootstrap.rb +250 -0
- data/lib/formatron/cli/generators/credentials.rb +100 -0
- data/lib/formatron/cli/generators/instance.rb +118 -0
- data/lib/formatron/cli/provision.rb +59 -0
- data/lib/formatron/cloud_formation.rb +54 -0
- data/lib/formatron/cloud_formation/resources/cloud_formation.rb +27 -0
- data/lib/formatron/cloud_formation/resources/ec2.rb +336 -0
- data/lib/formatron/cloud_formation/resources/iam.rb +94 -0
- data/lib/formatron/cloud_formation/resources/route53.rb +54 -0
- data/lib/formatron/cloud_formation/scripts.rb +128 -0
- data/lib/formatron/cloud_formation/template.rb +114 -0
- data/lib/formatron/cloud_formation/template/parameters.rb +20 -0
- data/lib/formatron/cloud_formation/template/vpc.rb +181 -0
- data/lib/formatron/cloud_formation/template/vpc/subnet.rb +187 -0
- data/lib/formatron/cloud_formation/template/vpc/subnet/acl.rb +147 -0
- data/lib/formatron/cloud_formation/template/vpc/subnet/bastion.rb +66 -0
- data/lib/formatron/cloud_formation/template/vpc/subnet/chef_server.rb +205 -0
- data/lib/formatron/cloud_formation/template/vpc/subnet/instance.rb +162 -0
- data/lib/formatron/cloud_formation/template/vpc/subnet/instance/policy.rb +74 -0
- data/lib/formatron/cloud_formation/template/vpc/subnet/instance/security_group.rb +117 -0
- data/lib/formatron/cloud_formation/template/vpc/subnet/instance/setup.rb +68 -0
- data/lib/formatron/cloud_formation/template/vpc/subnet/nat.rb +94 -0
- data/lib/formatron/completion.rb +26 -0
- data/lib/formatron/completion/completion.sh.erb +35 -0
- data/lib/formatron/config.rb +31 -0
- data/lib/formatron/config/reader.rb +29 -0
- data/lib/formatron/dsl.rb +15 -0
- data/lib/formatron/dsl/formatron.rb +25 -0
- data/lib/formatron/dsl/formatron/global.rb +19 -0
- data/lib/formatron/dsl/formatron/global/ec2.rb +17 -0
- data/lib/formatron/dsl/formatron/vpc.rb +17 -0
- data/lib/formatron/dsl/formatron/vpc/subnet.rb +27 -0
- data/lib/formatron/dsl/formatron/vpc/subnet/acl.rb +18 -0
- data/lib/formatron/dsl/formatron/vpc/subnet/chef_server.rb +32 -0
- data/lib/formatron/dsl/formatron/vpc/subnet/chef_server/organization.rb +22 -0
- data/lib/formatron/dsl/formatron/vpc/subnet/instance.rb +29 -0
- data/lib/formatron/dsl/formatron/vpc/subnet/instance/chef.rb +22 -0
- data/lib/formatron/dsl/formatron/vpc/subnet/instance/policy.rb +21 -0
- data/lib/formatron/dsl/formatron/vpc/subnet/instance/policy/statement.rb +23 -0
- data/lib/formatron/dsl/formatron/vpc/subnet/instance/security_group.rb +21 -0
- data/lib/formatron/dsl/formatron/vpc/subnet/instance/setup.rb +22 -0
- data/lib/formatron/dsl/formatron/vpc/subnet/instance/setup/variable.rb +23 -0
- data/lib/formatron/external.rb +61 -0
- data/lib/formatron/external/dsl.rb +171 -0
- data/lib/formatron/external/outputs.rb +25 -0
- data/lib/formatron/generators/bootstrap.rb +90 -0
- data/lib/formatron/generators/bootstrap/config.rb +62 -0
- data/lib/formatron/generators/bootstrap/ec2.rb +17 -0
- data/lib/formatron/generators/bootstrap/formatronfile.rb +52 -0
- data/lib/formatron/generators/bootstrap/formatronfile/Formatronfile.erb +79 -0
- data/lib/formatron/generators/bootstrap/ssl.rb +35 -0
- data/lib/formatron/generators/credentials.rb +17 -0
- data/lib/formatron/generators/instance.rb +64 -0
- data/lib/formatron/generators/instance/config.rb +47 -0
- data/lib/formatron/generators/instance/formatronfile.rb +47 -0
- data/lib/formatron/generators/instance/formatronfile/Formatronfile.erb +16 -0
- data/lib/formatron/generators/util.rb +14 -0
- data/lib/formatron/generators/util/cookbook.rb +65 -0
- data/lib/formatron/generators/util/gitignore.rb +16 -0
- data/lib/formatron/generators/util/readme.rb +18 -0
- data/lib/formatron/logger.rb +8 -0
- data/lib/formatron/s3/chef_server_cert.rb +85 -0
- data/lib/formatron/s3/chef_server_keys.rb +103 -0
- data/lib/formatron/s3/cloud_formation_template.rb +61 -0
- data/lib/formatron/s3/configuration.rb +58 -0
- data/lib/formatron/s3/path.rb +30 -0
- data/lib/formatron/util/dsl.rb +107 -0
- data/lib/formatron/util/shell.rb +20 -0
- data/lib/formatron/util/vpc.rb +15 -0
- data/lib/formatron/version.rb +4 -0
- data/support/cloudformation_describe_stacks_response.rb +36 -0
- data/support/dsl_test.rb +123 -0
- data/support/route53_get_hosted_zone_response.rb +21 -0
- data/support/s3_get_object_response.rb +21 -0
- data/support/template_test.rb +41 -0
- metadata +414 -0
@@ -0,0 +1,26 @@
|
|
1
|
+
class Formatron
|
2
|
+
# command completion utilities
|
3
|
+
module Completion
|
4
|
+
# exports commands, etc to completion script ERB template
|
5
|
+
class Template
|
6
|
+
attr_reader :subcommands, :command
|
7
|
+
|
8
|
+
def initialize(command, subcommands)
|
9
|
+
@command = command
|
10
|
+
@subcommands = subcommands
|
11
|
+
end
|
12
|
+
end
|
13
|
+
|
14
|
+
def self.script(command, subcommands)
|
15
|
+
template = File.join(
|
16
|
+
File.dirname(File.expand_path(__FILE__)),
|
17
|
+
'completion',
|
18
|
+
'completion.sh.erb'
|
19
|
+
)
|
20
|
+
erb = ERB.new File.read(template)
|
21
|
+
erb.filename = template
|
22
|
+
erb_template = erb.def_class Template, 'render()'
|
23
|
+
erb_template.new(command, subcommands).render
|
24
|
+
end
|
25
|
+
end
|
26
|
+
end
|
@@ -0,0 +1,35 @@
|
|
1
|
+
_formatron_complete() {
|
2
|
+
local commands=(
|
3
|
+
<% subcommands.each do |subcommand| %> "<%= subcommand %>"
|
4
|
+
<% end %>)
|
5
|
+
|
6
|
+
COMPREPLY=()
|
7
|
+
|
8
|
+
local word="${COMP_WORDS[COMP_CWORD]}"
|
9
|
+
|
10
|
+
if [ "${COMP_WORDS[1]}" == "help" ]; then
|
11
|
+
local entered=("${COMP_WORDS[@]:2}")
|
12
|
+
local index=$(($COMP_CWORD-2))
|
13
|
+
else
|
14
|
+
local entered=("${COMP_WORDS[@]:1}")
|
15
|
+
local index=$(($COMP_CWORD-1))
|
16
|
+
fi
|
17
|
+
|
18
|
+
local matches=()
|
19
|
+
for command in "${commands[@]}"; do
|
20
|
+
local components=($command)
|
21
|
+
if [ ${#components[@]} -ge ${#entered[@]} ]; then
|
22
|
+
local entered_prefix=${entered[@]::$index}
|
23
|
+
local command_prefix=${components[@]::$index}
|
24
|
+
local component=${components[$index]}
|
25
|
+
if [[ "${entered_prefix[@]}" == "${command_prefix[@]}" && "$component" == "$word"* ]]; then
|
26
|
+
matches+=("$component")
|
27
|
+
fi
|
28
|
+
fi
|
29
|
+
done
|
30
|
+
local completions="${matches[@]}"
|
31
|
+
|
32
|
+
COMPREPLY=($(compgen -W "$completions" -- "$word"))
|
33
|
+
}
|
34
|
+
|
35
|
+
complete -o default -F _formatron_complete <%= command %>
|
@@ -0,0 +1,31 @@
|
|
1
|
+
require_relative 'config/reader'
|
2
|
+
require 'deep_merge'
|
3
|
+
|
4
|
+
class Formatron
|
5
|
+
# Processes the config directory
|
6
|
+
module Config
|
7
|
+
CONFIG_DIR = 'config'
|
8
|
+
DEFAULT_CONFIG = '_default'
|
9
|
+
DEFAULT_JSON = '_default.json'
|
10
|
+
|
11
|
+
def self.targets(directory:)
|
12
|
+
config = File.join directory, CONFIG_DIR
|
13
|
+
Dir.entries(config).select do |entry|
|
14
|
+
path = File.join config, entry
|
15
|
+
File.directory?(path) && !%W(#{DEFAULT_CONFIG} . ..).include?(entry)
|
16
|
+
end
|
17
|
+
end
|
18
|
+
|
19
|
+
def self.target(directory:, target:)
|
20
|
+
Reader.read(
|
21
|
+
File.join(directory, CONFIG_DIR, DEFAULT_CONFIG),
|
22
|
+
DEFAULT_JSON
|
23
|
+
).deep_merge!(
|
24
|
+
Reader.read(
|
25
|
+
File.join(directory, CONFIG_DIR, target),
|
26
|
+
DEFAULT_JSON
|
27
|
+
)
|
28
|
+
)
|
29
|
+
end
|
30
|
+
end
|
31
|
+
end
|
@@ -0,0 +1,29 @@
|
|
1
|
+
require 'json'
|
2
|
+
require 'deep_merge'
|
3
|
+
|
4
|
+
class Formatron
|
5
|
+
module Config
|
6
|
+
# reads config directories into config hash
|
7
|
+
module Reader
|
8
|
+
def self.read(dir, default_file)
|
9
|
+
default = File.join(dir, default_file)
|
10
|
+
config = File.file?(default) ? JSON.parse(File.read(default)) : {}
|
11
|
+
entries = Dir.glob(File.join(dir, '*'), File::FNM_DOTMATCH)
|
12
|
+
do_entries entries, default_file, config
|
13
|
+
config
|
14
|
+
end
|
15
|
+
|
16
|
+
def self.do_entries(entries, default_file, config)
|
17
|
+
entries.each do |entry|
|
18
|
+
basename = File.basename(entry)
|
19
|
+
next if ['.', '..', default_file].include?(basename)
|
20
|
+
config[basename] = {} unless config[basename].is_a? Hash
|
21
|
+
config[basename].deep_merge!(
|
22
|
+
read(entry, default_file)
|
23
|
+
) if File.directory?(entry)
|
24
|
+
config[basename] = File.read(entry) if File.file?(entry)
|
25
|
+
end
|
26
|
+
end
|
27
|
+
end
|
28
|
+
end
|
29
|
+
end
|
@@ -0,0 +1,15 @@
|
|
1
|
+
require_relative 'dsl/formatron'
|
2
|
+
|
3
|
+
class Formatron
|
4
|
+
# context for evaluating the Formatronfile
|
5
|
+
class DSL
|
6
|
+
attr_reader :formatron, :config, :target
|
7
|
+
|
8
|
+
def initialize(file:, config:, target:, external:)
|
9
|
+
@formatron = Formatron.new external: external
|
10
|
+
@config = config
|
11
|
+
@target = target
|
12
|
+
instance_eval File.read(file), file
|
13
|
+
end
|
14
|
+
end
|
15
|
+
end
|
@@ -0,0 +1,25 @@
|
|
1
|
+
require_relative 'formatron/global'
|
2
|
+
require_relative 'formatron/vpc'
|
3
|
+
require 'formatron/util/dsl'
|
4
|
+
|
5
|
+
class Formatron
|
6
|
+
class DSL
|
7
|
+
# formatron top level DSL object
|
8
|
+
class Formatron
|
9
|
+
extend Util::DSL
|
10
|
+
|
11
|
+
dsl_initialize_block do |external:|
|
12
|
+
@external = external
|
13
|
+
end
|
14
|
+
|
15
|
+
dsl_property :name
|
16
|
+
dsl_property :bucket
|
17
|
+
dsl_block :global, 'Global'
|
18
|
+
dsl_hash :vpc, 'VPC'
|
19
|
+
|
20
|
+
def depends(dependency)
|
21
|
+
@external.merge bucket: @bucket, dependency: dependency
|
22
|
+
end
|
23
|
+
end
|
24
|
+
end
|
25
|
+
end
|
@@ -0,0 +1,19 @@
|
|
1
|
+
require 'formatron/util/dsl'
|
2
|
+
require_relative 'global/ec2'
|
3
|
+
|
4
|
+
class Formatron
|
5
|
+
class DSL
|
6
|
+
class Formatron
|
7
|
+
# Global configuration
|
8
|
+
class Global
|
9
|
+
extend Util::DSL
|
10
|
+
dsl_initialize_block
|
11
|
+
dsl_property :protect
|
12
|
+
dsl_property :kms_key
|
13
|
+
dsl_property :databag_secret
|
14
|
+
dsl_property :hosted_zone_id
|
15
|
+
dsl_block :ec2, 'EC2'
|
16
|
+
end
|
17
|
+
end
|
18
|
+
end
|
19
|
+
end
|
@@ -0,0 +1,17 @@
|
|
1
|
+
require 'formatron/util/dsl'
|
2
|
+
|
3
|
+
class Formatron
|
4
|
+
class DSL
|
5
|
+
class Formatron
|
6
|
+
class Global
|
7
|
+
# EC2 key pair configuration
|
8
|
+
class EC2
|
9
|
+
extend Util::DSL
|
10
|
+
dsl_initialize_block
|
11
|
+
dsl_property :key_pair
|
12
|
+
dsl_property :private_key
|
13
|
+
end
|
14
|
+
end
|
15
|
+
end
|
16
|
+
end
|
17
|
+
end
|
@@ -0,0 +1,17 @@
|
|
1
|
+
require_relative 'vpc/subnet'
|
2
|
+
require 'formatron/util/dsl'
|
3
|
+
|
4
|
+
class Formatron
|
5
|
+
class DSL
|
6
|
+
class Formatron
|
7
|
+
# VPC configuration
|
8
|
+
class VPC
|
9
|
+
extend Util::DSL
|
10
|
+
dsl_initialize_hash
|
11
|
+
dsl_property :guid
|
12
|
+
dsl_property :cidr
|
13
|
+
dsl_hash :subnet, 'Subnet'
|
14
|
+
end
|
15
|
+
end
|
16
|
+
end
|
17
|
+
end
|
@@ -0,0 +1,27 @@
|
|
1
|
+
require 'formatron/util/dsl'
|
2
|
+
require_relative 'subnet/acl'
|
3
|
+
require_relative 'subnet/instance'
|
4
|
+
require_relative 'subnet/chef_server'
|
5
|
+
|
6
|
+
class Formatron
|
7
|
+
class DSL
|
8
|
+
class Formatron
|
9
|
+
class VPC
|
10
|
+
# Subnet configuration
|
11
|
+
class Subnet
|
12
|
+
extend Util::DSL
|
13
|
+
dsl_initialize_hash
|
14
|
+
dsl_property :guid
|
15
|
+
dsl_property :cidr
|
16
|
+
dsl_property :availability_zone
|
17
|
+
dsl_property :gateway
|
18
|
+
dsl_block :acl, 'ACL'
|
19
|
+
dsl_hash :nat, 'Instance'
|
20
|
+
dsl_hash :bastion, 'Instance'
|
21
|
+
dsl_hash :instance, 'Instance'
|
22
|
+
dsl_hash :chef_server, 'ChefServer'
|
23
|
+
end
|
24
|
+
end
|
25
|
+
end
|
26
|
+
end
|
27
|
+
end
|
@@ -0,0 +1,18 @@
|
|
1
|
+
require 'formatron/util/dsl'
|
2
|
+
|
3
|
+
class Formatron
|
4
|
+
class DSL
|
5
|
+
class Formatron
|
6
|
+
class VPC
|
7
|
+
class Subnet
|
8
|
+
# Subnet ACL configuration
|
9
|
+
class ACL
|
10
|
+
extend Util::DSL
|
11
|
+
dsl_initialize_block
|
12
|
+
dsl_array :source_cidr
|
13
|
+
end
|
14
|
+
end
|
15
|
+
end
|
16
|
+
end
|
17
|
+
end
|
18
|
+
end
|
@@ -0,0 +1,32 @@
|
|
1
|
+
require_relative 'chef_server/organization'
|
2
|
+
require_relative 'instance'
|
3
|
+
require 'formatron/util/dsl'
|
4
|
+
|
5
|
+
class Formatron
|
6
|
+
class DSL
|
7
|
+
class Formatron
|
8
|
+
class VPC
|
9
|
+
class Subnet
|
10
|
+
# Chef Server instance configuration
|
11
|
+
class ChefServer < Instance
|
12
|
+
extend Util::DSL
|
13
|
+
dsl_initialize_hash
|
14
|
+
dsl_property :version
|
15
|
+
dsl_property :cookbooks_bucket
|
16
|
+
dsl_property :organization
|
17
|
+
dsl_property :username
|
18
|
+
dsl_property :email
|
19
|
+
dsl_property :first_name
|
20
|
+
dsl_property :last_name
|
21
|
+
dsl_property :password
|
22
|
+
dsl_property :ssl_key
|
23
|
+
dsl_property :ssl_cert
|
24
|
+
dsl_property :ssl_verify
|
25
|
+
dsl_property :stack
|
26
|
+
dsl_block :organization, 'Organization'
|
27
|
+
end
|
28
|
+
end
|
29
|
+
end
|
30
|
+
end
|
31
|
+
end
|
32
|
+
end
|
@@ -0,0 +1,22 @@
|
|
1
|
+
require_relative '../instance'
|
2
|
+
require 'formatron/util/dsl'
|
3
|
+
|
4
|
+
class Formatron
|
5
|
+
class DSL
|
6
|
+
class Formatron
|
7
|
+
class VPC
|
8
|
+
class Subnet
|
9
|
+
class ChefServer < Instance
|
10
|
+
# Chef Server organization configuration
|
11
|
+
class Organization
|
12
|
+
extend Util::DSL
|
13
|
+
dsl_initialize_block
|
14
|
+
dsl_property :short_name
|
15
|
+
dsl_property :full_name
|
16
|
+
end
|
17
|
+
end
|
18
|
+
end
|
19
|
+
end
|
20
|
+
end
|
21
|
+
end
|
22
|
+
end
|
@@ -0,0 +1,29 @@
|
|
1
|
+
require_relative 'instance/chef'
|
2
|
+
require_relative 'instance/policy'
|
3
|
+
require_relative 'instance/security_group'
|
4
|
+
require_relative 'instance/setup'
|
5
|
+
require 'formatron/util/dsl'
|
6
|
+
|
7
|
+
class Formatron
|
8
|
+
class DSL
|
9
|
+
class Formatron
|
10
|
+
class VPC
|
11
|
+
class Subnet
|
12
|
+
# Generic instance configuration
|
13
|
+
class Instance
|
14
|
+
extend Util::DSL
|
15
|
+
dsl_initialize_hash
|
16
|
+
dsl_property :guid
|
17
|
+
dsl_property :sub_domain
|
18
|
+
dsl_property :source_dest_check
|
19
|
+
dsl_property :instance_type
|
20
|
+
dsl_block :chef, 'Chef'
|
21
|
+
dsl_block :policy, 'Policy'
|
22
|
+
dsl_block :security_group, 'SecurityGroup'
|
23
|
+
dsl_block :setup, 'Setup'
|
24
|
+
end
|
25
|
+
end
|
26
|
+
end
|
27
|
+
end
|
28
|
+
end
|
29
|
+
end
|
@@ -0,0 +1,22 @@
|
|
1
|
+
require 'formatron/util/dsl'
|
2
|
+
|
3
|
+
class Formatron
|
4
|
+
class DSL
|
5
|
+
class Formatron
|
6
|
+
class VPC
|
7
|
+
class Subnet
|
8
|
+
class Instance
|
9
|
+
# Generic instance configuration
|
10
|
+
class Chef
|
11
|
+
extend Util::DSL
|
12
|
+
dsl_initialize_block
|
13
|
+
dsl_property :server
|
14
|
+
dsl_property :cookbook
|
15
|
+
dsl_property :bastion
|
16
|
+
end
|
17
|
+
end
|
18
|
+
end
|
19
|
+
end
|
20
|
+
end
|
21
|
+
end
|
22
|
+
end
|
@@ -0,0 +1,21 @@
|
|
1
|
+
require 'formatron/util/dsl'
|
2
|
+
require_relative 'policy/statement'
|
3
|
+
|
4
|
+
class Formatron
|
5
|
+
class DSL
|
6
|
+
class Formatron
|
7
|
+
class VPC
|
8
|
+
class Subnet
|
9
|
+
class Instance
|
10
|
+
# IAM policy configuration
|
11
|
+
class Policy
|
12
|
+
extend Util::DSL
|
13
|
+
dsl_initialize_block
|
14
|
+
dsl_block_array :statement, 'Statement'
|
15
|
+
end
|
16
|
+
end
|
17
|
+
end
|
18
|
+
end
|
19
|
+
end
|
20
|
+
end
|
21
|
+
end
|
@@ -0,0 +1,23 @@
|
|
1
|
+
require 'formatron/util/dsl'
|
2
|
+
|
3
|
+
class Formatron
|
4
|
+
class DSL
|
5
|
+
class Formatron
|
6
|
+
class VPC
|
7
|
+
class Subnet
|
8
|
+
class Instance
|
9
|
+
class Policy
|
10
|
+
# IAM policy statement configuration
|
11
|
+
class Statement
|
12
|
+
extend Util::DSL
|
13
|
+
dsl_initialize_block
|
14
|
+
dsl_array :action
|
15
|
+
dsl_array :resource
|
16
|
+
end
|
17
|
+
end
|
18
|
+
end
|
19
|
+
end
|
20
|
+
end
|
21
|
+
end
|
22
|
+
end
|
23
|
+
end
|
@@ -0,0 +1,21 @@
|
|
1
|
+
require 'formatron/util/dsl'
|
2
|
+
|
3
|
+
class Formatron
|
4
|
+
class DSL
|
5
|
+
class Formatron
|
6
|
+
class VPC
|
7
|
+
class Subnet
|
8
|
+
class Instance
|
9
|
+
# Instance security group configuration
|
10
|
+
class SecurityGroup
|
11
|
+
extend Util::DSL
|
12
|
+
dsl_initialize_block
|
13
|
+
dsl_array :open_tcp_port
|
14
|
+
dsl_array :open_udp_port
|
15
|
+
end
|
16
|
+
end
|
17
|
+
end
|
18
|
+
end
|
19
|
+
end
|
20
|
+
end
|
21
|
+
end
|