Skip to content

Commit

Permalink
Merge pull request #12 from myappleguy/open_up_url_options
Browse files Browse the repository at this point in the history
Open up url options, add tags to stack
  • Loading branch information
kunday-personal committed Dec 9, 2014
2 parents 052b8e1 + d82deac commit ea6b440
Show file tree
Hide file tree
Showing 6 changed files with 32 additions and 20 deletions.
27 changes: 15 additions & 12 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -52,8 +52,8 @@ You can add cloudformer tasks to your project by adding the following to your ra
end

where `cloudformation/cloudformation.json` is the stack json file and parameters is a hash of parameters used in the template.
For a template which takes the following parameters:
For a template which takes the following parameters:

"Parameters": {
"PackageUrl": {
"Type": "String"
Expand All @@ -62,13 +62,13 @@ For a template which takes the following parameters:
"Type": "String"
}
}

the parameter hash(Ruby Object) would look like:

{
"PackageUrl" => "http://localhost/app.rpm",
"PackageVersion" => "123"
}
"PackageVersion" => "123"
}

If you have a template with no parameters, pass an empty hash `{}` instead.

Expand Down Expand Up @@ -107,13 +107,16 @@ Here is a simple Cloudformation Stack(Code available in the samples directory) w
}
}
}
Then, in your Rakefile add,

Then, in your Rakefile add,

require 'cloudformer/tasks'

Cloudformer::Tasks.new("app") do |t|
t.template = "basic_template.json"
t.tags = [{'Key' => 'Name', 'Value' => 'BASIC-TMPLT'},
{'Key' => 'Owner', 'Value' => 'APPOWNER'}]

#AMI Works in Sydney region only, ensure you supply the right AMI.
t.parameters = {"AmiId" => "ami-8da439b7"}
end
Expand Down Expand Up @@ -145,7 +148,7 @@ Running `rake apply` will create an environment or update existing depending on
==================================================================================================

Running `rake apply` again gives us:

No updates are to be performed.

To remove the stack `rake delete` gives us:
Expand All @@ -170,7 +173,7 @@ Attempts to delete a non-existing stack will result in:
==============================================

To recreate the stack use `rake recreate`:

=================================================================================================
Attempting to delete stack - app
=================================================================================================
Expand All @@ -194,13 +197,13 @@ To recreate the stack use `rake recreate`:
=================================================================================================

To see the stack outputs `rake outputs`:

==============================
Server - - 172.31.3.52
==============================
==============================

To see recent events on the stack `rake events`:

==================================================================================================
2013-10-24 08:06:31 UTC - AWS::CloudFormation::Stack - CREATE_IN_PROGRESS - User Initiated
2013-10-24 08:06:52 UTC - AWS::EC2::Instance - CREATE_IN_PROGRESS -
Expand Down
1 change: 1 addition & 0 deletions cloudformer.gemspec
Original file line number Diff line number Diff line change
Expand Up @@ -22,4 +22,5 @@ Gem::Specification.new do |spec|
spec.add_development_dependency "rspec"
spec.add_dependency "rake"
spec.add_dependency "aws-sdk"
spec.add_dependency "httparty"
end
1 change: 0 additions & 1 deletion lib/cloudformer.rb
Original file line number Diff line number Diff line change
Expand Up @@ -3,5 +3,4 @@
require "cloudformer/tasks"

module Cloudformer

end
17 changes: 13 additions & 4 deletions lib/cloudformer/stack.rb
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
require 'aws-sdk'
require 'httparty'

class Stack
attr_accessor :stack, :name, :deployed
Expand All @@ -19,9 +20,17 @@ def deployed
return stack.exists?
end

def apply(template_file, parameters, disable_rollback=false, capabilities=[], notify=[])
def apply(template_file, parameters, disable_rollback=false, capabilities=[], notify=[], tags=[])
if ( template_file =~ /^https:\/\/s3\S+\.amazonaws\.com\/(.*)/ )
template = template_file
elsif ( template_file =~ /^http.*(.json)$/ )
begin
response = HTTParty.get(template_file)
template = response.body
rescue => e
puts "Unable to retieve json file for template from #{template_file} - #{e.class}, #{e}"
return :Failed
end
else
template = File.read(template_file)
end
Expand All @@ -35,7 +44,7 @@ def apply(template_file, parameters, disable_rollback=false, capabilities=[], no
if deployed
pending_operations = update(template, parameters, capabilities)
else
pending_operations = create(template, parameters, disable_rollback, capabilities, notify)
pending_operations = create(template, parameters, disable_rollback, capabilities, notify, tags)
end
rescue ::AWS::CloudFormation::Errors::ValidationError => e
puts e.message
Expand Down Expand Up @@ -154,9 +163,9 @@ def update(template, parameters, capabilities)
return true
end

def create(template, parameters, disable_rollback, capabilities, notify)
def create(template, parameters, disable_rollback, capabilities, notify, tags)
puts "Initializing stack creation..."
@cf.stacks.create(name, template, :parameters => parameters, :disable_rollback => disable_rollback, :capabilities => capabilities, :notify => notify)
@cf.stacks.create(name, template, :parameters => parameters, :disable_rollback => disable_rollback, :capabilities => capabilities, :notify => notify, :tags => tags)
sleep 10
return true
end
Expand Down
4 changes: 2 additions & 2 deletions lib/cloudformer/tasks.rb
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ def initialize(stack_name)
end
end

attr_accessor :template, :parameters, :disable_rollback, :retry_delete, :capabilities, :notify
attr_accessor :template, :parameters, :disable_rollback, :retry_delete, :capabilities, :notify, :tags

private
def define_tasks
Expand All @@ -35,7 +35,7 @@ def define_create_task
if retry_delete
@stack.delete
end
result = @stack.apply(template, parameters, disable_rollback, capabilities, notify)
result = @stack.apply(template, parameters, disable_rollback, capabilities, notify, tags)
if result == :Failed then exit 1 end
if result == :NoUpdates then exit 0 end
end
Expand Down
2 changes: 1 addition & 1 deletion lib/cloudformer/version.rb
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
module Cloudformer
VERSION = "0.0.15"
VERSION = "0.0.17"
end

0 comments on commit ea6b440

Please sign in to comment.