File tree Expand file tree Collapse file tree
services/foreman_opentofu
views/templates/provisioning Expand file tree Collapse file tree Original file line number Diff line number Diff line change @@ -103,6 +103,8 @@ def render_template(mode)
103103 host_name : @host_name ,
104104 resource : @resource ,
105105 dry_run : dry_run ( mode ) ,
106+ # FIXME: this should come from remote_execution_ssh_keys-hostparam
107+ ssh_keys : SmartProxy . with_features ( %w[ SSH Script ] ) &.pluck ( :pubkey ) &.compact ,
106108 user_data_filename : @user_data_filename ,
107109 }
108110 scope = Foreman ::Renderer . get_scope ( source : template , variables : variables )
Original file line number Diff line number Diff line change @@ -16,6 +16,20 @@ provider "hcloud" {
1616<%= resource_block(@resource) %>
1717
1818<% elsif !@dry_run %>
19+ <%
20+ ssh_key_labels = []
21+ if @ssh_keys.present?
22+ @ssh_keys.each_index do |idx|
23+ label = "ssh_key_#{idx}"
24+ ssh_key_labels << label
25+ %>
26+ resource "hcloud_ssh_key" "<%= label %> " {
27+ name = "<%= label %> "
28+ public_key = "<%= @ssh_keys[idx] %> "
29+ }
30+ <% end
31+ end %>
32+
1933# Create a new server running debian
2034resource "hcloud_server" "node1" {
2135 name = "<%= @host_name %> "
@@ -28,6 +42,10 @@ resource "hcloud_server" "node1" {
2842 image = <%= @cr_attrs['image_id'] %>
2943 <%- if @user_data_filename.present? %>
3044 user_data = "${file("<%= @user_data_filename %> ")}"
45+ <%- elsif @ssh_keys.present? %>
46+ ssh_keys = [
47+ <%= ssh_key_labels.map { |lbl| "hcloud_ssh_key.#{lbl}.id" }.join(",\n") %>
48+ ]
3149 <%- end %>
3250 <%- end %>
3351
You can’t perform that action at this time.
0 commit comments