Skip to content

Commit f2b5373

Browse files
Created terraform catalog forms and summary pages
1 parent 3e0cd03 commit f2b5373

File tree

12 files changed

+1364
-32
lines changed

12 files changed

+1364
-32
lines changed

app/controllers/catalog_controller.rb

Lines changed: 70 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -237,7 +237,7 @@ def atomic_form_field_changed
237237
build_automate_tree(:automate_catalog) if automate_tree_needed?
238238
if params[:st_prov_type] # build request screen for selected item type
239239
@_params[:org_controller] = "service_template"
240-
if ansible_playbook?
240+
if ansible_playbook? || terraform_template?
241241
@record = ServiceTemplate.new
242242
# waiting for back-end PR to be merged to implement this
243243
# if false
@@ -285,7 +285,10 @@ def atomic_form_field_changed
285285

286286
render :update do |page|
287287
page << javascript_prologue
288-
if @edit[:new][:st_prov_type] == "generic_ansible_playbook"
288+
if @edit[:new][:st_prov_type] == "generic_terraform_template"
289+
page.replace("form_div", :partial => "tt_react_form")
290+
page << javascript_hide("form_buttons_div")
291+
elsif @edit[:new][:st_prov_type] == "generic_ansible_playbook"
289292
page.replace("form_div", :partial => "st_angular_form")
290293
page << javascript_hide("form_buttons_div")
291294
else
@@ -370,6 +373,7 @@ def explorer
370373
end
371374
template_locals = {:locals => {:controller => "catalog"}}
372375
template_locals[:locals].merge!(fetch_playbook_details) if need_ansible_locals?
376+
template_locals[:locals].merge!(fetch_terraform_template_details) if need_terraform_locals?
373377
template_locals[:locals].merge!(fetch_ct_details) if need_container_template_locals?
374378
template_locals[:locals].merge!(fetch_ovf_template_details) if need_ovf_template_locals?
375379

@@ -890,7 +894,7 @@ def resource_action_entry_point(resource_action)
890894
def build_tenants_tree
891895
tenants = @record ? @record.additional_tenants : Tenant.where(:id => @edit[:new][:tenant_ids])
892896
catalog_bundle = @edit.present? && @edit[:key] && @edit[:key].starts_with?('st_edit') # Get the info if adding/editing Catalog Item or Bundle; not important if only displaying
893-
TreeBuilderTenants.new('tenants_tree', @sb, true, :additional_tenants => tenants, :selectable => @edit.present?, :ansible_playbook => ansible_playbook_type?, :catalog_bundle => catalog_bundle)
897+
TreeBuilderTenants.new('tenants_tree', @sb, true, :additional_tenants => tenants, :selectable => @edit.present?, :template => ansible_playbook_type? || terraform_template_type?, :catalog_bundle => catalog_bundle)
894898
end
895899

896900
def svc_catalog_provision_finish_submit_endpoint
@@ -915,6 +919,24 @@ def ansible_playbook?
915919
end
916920
helper_method :ansible_playbook?
917921

922+
def terraform_template_type?
923+
prov_type = if params[:st_prov_type]
924+
params[:st_prov_type]
925+
elsif @record
926+
@record.prov_type
927+
elsif @edit
928+
@edit[:new][:st_prov_type]
929+
end
930+
prov_type == 'generic_terraform_template'
931+
end
932+
933+
def terraform_template?
934+
terraform_template = terraform_template_type?
935+
@current_region = MiqRegion.my_region.region if terraform_template
936+
terraform_template
937+
end
938+
helper_method :terraform_template?
939+
918940
# Get all the available Catalogs
919941
def available_catalogs
920942
Rbac.filtered(ServiceTemplateCatalog.all).collect do |sc|
@@ -1904,7 +1926,7 @@ def get_node_info_handle_leaf_node(id)
19041926
@no_wf_msg = _("Request is missing for selected item")
19051927
end
19061928
end
1907-
unless @record.prov_type == "generic_ansible_playbook"
1929+
unless @record.prov_type == "generic_ansible_playbook" || @record.prov_type == "generic_terraform_template"
19081930
@sb[:dialog_label] = _("No Dialog")
19091931
@sb[:fqname] = nil
19101932
@sb[:reconfigure_fqname] = nil
@@ -2199,6 +2221,40 @@ def fetch_playbook_details
21992221
playbook_details
22002222
end
22012223

2224+
def fetch_terraform_template_details
2225+
terraform_template_details = {}
2226+
provision = @record.config_info[:provision]
2227+
terraform_template_details[:provisioning] = {}
2228+
terraform_template_details[:provisioning][:repository] = fetch_name_from_object(ManageIQ::Providers::EmbeddedTerraform::AutomationManager::ConfigurationScriptSource, provision[:repository_id])
2229+
terraform_template_details[:provisioning][:template] = fetch_name_from_object(ManageIQ::Providers::EmbeddedTerraform::AutomationManager::ConfigurationScriptPayload, provision[:configuration_script_payload_id])
2230+
terraform_template_details[:provisioning][:credential] = fetch_name_from_object(ManageIQ::Providers::EmbeddedTerraform::AutomationManager::Credential, provision[:credential_id])
2231+
terraform_template_details[:provisioning][:network_credential] = fetch_name_from_object(ManageIQ::Providers::EmbeddedTerraform::AutomationManager::NetworkCredential, provision[:network_credential_id]) if provision[:network_credential_id]
2232+
terraform_template_details[:provisioning][:cloud_credential] = fetch_name_from_object(ManageIQ::Providers::EmbeddedTerraform::AutomationManager::CloudCredential, provision[:cloud_credential_id]) if provision[:cloud_credential_id]
2233+
fetch_dialog(terraform_template_details, provision[:dialog_id], :provisioning)
2234+
terraform_template_details[:provisioning][:execution_ttl] = provision[:execution_ttl]
2235+
terraform_template_details[:provisioning][:verbosity] = provision[:verbosity]
2236+
terraform_template_details[:provisioning][:log_output] = provision[:log_output]
2237+
terraform_template_details[:provisioning][:become_enabled] = provision[:become_enabled] == true ? _('Yes') : _('No')
2238+
2239+
if @record.config_info[:retirement]
2240+
retirement = @record.config_info[:retirement]
2241+
terraform_template_details[:retirement] = {}
2242+
terraform_template_details[:retirement][:remove_resources] = retirement[:remove_resources]
2243+
if retirement[:repository_id]
2244+
terraform_template_details[:retirement][:repository] = fetch_name_from_object(ManageIQ::Providers::EmbeddedTerraform::AutomationManager::ConfigurationScriptSource, retirement[:repository_id])
2245+
terraform_template_details[:retirement][:template] = fetch_name_from_object(ManageIQ::Providers::EmbeddedTerraform::AutomationManager::ConfigurationScriptPayload, retirement[:configuration_script_payload_id])
2246+
terraform_template_details[:retirement][:credential] = fetch_name_from_object(ManageIQ::Providers::EmbeddedTerraform::AutomationManager::Credential, retirement[:credential_id])
2247+
terraform_template_details[:retirement][:network_credential] = fetch_name_from_object(ManageIQ::Providers::EmbeddedTerraform::AutomationManager::NetworkCredential, retirement[:network_credential_id]) if retirement[:network_credential_id]
2248+
terraform_template_details[:retirement][:cloud_credential] = fetch_name_from_object(ManageIQ::Providers::EmbeddedTerraform::AutomationManager::CloudCredential, retirement[:cloud_credential_id]) if retirement[:cloud_credential_id]
2249+
end
2250+
terraform_template_details[:retirement][:execution_ttl] = retirement[:execution_ttl]
2251+
terraform_template_details[:retirement][:verbosity] = retirement[:verbosity]
2252+
terraform_template_details[:retirement][:log_output] = retirement[:log_output]
2253+
terraform_template_details[:retirement][:become_enabled] = retirement[:become_enabled] == true ? _('Yes') : _('No')
2254+
end
2255+
terraform_template_details
2256+
end
2257+
22022258
def fetch_dialog(playbook_details, dialog_id, key)
22032259
return nil if dialog_id.nil?
22042260

@@ -2303,6 +2359,8 @@ def replace_right_cell(options = {})
23032359
content = if @tagging
23042360
action_url = x_active_tree == :ot_tree ? "ot_tags_edit" : "st_tags_edit"
23052361
r[:partial => "layouts/x_tagging", :locals => {:action_url => action_url}]
2362+
elsif action && %w[at_st_new st_new].include?(action) && terraform_template?
2363+
r[:partial => "tt_react_form"]
23062364
elsif action && %w[at_st_new st_new].include?(action)
23072365
r[:partial => ansible_playbook? ? "st_angular_form" : "st_form"]
23082366
elsif action && %w[ownership].include?(action)
@@ -2321,6 +2379,7 @@ def replace_right_cell(options = {})
23212379
else
23222380
template_locals = {:controller => "catalog"}
23232381
template_locals.merge!(fetch_playbook_details) if need_ansible_locals?
2382+
template_locals.merge!(fetch_terraform_template_details) if need_terraform_locals?
23242383
template_locals.merge!(fetch_ct_details) if need_container_template_locals?
23252384
template_locals.merge!(fetch_ovf_template_details) if need_ovf_template_locals?
23262385
r[:partial => "catalog/#{x_active_tree}_show", :locals => template_locals]
@@ -2344,7 +2403,7 @@ def replace_right_cell(options = {})
23442403
presenter.hide(:toolbar).show(:paging_div)
23452404
# incase it was hidden for summary screen, and incase there were no records on show_list
23462405
presenter.remove_paging
2347-
if (action == 'at_st_new' && ansible_playbook?) || %w[st_catalog_new st_catalog_edit copy_catalog].include?(action)
2406+
if (action == 'at_st_new' && (ansible_playbook? || terraform_template?)) || %w[st_catalog_new st_catalog_edit copy_catalog].include?(action)
23482407
presenter.hide(:form_buttons_div)
23492408
else
23502409
presenter.show(:form_buttons_div)
@@ -2407,6 +2466,12 @@ def need_ansible_locals?
24072466
@record.prov_type == "generic_ansible_playbook"
24082467
end
24092468

2469+
def need_terraform_locals?
2470+
x_active_tree == :sandt_tree &&
2471+
TreeBuilder.get_model_for_prefix(@nodetype) == "ServiceTemplate" &&
2472+
@record.prov_type == "generic_terraform_template"
2473+
end
2474+
24102475
def need_container_template_locals?
24112476
x_active_tree == :sandt_tree &&
24122477
TreeBuilder.get_model_for_prefix(@nodetype) == "ServiceTemplate" &&

app/helpers/catalog_helper.rb

Lines changed: 34 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -95,15 +95,15 @@ def catalog_tab_content(key_name, &block)
9595

9696
def catalog_basic_information(record, sb_params, tenants_tree)
9797
prov_types = catalog_provision_types
98-
prov_data = [prov_types[:template], prov_types[:ovf]].include?(record.prov_type) && catalog_provision?(record, :playbook) ? provisioning : nil
98+
prov_data = [prov_types[:template], prov_types[:ovf]].include?(record.prov_type) && (catalog_provision?(record, :playbook) || catalog_provision?(record, :terraform_template)) ? provisioning : nil
9999
data = {:title => _('Basic Information'), :mode => "miq_catalog_basic_information"}
100100
rows = []
101101
rows.push(row_data(_('Name'), record.name))
102102
rows.push(row_data(_('Description'), record.description))
103103
rows.push(row_data(_('Display in Catalog'), {:input => "checkbox", :name => "display", :checked => record.display, :disabled => true, :label => ''}))
104104
rows.push(row_data(_('Catalog'), record.service_template_catalog ? record.service_template_catalog.name : _('Unassigned')))
105105
rows.push(row_data(_('Zone'), record.zone ? record.zone.name : '')) unless record.composite?
106-
rows.push(row_data(_('Dialog'), sb_params[:dialog_label])) unless catalog_provision?(record, :playbook)
106+
rows.push(row_data(_('Dialog'), sb_params[:dialog_label])) unless catalog_provision?(record, :playbook) || catalog_provision?(record, :terraform_template)
107107
rows.push(row_data(_("Price / Month (in %{currency})") % {:currency => record.currency.code}, record.price)) if record.currency
108108
rows.push(row_data(_('Item Type'), _(ServiceTemplate.all_catalog_item_types[record.prov_type]))) if record.prov_type
109109
rows.push(row_data(_('Subtype'), _(ServiceTemplate::GENERIC_ITEM_SUBTYPES[record[:generic_subtype]]) || _("Custom"))) if catalog_provision?(record, :generic)
@@ -118,7 +118,7 @@ def catalog_basic_information(record, sb_params, tenants_tree)
118118
rows.push(row_data(_('Container Template'), provision_data(prov_data, :template_name)))
119119
end
120120

121-
unless catalog_provision?(record, :playbook)
121+
unless catalog_provision?(record, :playbook) || catalog_provision?(record, :terraform_template)
122122
entry_points = [[_("Provisioning"), :fqname]]
123123
unless record.prov_type.try(:start_with?, "generic_")
124124
entry_points.push([_("Reconfigure"), :reconfigure_fqname], [_("Retirement"), :retire_fqname])
@@ -184,21 +184,33 @@ def catalog_resources(record)
184184
miq_structured_list(data)
185185
end
186186

187-
def catalog_generic_ansible_playbook_info(type, record, info)
187+
def catalog_generic_template_info(type, record, info)
188188
list_type = type == :provision ? 'provisioning' : 'retirement'
189189
data = {:title => "#{list_type.camelize} %s" % _('Info'), :mode => "miq_catalog_playbook_info"}
190190
rows = []
191191
rows.push(row_data(_('Repository'), info[:repository]))
192-
rows.push(row_data(_('Playbook'), info[:playbook]))
193-
rows.push(row_data(_('Machine Credential'), info[:machine_credential]))
194-
rows.push(row_data(_('Vault Credential'), info[:vault_credential]))
195-
rows.push(row_data(_('Vault Credential'), info[:vault_credential]))
196-
rows.push(row_data(_('Cloud Credential'), info[:cloud_credential]))
197-
rows.push(row_data(_('Max TTL (mins)'), record.config_info[type][:execution_ttl]))
198-
rows.push(row_data(_('Hosts'), record.config_info[type][:hosts]))
199-
rows.push(row_data(_('Logging Output'), ViewHelper::LOG_OUTPUT_LEVELS[info[:log_output]]))
200-
rows.push(row_data(_('Escalate Privilege'), info[:become_enabled]))
201-
rows.push(row_data(_('Verbosity'), _(ViewHelper::VERBOSITY_LEVELS[info[:verbosity]])))
192+
if record.type == 'ServiceTemplateAnsiblePlaybook'
193+
rows.push(row_data(_('Playbook'), info[:playbook]))
194+
rows.push(row_data(_('Machine Credential'), info[:machine_credential]))
195+
rows.push(row_data(_('Vault Credential'), info[:vault_credential]))
196+
rows.push(row_data(_('Vault Credential'), info[:vault_credential]))
197+
rows.push(row_data(_('Cloud Credential'), info[:cloud_credential]))
198+
rows.push(row_data(_('Max TTL (mins)'), record.config_info[type][:execution_ttl]))
199+
rows.push(row_data(_('Hosts'), record.config_info[type][:hosts]))
200+
rows.push(row_data(_('Logging Output'), ViewHelper::LOG_OUTPUT_LEVELS[info[:log_output]]))
201+
rows.push(row_data(_('Escalate Privilege'), info[:become_enabled]))
202+
rows.push(row_data(_('Verbosity'), _(ViewHelper::VERBOSITY_LEVELS[info[:verbosity]])))
203+
else
204+
rows.push(row_data(_('Template'), info[:template]))
205+
rows.push(row_data(_('Machine Credential'), info[:credential]))
206+
rows.push(row_data(_('Cloud Credential'), info[:cloud_credential]))
207+
rows.push(row_data(_('Max TTL (mins)'), record.config_info[type][:execution_ttl]))
208+
rows.push(row_data(_('Hosts'), record.config_info[type][:hosts]))
209+
rows.push(row_data(_('Logging Output'), ViewHelper::LOG_OUTPUT_LEVELS[info[:log_output]]))
210+
rows.push(row_data(_('Escalate Privilege'), info[:become_enabled]))
211+
rows.push(row_data(_('Verbosity'), _(ViewHelper::VERBOSITY_LEVELS[info[:verbosity]])))
212+
data[:rows] = rows
213+
end
202214
data[:rows] = rows
203215
miq_structured_list(data)
204216
end
@@ -238,12 +250,13 @@ def catalog_dialog(provisioning)
238250
end
239251

240252
def catalog_provision_types
241-
{:generic => "generic",
242-
:orchestration => "generic_orchestration",
243-
:ovf => "generic_ovf_template",
244-
:playbook => "generic_ansible_playbook",
245-
:tower => "generic_ansible_tower",
246-
:template => "generic_container_template"}.freeze
253+
{:generic => "generic",
254+
:orchestration => "generic_orchestration",
255+
:ovf => "generic_ovf_template",
256+
:playbook => "generic_ansible_playbook",
257+
:terraform_template => "generic_terraform_template",
258+
:tower => "generic_ansible_tower",
259+
:template => "generic_container_template"}.freeze
247260
end
248261

249262
private
@@ -257,7 +270,7 @@ def catalog_tab_conditions(record)
257270
:detail => record.display && !record.prov_type.try(:start_with?, "generic_"),
258271
:resource => record.composite?,
259272
:request => !record.prov_type || (record.prov_type && need_prov_dialogs?(record.prov_type)),
260-
:provision => record.prov_type == catalog_provision_types[:playbook],
273+
:provision => record.prov_type == catalog_provision_types[:playbook] || record.prov_type == catalog_provision_types[:terraform_template],
261274
:retirement => record.config_info.fetch_path(:retirement)
262275
}
263276
end

app/javascript/components/ansible-playbook-edit-catalog-form/index.jsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -213,7 +213,7 @@ AnsiblePlayBookEditCatalogForm.propTypes = {
213213
tenantTree: PropTypes.shape({
214214
additional_tenants: PropTypes.arrayOf(PropTypes.any).isRequired,
215215
selectable: PropTypes.bool.isRequired,
216-
ansible_playbook: PropTypes.bool.isRequired,
216+
template: PropTypes.bool.isRequired,
217217
catalog_bundle: PropTypes.bool.isRequired,
218218
locals_for_render: PropTypes.shape({
219219
tree_id: PropTypes.string.isRequired,

0 commit comments

Comments
 (0)