-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathcf-get
executable file
·43 lines (32 loc) · 1.14 KB
/
cf-get
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
#! /usr/bin/env ruby
require "rubygems"
require "bundler/setup"
require "fog"
require "fileutils"
require 'trollop'
require 'yaml'
def set_environment(environment)
environments[environment]
end
def environments
YAML::load_file(File.join(File.dirname(File.expand_path(__FILE__)), 'config.yml'))
end
opts = Trollop::options do
opt :file, "", :type => :string
opt :stack, "", :type => :string
opt :environment, "", :type => :string
end
Trollop::die :file, "represent a file to write to" unless opts[:file]
Trollop::die :stack, "represent a stack on aws" unless opts[:stack]
Trollop::die :environment, "needs an environment. Valid values(#{environments.keys.join(',')})" unless environments.keys.include? opts[:environment]
settings = set_environment(opts[:environment])
@connection = Fog::AWS::CloudFormation.new(settings)
stack = @connection.get_template opts[:stack]
filename = opts[:file]
if File.exists?(filename)
old_filename = "#{filename}.#{Time.now.to_i.to_s}"
FileUtils.mv(filename, old_filename)
puts "old cloudformation: #{old_filename}"
end
File.open(filename, mode= "w+"){|file| file.write(stack.body["TemplateBody"]) }
puts filename