rake-cloudformation 1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
data/Gemfile ADDED
@@ -0,0 +1,2 @@
1
+ source 'https://rubygems.org'
2
+ gem 'aws-sdk'
@@ -0,0 +1,101 @@
1
+ # ex: syntax=ruby ts=2 sw=2 si et
2
+ require 'aws/cloud_formation'
3
+
4
+ module Rake
5
+ module CloudFormation
6
+ class Service
7
+ extend Rake::CloudFormation
8
+ end
9
+
10
+ class Stack < Rake::Task
11
+ include Rake::DSL
12
+ include Rake::CloudFormation
13
+
14
+ def initialize(*args)
15
+ super
16
+ @region = 'us-east-1'
17
+ @parameters = {}
18
+ @capabilities = []
19
+ end
20
+
21
+ def self.define_task(args, &block)
22
+ t = super
23
+ if (t.is_a?(Stack))
24
+ yield t if block_given?
25
+ t.prepare
26
+ end
27
+ t
28
+ end
29
+
30
+ attr_accessor :template, :region
31
+ attr_reader :parameters, :capabilities
32
+
33
+ def prepare
34
+ prerequisites << file(@template)
35
+ end
36
+
37
+ def needed?
38
+ !cf(region).stacks[name].exists? or cf(region).stacks[name].status != 'CREATE_COMPLETE'
39
+ end
40
+
41
+ def execute(*args)
42
+ super
43
+ options = {}
44
+ unless parameters.empty?
45
+ options[:parameters] = parameters.inject({}) do |hash, (key, value)|
46
+ if value.is_a?(String)
47
+ hash[key] = value
48
+ elsif value.is_a?(Proc)
49
+ hash[key] = value.call
50
+ else
51
+ raise "Parameter value of unknown type: key=#{key.inspect} value=#{value.inspect}"
52
+ end
53
+ hash
54
+ end
55
+ end
56
+ options[:capabilities] = capabilities unless capabilities.empty?
57
+ puts "Creating CloudFormation stack: #{name}"
58
+ cf(region).stacks.create(name, IO.read(template), options)
59
+ while cf(region).stacks[name].status === 'CREATE_IN_PROGRESS'
60
+ sleep 20
61
+ end
62
+ unless cf(region).stacks[name].status === 'CREATE_COMPLETE'
63
+ raise "Stack creation failed"
64
+ end
65
+ end
66
+ end
67
+
68
+ def cf(region)
69
+ AWS.config(
70
+ :access_key_id => access_key_id,
71
+ :secret_access_key => secret_access_key,
72
+ :region => region
73
+ )
74
+ AWS::CloudFormation.new
75
+ end
76
+
77
+ def access_key_id
78
+ credential_file_hash['AWKAccessKeyId']
79
+ end
80
+
81
+ def secret_access_key
82
+ credential_file_hash['AWSSecretKey']
83
+ end
84
+
85
+ def credential_file_hash
86
+ Hash[*File.read(ENV['AWS_CREDENTIAL_FILE']).split(/[=\n]/)]
87
+ end
88
+ end
89
+ end
90
+
91
+ def cfn_stack(args, &block)
92
+ Rake::CloudFormation::Stack.define_task(args, &block)
93
+ end
94
+
95
+ def cfn_get_stack_output(stack_name, region, output_key)
96
+ Rake::CloudFormation::Service.cf(region).stacks[stack_name].outputs.detect { |o| o.key === output_key }.value
97
+ end
98
+
99
+ def cfn_stack_output(*args)
100
+ Proc.new { cfn_get_stack_output(*args) }
101
+ end
@@ -0,0 +1,16 @@
1
+ # ex: syntax=ruby ts=2 sw=2 si et
2
+
3
+ Gem::Specification.new do |gem|
4
+ gem.authors = [ 'Nate Riffe']
5
+ gem.email = 'inkblot@movealong.org'
6
+ gem.description = 'Library functions for defining tasks to start AWS CloudFormation stacks using rake'
7
+ gem.summary = 'Start AWS CloudFormation stacks with rake'
8
+ gem.homepage = 'https://github.com/inkblot/rake-cloudformation.git'
9
+
10
+ gem.files = `git ls-files`.split($\)
11
+ gem.name = 'rake-cloudformation'
12
+ gem.require_paths = [ 'lib' ]
13
+ gem.version = '1'
14
+
15
+ gem.add_runtime_dependency 'aws-sdk', '~> 1.59'
16
+ end
metadata ADDED
@@ -0,0 +1,64 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: rake-cloudformation
3
+ version: !ruby/object:Gem::Version
4
+ version: '1'
5
+ prerelease:
6
+ platform: ruby
7
+ authors:
8
+ - Nate Riffe
9
+ autorequire:
10
+ bindir: bin
11
+ cert_chain: []
12
+ date: 2014-12-06 00:00:00.000000000 Z
13
+ dependencies:
14
+ - !ruby/object:Gem::Dependency
15
+ name: aws-sdk
16
+ requirement: !ruby/object:Gem::Requirement
17
+ none: false
18
+ requirements:
19
+ - - ~>
20
+ - !ruby/object:Gem::Version
21
+ version: '1.59'
22
+ type: :runtime
23
+ prerelease: false
24
+ version_requirements: !ruby/object:Gem::Requirement
25
+ none: false
26
+ requirements:
27
+ - - ~>
28
+ - !ruby/object:Gem::Version
29
+ version: '1.59'
30
+ description: Library functions for defining tasks to start AWS CloudFormation stacks
31
+ using rake
32
+ email: inkblot@movealong.org
33
+ executables: []
34
+ extensions: []
35
+ extra_rdoc_files: []
36
+ files:
37
+ - Gemfile
38
+ - lib/rake/cloud_formation.rb
39
+ - rake-cloudformation.gemspec
40
+ homepage: https://github.com/inkblot/rake-cloudformation.git
41
+ licenses: []
42
+ post_install_message:
43
+ rdoc_options: []
44
+ require_paths:
45
+ - lib
46
+ required_ruby_version: !ruby/object:Gem::Requirement
47
+ none: false
48
+ requirements:
49
+ - - ! '>='
50
+ - !ruby/object:Gem::Version
51
+ version: '0'
52
+ required_rubygems_version: !ruby/object:Gem::Requirement
53
+ none: false
54
+ requirements:
55
+ - - ! '>='
56
+ - !ruby/object:Gem::Version
57
+ version: '0'
58
+ requirements: []
59
+ rubyforge_project:
60
+ rubygems_version: 1.8.24
61
+ signing_key:
62
+ specification_version: 3
63
+ summary: Start AWS CloudFormation stacks with rake
64
+ test_files: []