vagrant-terraform 0.1.3 → 0.1.6

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: 2522d1ea4a52b4c972f6abf6a66f11f361ec801a26fb5bcb089d286a6cd292df
4
- data.tar.gz: 703b30e9a3cb591a6022ad372ed5a1e9932bb319c170a07eda801659a14d734b
3
+ metadata.gz: b91e84fbdc3a525218339936061f9350f02db124777bb7b07d1ac17229e02c6c
4
+ data.tar.gz: ae303b93001724e9696a22de69eca6f4d1822dc1063763a8d40aeaa1f9c73878
5
5
  SHA512:
6
- metadata.gz: e361ce86c637c40b6b72510686a6cf9a77238f36fb7f8848965aeacac3acd95356d4928ddc6678d5a5c93108b8aaab38eb9d3eb6e74591706d461a6a0eeb356a
7
- data.tar.gz: 448483359a5f6d30a4e95a5463edcb297504dae0ed4f42b65ede44a2834a1c9d9821c59bd123e9f2ae5132ce875e44fcf55754a085031ba72edcfae00442e1cb
6
+ metadata.gz: c26f1555ad6de110ddac0b844eb50d34ce1dde3f93b8918ccf33ab4cd0848f4d54ff373ca973cbb2ae29bddb5e2f0481f00085beaacb9c3b690fb7989b05ad62
7
+ data.tar.gz: 6e381a75c334749f0d8f1368a4f781a17b2f125d528544a30a0406fbca0104546bf2bfe2784ca75d2eacd07380f823fd29d6dc00984819addd7bba2901583ee3
@@ -0,0 +1,32 @@
1
+ name: Ruby Gem
2
+ on:
3
+ push:
4
+ tags:
5
+ - release/*
6
+
7
+ jobs:
8
+ build:
9
+ name: Build + Publish
10
+ runs-on: ubuntu-latest
11
+ permissions:
12
+ contents: read
13
+ packages: write
14
+
15
+ steps:
16
+ - uses: actions/checkout@v4
17
+ - name: Set up Ruby 3.3.6
18
+ uses: ruby/setup-ruby@v1
19
+ with:
20
+ ruby-version: 3.3.6
21
+
22
+ - name: Publish to RubyGems
23
+ run: |
24
+ mkdir -p $HOME/.gem
25
+ touch $HOME/.gem/credentials
26
+ chmod 0600 $HOME/.gem/credentials
27
+ printf -- "---\n:rubygems_api_key: ${GEM_HOST_API_KEY}\n" > $HOME/.gem/credentials
28
+ gem build *.gemspec
29
+ gem push *.gem
30
+ env:
31
+ GEM_HOST_API_KEY: "${{secrets.RUBYGEMS_AUTH_TOKEN}}"
32
+
data/README.md CHANGED
@@ -7,7 +7,6 @@ Could be extended to support other Terraform providers in addition to Proxmox bu
7
7
  the moment I'm not planning to.
8
8
 
9
9
  Things I'm _not_ planning to do (due to lack of time and resources):
10
- * Put this in rubygems.org. If you want to use this, roll your own gem like instructed below.
11
10
  * Support other Terraform providers unless I have to move away from Proxmox to something else.
12
11
  * Add support for suspend / snapshots.
13
12
  * Support / test anything other than Ubuntu/Fedora
@@ -15,6 +14,12 @@ Things I'm _not_ planning to do (due to lack of time and resources):
15
14
 
16
15
  ## Installation
17
16
 
17
+ From rubygems.org
18
+ ```
19
+ vagrant plugin install vagrant-terraform
20
+ ```
21
+
22
+ Build & install:
18
23
  ```
19
24
  $ gem build *.gemspec
20
25
  $ vagrant plugin install *.gem
@@ -80,6 +80,7 @@ resource "proxmox_vm_qemu" "#{vmname.gsub(/\./, '-')}" {
80
80
  }
81
81
  }
82
82
  }
83
+ %SERIAL%
83
84
  nameserver = "#{config.nameserver}"
84
85
  searchdomain = "#{config.searchdomain}"
85
86
  %NETWORKS%
@@ -116,6 +117,18 @@ terraform {
116
117
  ipconfig%IDX% = "%IP%"
117
118
  END
118
119
 
120
+ serial_template = <<-END
121
+ serial {
122
+ id = 0
123
+ type = "socket"
124
+ }
125
+ END
126
+ if config.serial_port
127
+ main_tf = main_tf.gsub(/%SERIAL%/, serial_template)
128
+ else
129
+ main_tf = main_tf.gsub(/%SERIAL%/, '')
130
+ end
131
+
119
132
  vagrantfile_networks = []
120
133
  env[:machine].id = vmname
121
134
  env[:machine].config.vm.networks.each_with_index do |network, idx|
@@ -150,8 +163,8 @@ END
150
163
  env[:ui].info(" -- Target node: #{config.target_node}")
151
164
  env[:ui].info(" -- Storage domain: #{config.storage_domain}")
152
165
  env[:ui].info(" -- CPU Cores: #{config.cpu_cores}")
153
- env[:ui].info(" -- Memory: #{Filesize.from("#{config.memory_size} B").to_f('MiB').to_i} MB")
154
- env[:ui].info(" -- Disk: #{Filesize.from("#{config.disk_size} B").to_f('GiB').to_i} GB") unless config.disk_size.nil?
166
+ env[:ui].info(" -- Memory: #{Filesize.from("#{config.memory_size} B").to_f('MB').to_i} MB")
167
+ env[:ui].info(" -- Disk: #{Filesize.from("#{config.disk_size} B").to_f('GB').to_i} GB") unless config.disk_size.nil?
155
168
 
156
169
  terraform_dir = env[:machine_tf_dir]
157
170
  terraform_main_file = "#{terraform_dir}/main.tf"
@@ -171,6 +184,18 @@ END
171
184
  raise e
172
185
  end
173
186
 
187
+ # Terraform error message was 'clone failed: cfs-lock 'storage-qnap-nfs' error: got lock request timeout'
188
+ if e.message.gsub(ansi_escape_regex, '').include?("clone failed: cfs-lock")
189
+ env[:ui].info("Proxmox unable to get storage lock, retrying")
190
+ raise e
191
+ end
192
+
193
+ # Terraform error message was 'clone failed: 'storage-qnap-nfs'-locked command timed out - aborting'
194
+ if e.message.gsub(ansi_escape_regex, '').include?("command timed out")
195
+ env[:ui].info("Proxmox clone template, retrying")
196
+ raise e
197
+ end
198
+
174
199
  if e.message.gsub(ansi_escape_regex, '') =~ /.*Error: [0-9 ]*unable to create VM [0-9]*: config file already exists/
175
200
  env[:ui].info("Proxmox ID conflict, retrying")
176
201
  raise e
@@ -1,8 +1,9 @@
1
1
  require 'log4r'
2
- require 'vagrant-terraform/util/timer'
3
- require 'vagrant-terraform/util/terraform_execute'
4
2
  require 'socket'
5
3
  require 'timeout'
4
+ require 'vagrant-terraform/util/timer'
5
+ require 'vagrant-terraform/util/terraform_execute'
6
+ Vagrant.require 'net/ssh'
6
7
 
7
8
  module VagrantPlugins
8
9
  module TerraformProvider
@@ -18,21 +19,30 @@ module VagrantPlugins
18
19
  @app = app
19
20
  end
20
21
 
21
- def port_open?(ip, port, seconds=10)
22
- # => checks if a port is open or not on a remote host
23
- Timeout::timeout(seconds) do
22
+ def port_open?(ip)
23
+ # Check if ssh server responds, AuthenticationFailed is what we expect to get.
24
+ # If credentials vagrant:vagrant happen to work that's a success as well.
25
+ begin
24
26
  begin
25
- TCPSocket.new(ip, port).close
26
- @logger.info("SSH Check OK for IP: #{ip}")
27
- true
28
- rescue Errno::ECONNREFUSED, Errno::EHOSTUNREACH, SocketError => e
29
- @logger.info("SSH Connection Failed for IP #{ip}: #{e}")
30
- false
27
+ ssh = Net::SSH.start(ip, "vagrant", password: "vagrant",
28
+ non_interactive: true, user_known_hosts_file: [],
29
+ verify_host_key: :never)
30
+ ensure
31
+ ssh&.close
31
32
  end
33
+ return true
34
+ rescue Errno::ECONNREFUSED, Errno::EHOSTUNREACH
35
+ return false
36
+ rescue Net::SSH::AuthenticationFailed
37
+ return true
38
+ rescue Errno::ECONNRESET
39
+ @logger.debug("Got connection reset")
40
+ return false
41
+ rescue StandardError => e
42
+ @logger.debug("Got error #{e.message}")
43
+ return false
32
44
  end
33
- rescue Timeout::Error
34
- @logger.info("SSH Connection Failed: Timeout for IP: #{ip}" )
35
- false
45
+ return false
36
46
  end
37
47
 
38
48
  def call(env)
@@ -42,7 +52,7 @@ module VagrantPlugins
42
52
  # Wait for VM to obtain an ip address.
43
53
  env[:metrics]["instance_ip_time"] = Util::Timer.time do
44
54
  env[:ui].info(I18n.t("vagrant_terraform.waiting_for_ip"))
45
- for attempt in 1..300
55
+ for attempt in 1..100
46
56
  # If we're interrupted don't worry about waiting
47
57
  next if env[:interrupted]
48
58
 
@@ -51,7 +61,7 @@ module VagrantPlugins
51
61
  unless ip_addr.nil?
52
62
  env[:ui].info("Got IP (attempt #{attempt}): #{ip_addr}")
53
63
  # Check if SSH-Server is up
54
- if port_open?(ip_addr, 22)
64
+ if port_open?(ip_addr)
55
65
  env[:ip_address] = ip_addr
56
66
  @logger.debug("Got output #{env[:ip_address]}")
57
67
  break
@@ -56,8 +56,8 @@ module VagrantPlugins
56
56
  end
57
57
 
58
58
  b2.use ProvisionerCleanup, :before if defined?(ProvisionerCleanup)
59
- b2.use HaltVM unless env[:machine].state.id == :stopped
60
- # b2.use WaitTillDown unless env[:machine].state.id == :stopped
59
+ # Maybe with sshfs clean halting could be beneficial
60
+ # b2.use HaltVM unless env[:machine].state.id == :stopped
61
61
  b2.use DestroyVM
62
62
  end
63
63
  end
@@ -25,6 +25,7 @@ module VagrantPlugins
25
25
  attr_accessor :searchdomain
26
26
  attr_accessor :os_type
27
27
  attr_accessor :full_clone
28
+ attr_accessor :serial_port
28
29
 
29
30
  def initialize
30
31
  @api_url = UNSET_VALUE
@@ -46,6 +47,7 @@ module VagrantPlugins
46
47
  @searchdomain = UNSET_VALUE
47
48
  @os_type = UNSET_VALUE
48
49
  @full_clone = UNSET_VALUE
50
+ @serial_port = UNSET_VALUE
49
51
  end
50
52
 
51
53
  def finalize!
@@ -68,6 +70,7 @@ module VagrantPlugins
68
70
  @searchdomain = '' if @searchdomain == UNSET_VALUE
69
71
  @os_type = 'l26' if @os_type == UNSET_VALUE
70
72
  @full_clone = true if @full_clone == UNSET_VALUE
73
+ @serial_port = false if @serial_port == UNSET_VALUE
71
74
 
72
75
  unless disk_size.nil?
73
76
  begin
@@ -1,6 +1,6 @@
1
1
  module VagrantPlugins
2
2
  module TerraformProvider
3
- VERSION = '0.1.3'
3
+ VERSION = '0.1.6'
4
4
  end
5
5
  end
6
6
 
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: vagrant-terraform
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.3
4
+ version: 0.1.6
5
5
  platform: ruby
6
6
  authors:
7
7
  - Mika Båtsman
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2025-01-07 00:00:00.000000000 Z
11
+ date: 2025-01-14 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: filesize
@@ -31,6 +31,7 @@ executables: []
31
31
  extensions: []
32
32
  extra_rdoc_files: []
33
33
  files:
34
+ - ".github/workflows/build-gem.yml"
34
35
  - ".gitignore"
35
36
  - Gemfile
36
37
  - Gemfile.lock
@@ -83,7 +84,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
83
84
  - !ruby/object:Gem::Version
84
85
  version: '0'
85
86
  requirements: []
86
- rubygems_version: 3.2.33
87
+ rubygems_version: 3.5.22
87
88
  signing_key:
88
89
  specification_version: 4
89
90
  summary: This vagrant plugin provides the ability to create, control, and destroy