Skip to content

Commit

Permalink
new --refresh-parameters flag for update (#212)
Browse files Browse the repository at this point in the history
Adds a new --refresh-parameters flag for update calls allowing stacks
to refresh parent stack parameters if necessary
  • Loading branch information
jfarrell authored and askreet committed Apr 3, 2017
1 parent 3bc5d1c commit d0f1f30
Show file tree
Hide file tree
Showing 3 changed files with 35 additions and 8 deletions.
6 changes: 5 additions & 1 deletion lib/moonshot/commands/update.rb
Original file line number Diff line number Diff line change
Expand Up @@ -18,11 +18,15 @@ def parser
parser.on('--force', '-f', TrueClass, 'Apply ChangeSet without confirmation') do |v|
@force = v
end

parser.on('--refresh-parameters', TrueClass, 'Update parameters from parent stacks') do |v|
@refresh_parameters = v
end
end

def execute
@force = true unless Moonshot.config.interactive
controller.update(dry_run: @dry_run, force: @force)
controller.update(dry_run: @dry_run, force: @force, refresh_parameters: @refresh_parameters)
end
end
end
Expand Down
9 changes: 4 additions & 5 deletions lib/moonshot/controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@ def create # rubocop:disable AbcSize
end
end

def update(dry_run:, force:) # rubocop:disable AbcSize
def update(dry_run:, force:, refresh_parameters:) # rubocop:disable AbcSize
# Scan the template for all required parameters and configure
# the ParameterCollection.
@config.parameters = ParameterCollection.from_template(stack.template)
Expand All @@ -75,7 +75,8 @@ def update(dry_run:, force:) # rubocop:disable AbcSize

# Import all Outputs from parent stacks as Parameters on this
# stack.
ParentStackParameterLoader.new(@config).load_missing_only!
parent_stack_params = ParentStackParameterLoader.new(@config)
refresh_parameters ? parent_stack_params.load! : parent_stack_params.load_missing_only!

# If there is an answer file, use it to populate parameters.
if @config.answer_file
Expand All @@ -91,9 +92,7 @@ def update(dry_run:, force:) # rubocop:disable AbcSize

# Interview the user for missing parameters, using the
# appropriate prompts.
@config.parameters.values.each do |sp|
next if sp.set?

@config.parameters.values.reject(&:set?).each do |sp|
parameter_source = @config.parameter_sources.fetch(sp.name,
@config.default_parameter_source)
parameter_source.get(sp)
Expand Down
28 changes: 26 additions & 2 deletions spec/moonshot/controller_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -153,8 +153,7 @@
}
expect(stack).to receive(:parameters).and_return(existing_parameters)
expect(stack).to receive(:update)

subject.update(dry_run: false, force: false)
subject.update(dry_run: false, force: false, refresh_parameters: false)

pc = subject.config.parameters
expect(pc.keys).to eq(%w(InputParameter1 InputParameter2 InputParameter3 InputParameter4))
Expand All @@ -168,4 +167,29 @@
expect(pc.values.map(&:to_cf)).to eq(expected_update_stack_parameters)
end
end

context 'when refresh-parameters option is provided' do
before(:each) do
subject.config.answer_file = fixture_path('answer2.yml')
subject.config.parameter_overrides['InputParameter4'] = 'Override4'

existing_parameters = {
'InputParameter1' => 'Existing1',
'InputParameter2' => 'Existing2',
'InputParameter3' => 'Existing3'
}
expect(stack).to receive(:parameters).and_return(existing_parameters)
expect(stack).to receive(:update)
end

it 'should preserve existing existing parent parameters' do
expect_any_instance_of(Moonshot::ParentStackParameterLoader).to receive(:load_missing_only!)
subject.update(dry_run: false, force: false, refresh_parameters: false)
end

it 'should refresh all parent stack parameters' do
expect_any_instance_of(Moonshot::ParentStackParameterLoader).to receive(:load!)
subject.update(dry_run: false, force: false, refresh_parameters: true)
end
end
end

0 comments on commit d0f1f30

Please sign in to comment.