Module: KnifeCloudformation::Knife::Stack::InstanceMethods
- Defined in:
- lib/knife-cloudformation/knife/stack.rb
Constant Summary collapse
- MAX_PARAMETER_ATTEMPTS =
maximum number of attempts to get valid parameter value
5
Instance Method Summary collapse
-
#populate_parameters!(stack) ⇒ Hash
Prompt for parameter values and store result.
Instance Method Details
#populate_parameters!(stack) ⇒ Hash
Prompt for parameter values and store result
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 44 45 46 47 48 |
# File 'lib/knife-cloudformation/knife/stack.rb', line 18 def populate_parameters!(stack) if(Chef::Config[:knife][:cloudformation][:interactive_parameters]) if(stack['Parameters'] || stack['parameters']) Chef::Config[:knife][:cloudformation][:options][:parameters] ||= Mash.new stack.fetch('Parameters', stack.fetch('parameters', {})).each do |k,v| next if Chef::Config[:knife][:cloudformation][:options][:parameters][k] attempt = 0 valid = false until(valid) attempt += 1 default = Chef::Config[:knife][:cloudformation][:options][:parameters][k] || v['Default'] || v['default'] answer = ui.ask_question("#{k.split(/([A-Z]+[^A-Z]*)/).find_all{|s|!s.empty?}.join(' ')}: ", :default => default) validation = KnifeCloudformation::Utils::StackParameterValidator.validate(answer, v) if(validation == true) Chef::Config[:knife][:cloudformation][:options][:parameters][k] = answer valid = true else validation.each do |validation_error| ui.error validation_error.last end end if(attempt > MAX_PARAMETER_ATTEMPTS) ui.fatal 'Failed to receive allowed parameter!' exit 1 end end end end end stack end |