Skip to content

Commit

Permalink
Added template file as a configuration option. (#264)
Browse files Browse the repository at this point in the history
  • Loading branch information
jamesiarmes authored and bronislav committed Sep 24, 2019
1 parent bad66eb commit 15c5efe
Show file tree
Hide file tree
Showing 8 changed files with 50 additions and 3 deletions.
4 changes: 4 additions & 0 deletions lib/moonshot/commands/create.rb
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,10 @@ def parser
parser.on('--version VERSION_NAME', 'Version for initial deployment. If unset, a new development build is created from the local directory') do |v| # rubocop:disable LineLength
@version = v
end

parser.on('--template-file=FILE', 'Override the path to the CloudFormation template.') do |v| # rubocop:disable LineLength
Moonshot.config.template_file = v
end
end

def execute
Expand Down
7 changes: 7 additions & 0 deletions lib/moonshot/commands/delete.rb
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,13 @@ class Delete < Moonshot::Command
self.usage = 'delete [options]'
self.description = 'Delete an existing environment'

def parser
parser = super
parser.on('--template-file=FILE', 'Override the path to the CloudFormation template.') do |v| # rubocop:disable LineLength
Moonshot.config.template_file = v
end
end

def execute
controller.delete
end
Expand Down
4 changes: 4 additions & 0 deletions lib/moonshot/commands/update.rb
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,10 @@ def parser
parser.on('--refresh-parameters', TrueClass, 'Update parameters from parent stacks') do |v|
@refresh_parameters = v
end

parser.on('--template-file=FILE', 'Override the path to the CloudFormation template.') do |v| # rubocop:disable LineLength
Moonshot.config.template_file = v
end
end

def execute
Expand Down
1 change: 1 addition & 0 deletions lib/moonshot/controller_config.rb
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ class ControllerConfig
attr_accessor :ssh_command
attr_accessor :ssh_config
attr_accessor :ssh_instance
attr_accessor :template_file
attr_accessor :template_s3_bucket

def initialize
Expand Down
7 changes: 7 additions & 0 deletions lib/moonshot/stack.rb
Original file line number Diff line number Diff line change
Expand Up @@ -159,7 +159,14 @@ def load_template_file
)
]

# If a template file has been specified in the config, look there first.
if @config.template_file
templates.unshift YamlStackTemplate.new(@config.template_file)
templates.unshift JsonStackTemplate.new(@config.template_file)
end

template = templates.find(&:exist?)

raise 'No template found in moonshot/template.{yml,json}!' unless template
template
end
Expand Down
6 changes: 3 additions & 3 deletions lib/plugins/dynamic_template.rb
Original file line number Diff line number Diff line change
Expand Up @@ -14,9 +14,9 @@ def run_hook
end

def cli_hook(parser)
parser.on('-sPATH', '--destination-path=PATH',
'Destination path for the dynamically generated template', String) do |value|
@dynamic_template.destination = value
parser.on('--template-file=FILE', 'Override the path to the CloudFormation template.') do |v| # rubocop:disable LineLength
@dynamic_template.destination = v
Moonshot.config.template_file = v
end
end

Expand Down
12 changes: 12 additions & 0 deletions spec/fs_fixtures/moonshot/custom.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
{
"Resources": {

},

"Parameters": {
"Parent1": {
"Type": "String",
"Description": "This is imported from the parent stack on create."
}
}
}
12 changes: 12 additions & 0 deletions spec/moonshot/stack_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -152,5 +152,17 @@
expect { subject.template }
.to raise_error(RuntimeError, /No template found/)
end

context 'a custom template file is specified' do
let(:custom_path) { File.join(Dir.pwd, 'moonshot', 'custom.json') }

before(:each) do
config.template_file = custom_path
end

it 'should load the custom template' do
expect(subject.template.filename).to eq(custom_path)
end
end
end
end

0 comments on commit 15c5efe

Please sign in to comment.