Skip to content

Commit

Permalink
Parse dialog options as Extra Vars
Browse files Browse the repository at this point in the history
  • Loading branch information
agrare committed Jun 3, 2024
1 parent d07d565 commit 47b10d3
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 7 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -21,13 +21,9 @@ def pre_execute
def execute
template_path = File.join(options[:git_checkout_tempdir], template_relative_path)
credentials = Authentication.where(:id => options[:credentials])
input_vars = decrypt_input_vars(options[:input_vars])

response = Terraform::Runner.run(
options[:input_vars],
template_path,
:credentials => credentials,
:env_vars => options[:env_vars]
)
response = Terraform::Runner.run(input_vars, template_path, :credentials => credentials, :env_vars => options[:env_vars])

options[:terraform_stack_id] = response.stack_id
save!
Expand Down Expand Up @@ -110,6 +106,13 @@ def stack_response
@stack_response ||= Terraform::Runner::ResponseAsync.new(options[:terraform_stack_id])
end

def decrypt_input_vars(input_vars)
input_vars
.dup
.fetch("extra_vars", {})
.transform_values { |val| val.kind_of?(String) ? ManageIQ::Password.try_decrypt(val) : val }
end

def configuration_script_source
@configuration_script_source ||= template.configuration_script_source
end
Expand Down
13 changes: 12 additions & 1 deletion app/models/service_terraform_template.rb
Original file line number Diff line number Diff line change
Expand Up @@ -85,7 +85,7 @@ def save_job_options(action, overrides)
job_options[:extra_vars].try(:transform_values!) do |val|
val.kind_of?(String) ? val : val[:default] # TODO: support Hash only
end
# TODO: job_options.deep_merge!(parse_dialog_options) unless action == ResourceAction::RETIREMENT
job_options.deep_merge!(parse_dialog_options) unless action == ResourceAction::RETIREMENT
job_options.deep_merge!(overrides)
translate_credentials!(job_options)

Expand All @@ -97,6 +97,17 @@ def job_option_key(action)
"#{action.downcase}_job_options".to_sym
end

def parse_dialog_options
dialog_options = options[:dialog] || {}

params = dialog_options.each_with_object({}) do |(attr, val), obj|
var_key = attr.sub(/^(password::)?dialog_/, '')
obj[var_key] = val
end

params.blank? ? {} : {:extra_vars => params}
end

def translate_credentials!(options)
options[:credentials] = []

Expand Down

0 comments on commit 47b10d3

Please sign in to comment.