Skip to content

Commit d4f87f4

Browse files
committed
fix: allow image based deployment without user-data
1 parent 1fd289a commit d4f87f4

2 files changed

Lines changed: 20 additions & 0 deletions

File tree

app/services/foreman_opentofu/opentofu_executer.rb

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff 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)

app/views/templates/provisioning/hetzner_provision_host.erb

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff 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
2034
resource "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

0 commit comments

Comments
 (0)