foreman_opentofu 0.0.8 → 0.0.9

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 1c6c33726e58d82ca151e1fea14387dc4641bf22ddc119516d7bb8677d9a4e3d
4
- data.tar.gz: 7a6c5f927baa086f56c4c05334e6290186ff006f959ff4c41ec3e200454217d6
3
+ metadata.gz: d503531c6bffeae87aa7690aa461bc02b648b9c41fc6073b26f9bd5103497aac
4
+ data.tar.gz: 0453a378d1fc82ea7f0138e7b64b52c0f0cbb2c90f4e215ca9aeb0667df9ba7b
5
5
  SHA512:
6
- metadata.gz: dca5c1a3e49b1e08c4dde175a672e4264759546cff70af0e0f160abd0f6af5cec3f5331d998e426bc716024b98245098213d486f3d06f2bd7d35790396fab8c8
7
- data.tar.gz: 2b0bfb50ed66c7d7fbca8cdf0fb59049b0a6624758332e60e3f4c97cdae79baa32bb21b88cbdb5087e02fe3288a048b2c64f61e3f2080dbf8c71fba0b18bb434
6
+ metadata.gz: ab3fcc15fbaf60eabad7af66a09054a82258124cb1df8ff5bde465a61afe2053588f6cc6166b023010476cb30182992753956d54fea93a609c11787abbe068eb
7
+ data.tar.gz: 1214ef83924634b8a9772cd49dafc04ab17a6797d36bbd9c9c0295f35dc433ea981c0e2fcbc1dca9ab88f748b9c1a5a177a9a5308006c55ea30c81b6cca8657b
@@ -12,6 +12,7 @@ module ForemanOpentofu
12
12
  def initialize(workdir, opts = {})
13
13
  @workdir = workdir
14
14
  @variables = opts[:variables]
15
+ @compute_resource = opts[:compute_resource]
15
16
  end
16
17
 
17
18
  # rubocop:disable Style/SingleLineMethods
@@ -169,14 +170,30 @@ module ForemanOpentofu
169
170
  cmd.map { |item| "'#{item}'" }.append('2>&1').join(' ')
170
171
  end
171
172
 
172
- def common_envvars
173
+ def http_proxy_vars
174
+ return {} unless @compute_resource&.http_proxy
175
+
173
176
  {
177
+ 'http_proxy' => @compute_resource.http_proxy.full_url,
178
+ 'https_proxy' => @compute_resource.http_proxy.full_url,
179
+ # add Foreman-FQDN to no_proxy to ensure TfState-API is not proxied
180
+ 'no_proxy' => URI.split(Setting[:foreman_url])[2],
181
+ }
182
+ end
183
+
184
+ def cli_config_envvars
185
+ path = ForemanOpentofu::OPENTOFU_CLI_CONFIG_PATH
186
+ File.exist?(path) ? { 'TF_CLI_CONFIG_FILE' => path } : {}
187
+ end
188
+
189
+ def common_envvars
190
+ http_proxy_vars.merge(cli_config_envvars).merge({
174
191
  'TF_PLUGIN_CACHE_DIR' => ForemanOpentofu::OPENTOFU_PLUGIN_CACHE_PATH,
175
192
  'TEMPDIR' => ForemanOpentofu::OPENTOFU_TMP_PATH,
176
193
  'TMPDIR' => ForemanOpentofu::OPENTOFU_TMP_PATH,
177
194
  'TMP' => ForemanOpentofu::OPENTOFU_TMP_PATH,
178
195
  'TEMP' => ForemanOpentofu::OPENTOFU_TMP_PATH,
179
- }
196
+ })
180
197
  end
181
198
 
182
199
  def terraform_envvars
@@ -26,7 +26,7 @@ module ForemanOpentofu
26
26
  f.write(@cr_attrs['user_data'])
27
27
  end
28
28
  end
29
- tofu = AppWrapper.new(dir, variables: provider_variables)
29
+ tofu = AppWrapper.new(dir, variables: provider_variables, compute_resource: @compute_resource)
30
30
  @use_backend = %w[create destroy output keygen].include?(mode)
31
31
  @token = create_token(@host_name) if @use_backend
32
32
  tofu.main_configuration = render_template(mode)
@@ -1,4 +1,6 @@
1
1
  <%= field_set_tag _("Common fields"), :id => "compute_ressource_common_field_set" do %>
2
+ <%= http_proxy_field f %>
3
+
2
4
  <%= select_f f,
3
5
  :opentofu_provider,
4
6
  ForemanOpentofu::ProviderTypeManager.enabled_provider_types,
@@ -16,3 +16,7 @@
16
16
  <td><%= _("Caching") %></td>
17
17
  <td><%= @compute_resource.caching_enabled ? _("Enabled") : _("Disabled") %></td>
18
18
  </tr>
19
+ <tr>
20
+ <td><%= _('HTTP-Proxy') %></td>
21
+ <td><%= @compute_resource.http_proxy.present? ? link_to(@compute_resource.http_proxy, edit_http_proxy_path(@compute_resource.http_proxy)) : '' %></td>
22
+ </tr>
@@ -39,6 +39,13 @@ module ForemanOpentofu
39
39
  description: N_('Number of Bits for the SSH-Key required to provision hosts on image-based providers.')
40
40
  end
41
41
  end
42
+
43
+ # These actions use one-time-token authentication so tofu can report the TfState.
44
+ tests_to_skip 'AccessPermissionsTest' => [
45
+ 'api/v2/tf_states/create should have a permission that grants access',
46
+ 'api/v2/tf_states/destroy should have a permission that grants access',
47
+ 'api/v2/tf_states/show should have a permission that grants access',
48
+ ]
42
49
  end
43
50
  end
44
51
  end
@@ -1,3 +1,3 @@
1
1
  module ForemanOpentofu
2
- VERSION = '0.0.8'.freeze
2
+ VERSION = '0.0.9'.freeze
3
3
  end
@@ -7,4 +7,5 @@ module ForemanOpentofu
7
7
  OPENTOFU_MAIN_PATH = '/var/lib/foreman-opentofu'.freeze
8
8
  OPENTOFU_TMP_PATH = File.join(OPENTOFU_MAIN_PATH, 'tmp').freeze
9
9
  OPENTOFU_PLUGIN_CACHE_PATH = File.join(OPENTOFU_MAIN_PATH, 'plugin-cache').freeze
10
+ OPENTOFU_CLI_CONFIG_PATH = '/etc/foreman/tofurc'.freeze
10
11
  end
@@ -2,6 +2,14 @@ FactoryBot.modify do
2
2
  factory :compute_resource do
3
3
  provider { 'Tofu' }
4
4
 
5
+ trait :with_template do
6
+ attrs do
7
+ {
8
+ opentofu_template_id: FactoryBot.create(:provisioning_template, template_kind: TemplateKind.find_or_create_by(name: 'opentofu_script')).id,
9
+ }
10
+ end
11
+ end
12
+
5
13
  trait :opentofu_hetzner do
6
14
  opentofu_provider { :hetzner }
7
15
  user { 'dummy' }
@@ -14,6 +22,7 @@ FactoryBot.modify do
14
22
  password { '{"credentials":{"privateKey":"test-only"}}' }
15
23
  user { '11111111-1111-4111-8111-111111111111' }
16
24
  url { nil }
25
+ after(:build) { |cr| cr.stubs(:setup_key_pair) }
17
26
  end
18
27
 
19
28
  trait :opentofu_nutanix do
@@ -24,6 +33,10 @@ FactoryBot.modify do
24
33
  # uuid { 'vdatacenter' } # alias for datacenter
25
34
  # after(:build) { |cr| cr.stubs(:update_public_key) }
26
35
  end
36
+
37
+ trait :no_keygen do
38
+ after(:build) { |cr| cr.stubs(:setup_key_pair) }
39
+ end
27
40
  end
28
41
  end
29
42
 
@@ -2,13 +2,15 @@ require 'test_plugin_helper'
2
2
 
3
3
  module ForemanOpentofu
4
4
  class AppWrapperTest < ActiveSupport::TestCase
5
+ let(:compute_resource) { FactoryBot.create(:opentofu_hetzner_cr, :no_keygen, :with_template) }
5
6
  let(:app_wrapper) do
6
7
  AppWrapper.new(
7
8
  File.join('/tmp', "app_wrapper_test_#{rand(9999).to_s.rjust(4, '0')}"),
8
9
  variables: {
9
10
  user: 'admin',
10
11
  password: 'secret',
11
- }
12
+ },
13
+ compute_resource: compute_resource
12
14
  )
13
15
  end
14
16
 
@@ -198,6 +200,19 @@ module ForemanOpentofu
198
200
  end
199
201
  end
200
202
 
203
+ test 'http_proxy variables empty by default' do
204
+ assert_empty app_wrapper.send(:http_proxy_vars)
205
+ end
206
+
207
+ test 'http_proxy variables if present in compute_resource' do
208
+ compute_resource.http_proxy = FactoryBot.create(:http_proxy)
209
+
210
+ vars = app_wrapper.send(:http_proxy_vars)
211
+ assert_equal %w[http_proxy https_proxy no_proxy], vars.keys.sort
212
+ assert_equal compute_resource.http_proxy.full_url, vars['http_proxy']
213
+ assert_equal 'foreman.example.com', vars['no_proxy']
214
+ end
215
+
201
216
  test 'create_variables_file()' do
202
217
  app_wrapper.create_variables_file
203
218
  expected = "variable \"user\" {\n type = string\n sensitive = false\n}"
@@ -226,7 +226,7 @@ module ForemanOpentofu
226
226
  password: @compute_resource.password,
227
227
  endpoint: @compute_resource.url,
228
228
  }
229
- AppWrapper.expects(:new).with(kind_of(String), variables: expected_variables).returns(@app_mock)
229
+ AppWrapper.expects(:new).with(kind_of(String), variables: expected_variables, compute_resource: @compute_resource).returns(@app_mock)
230
230
 
231
231
  stub_opentofu_tmp_dir do
232
232
  @executor.run_test_connection
@@ -237,7 +237,7 @@ module ForemanOpentofu
237
237
  compute_resource = FactoryBot.build_stubbed(:opentofu_hetzner_cr)
238
238
  executor = OpentofuExecuter.new(compute_resource)
239
239
  executor.stubs(:render_template).returns('rendered template')
240
- AppWrapper.expects(:new).with(kind_of(String), variables: { password: compute_resource.password }).returns(@app_mock)
240
+ AppWrapper.expects(:new).with(kind_of(String), variables: { password: compute_resource.password }, compute_resource: compute_resource).returns(@app_mock)
241
241
 
242
242
  stub_opentofu_tmp_dir do
243
243
  executor.run_test_connection
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: foreman_opentofu
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.8
4
+ version: 0.0.9
5
5
  platform: ruby
6
6
  authors:
7
7
  - ATIX AG