vagrant-terraform 0.1.3

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.
Files changed (35) hide show
  1. checksums.yaml +7 -0
  2. data/.gitignore +10 -0
  3. data/Gemfile +11 -0
  4. data/Gemfile.lock +11 -0
  5. data/LICENSE +21 -0
  6. data/README.md +120 -0
  7. data/example_box/README.md +12 -0
  8. data/example_box/Vagrantfile +14 -0
  9. data/example_box/dummy.box +0 -0
  10. data/example_box/metadata.json +4 -0
  11. data/lib/vagrant-terraform/action/create_vm.rb +205 -0
  12. data/lib/vagrant-terraform/action/destroy_vm.rb +39 -0
  13. data/lib/vagrant-terraform/action/halt_vm.rb +39 -0
  14. data/lib/vagrant-terraform/action/is_created.rb +19 -0
  15. data/lib/vagrant-terraform/action/is_running.rb +19 -0
  16. data/lib/vagrant-terraform/action/read_ssh_info.rb +44 -0
  17. data/lib/vagrant-terraform/action/read_state.rb +67 -0
  18. data/lib/vagrant-terraform/action/setup_terraform.rb +42 -0
  19. data/lib/vagrant-terraform/action/start_vm.rb +51 -0
  20. data/lib/vagrant-terraform/action/wait_for_vm_up.rb +99 -0
  21. data/lib/vagrant-terraform/action.rb +186 -0
  22. data/lib/vagrant-terraform/config.rb +90 -0
  23. data/lib/vagrant-terraform/errors.rb +32 -0
  24. data/lib/vagrant-terraform/plugin.rb +75 -0
  25. data/lib/vagrant-terraform/provider.rb +76 -0
  26. data/lib/vagrant-terraform/util/machine_names.rb +23 -0
  27. data/lib/vagrant-terraform/util/terraform_execute.rb +32 -0
  28. data/lib/vagrant-terraform/util/timer.rb +17 -0
  29. data/lib/vagrant-terraform/util/update_vm_state.rb +29 -0
  30. data/lib/vagrant-terraform/util.rb +8 -0
  31. data/lib/vagrant-terraform/version.rb +6 -0
  32. data/lib/vagrant-terraform.rb +21 -0
  33. data/locales/en.yml +50 -0
  34. data/vagrant-terraform.gemspec +21 -0
  35. metadata +91 -0
@@ -0,0 +1,32 @@
1
+ require 'open3'
2
+
3
+ module VagrantPlugins
4
+ module TerraformProvider
5
+ module Util
6
+ module TerraformExecute
7
+
8
+ module_function
9
+
10
+ def terraform_execute(env, command)
11
+ env[:machine_tf_dir] = ".vagrant/terraform/#{env[:machine].id}" if env[:machine_tf_dir].nil?
12
+ Dir.mkdir(env[:machine_tf_dir]) unless File.exist?(env[:machine_tf_dir])
13
+ stdout, stderr, status = Open3.capture3(command, :chdir=>env[:machine_tf_dir])
14
+ if stderr != ""
15
+ if env[:machine].provider_config.debug
16
+ env[:ui].info("terraform command: #{command}")
17
+ env[:ui].info("terraform stdout: #{stdout}")
18
+ env[:ui].info("terraform stderr: #{stderr}")
19
+ env[:ui].info("terraform status: #{status}")
20
+ end
21
+ end
22
+
23
+ if status != 0
24
+ raise Errors::TerraformError,
25
+ :error_message => "terraform command '#{command}' failed with status: #{status}, stderr: #{stderr}"
26
+ end
27
+ return stdout
28
+ end
29
+ end
30
+ end
31
+ end
32
+ end
@@ -0,0 +1,17 @@
1
+ module VagrantPlugins
2
+ module TerraformProvider
3
+ module Util
4
+ class Timer
5
+ # A basic utility method that times the execution of the given
6
+ # block and returns it.
7
+ def self.time
8
+ start_time = Time.now.to_f
9
+ yield
10
+ end_time = Time.now.to_f
11
+
12
+ end_time - start_time
13
+ end
14
+ end
15
+ end
16
+ end
17
+ end
@@ -0,0 +1,29 @@
1
+ module VagrantPlugins
2
+ module TerraformProvider
3
+ module Util
4
+ module UpdateVmState
5
+
6
+ module_function
7
+
8
+ def update_vm_state(file_path, new_state)
9
+ # Read the file contents
10
+ lines = File.readlines(file_path)
11
+
12
+ # Update the line containing "vm_state"
13
+ updated_lines = lines.map do |line|
14
+ if line.strip.start_with?("vm_state")
15
+ line.gsub(/vm_state\s*=\s*".*"/, "vm_state = \"#{new_state}\"")
16
+ else
17
+ line
18
+ end
19
+ end
20
+
21
+ # Write the updated contents back to the file
22
+ File.open(file_path, "w") do |file|
23
+ file.puts(updated_lines)
24
+ end
25
+ end
26
+ end
27
+ end
28
+ end
29
+ end
@@ -0,0 +1,8 @@
1
+ module VagrantPlugins
2
+ module TerraformProvider
3
+ module Util
4
+ autoload :Timer, 'vagrant-terraform/util/timer'
5
+ end
6
+ end
7
+ end
8
+
@@ -0,0 +1,6 @@
1
+ module VagrantPlugins
2
+ module TerraformProvider
3
+ VERSION = '0.1.3'
4
+ end
5
+ end
6
+
@@ -0,0 +1,21 @@
1
+ require 'log4r'
2
+ require 'pathname'
3
+ require 'vagrant-terraform/plugin'
4
+
5
+ module VagrantPlugins
6
+ module TerraformProvider
7
+ lib_path = Pathname.new(File.expand_path("../vagrant-terraform", __FILE__))
8
+ autoload :Action, lib_path.join("action")
9
+ autoload :Errors, lib_path.join("errors")
10
+ autoload :Util, lib_path.join("util")
11
+
12
+ @@logger = Log4r::Logger.new("vagrant_terraform::provider")
13
+
14
+ # This returns the path to the source of this plugin.
15
+ #
16
+ # @return [Pathname]
17
+ def self.source_root
18
+ @source_root ||= Pathname.new(File.expand_path("../../", __FILE__))
19
+ end
20
+ end
21
+ end
data/locales/en.yml ADDED
@@ -0,0 +1,50 @@
1
+ en:
2
+ vagrant_terraform:
3
+ creating_vm: |-
4
+ Creating VM with the following settings...
5
+ starting_vm: |-
6
+ Starting VM.
7
+ not_created: |-
8
+ VM is not created. Please run `vagrant up` first.
9
+ not_up: |-
10
+ VM is not running. Please run `vagrant up` first.
11
+ powering_up: |-
12
+ VM is currently powering up. Please run `vagrant halt` to abort or wait until its status is 'up'.
13
+ error_recovering: |-
14
+ An error occured. Recovering..
15
+ waiting_for_ip: |-
16
+ Waiting for VM to get an IP address...
17
+ ready: |-
18
+ Machine is booted and ready for use!
19
+ halt_vm: |-
20
+ Halting VM...
21
+ destroy_vm: |-
22
+ Removing VM...
23
+ already_up: |-
24
+ VM is already up.
25
+ states:
26
+ long_running: |-
27
+ The instance is running. Use `vagrant halt` to stop it.
28
+ short_running: |-
29
+ running
30
+ short_stopped: |-
31
+ stopped
32
+ long_down: |-
33
+ The instance is not running. Use `vagrant up` to start it.
34
+ short_down: |-
35
+ down
36
+ long_not_created: |-
37
+ The instance is not created. Use `vagrant up` to create it.
38
+ short_not_created: |-
39
+ not created
40
+ errors:
41
+ no_vm_error: |-
42
+ No VM found with id '%{vm_id}'
43
+ create_vm_error: |-
44
+ Creation failed. Terraform error message was '%{error_message}'
45
+ start_vm_error: |-
46
+ Unable to start VM: %{error_message}
47
+ no_ip_error: |-
48
+ The VM has not reported an IP address. Please ensure the qemu-guest-agent is running and the machine is up.
49
+ terraform_execution_error: |-
50
+ Terraforming failed. Error was '%{error_message}'
@@ -0,0 +1,21 @@
1
+ # -*- encoding: utf-8 -*-
2
+ require File.expand_path('../lib/vagrant-terraform/version', __FILE__)
3
+
4
+ Gem::Specification.new do |gem|
5
+ gem.authors = ["Mika Båtsman"]
6
+ gem.email = ["mika.batsman@gmail.com"]
7
+ gem.description = %q{Vagrant provider for proxmox using terraform}
8
+ gem.summary = %q{This vagrant plugin provides the ability to create, control, and destroy virtual machines under proxmox}
9
+ gem.homepage = "https://github.com/mika-b/vagrant-terraform"
10
+ gem.licenses = ['MIT']
11
+
12
+ gem.files = `git ls-files`.split($\)
13
+ gem.executables = gem.files.grep(%r{^bin/}).map{ |f| File.basename(f) }
14
+ gem.test_files = gem.files.grep(%r{^(test|spec|features)/})
15
+ gem.name = "vagrant-terraform"
16
+ gem.require_paths = ["lib"]
17
+ gem.version = VagrantPlugins::TerraformProvider::VERSION
18
+
19
+ gem.add_runtime_dependency 'filesize', '~> 0'
20
+ gem.required_ruby_version = '>= 3.0.0'
21
+ end
metadata ADDED
@@ -0,0 +1,91 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: vagrant-terraform
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.1.3
5
+ platform: ruby
6
+ authors:
7
+ - Mika Båtsman
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2025-01-07 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: filesize
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - "~>"
18
+ - !ruby/object:Gem::Version
19
+ version: '0'
20
+ type: :runtime
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - "~>"
25
+ - !ruby/object:Gem::Version
26
+ version: '0'
27
+ description: Vagrant provider for proxmox using terraform
28
+ email:
29
+ - mika.batsman@gmail.com
30
+ executables: []
31
+ extensions: []
32
+ extra_rdoc_files: []
33
+ files:
34
+ - ".gitignore"
35
+ - Gemfile
36
+ - Gemfile.lock
37
+ - LICENSE
38
+ - README.md
39
+ - example_box/README.md
40
+ - example_box/Vagrantfile
41
+ - example_box/dummy.box
42
+ - example_box/metadata.json
43
+ - lib/vagrant-terraform.rb
44
+ - lib/vagrant-terraform/action.rb
45
+ - lib/vagrant-terraform/action/create_vm.rb
46
+ - lib/vagrant-terraform/action/destroy_vm.rb
47
+ - lib/vagrant-terraform/action/halt_vm.rb
48
+ - lib/vagrant-terraform/action/is_created.rb
49
+ - lib/vagrant-terraform/action/is_running.rb
50
+ - lib/vagrant-terraform/action/read_ssh_info.rb
51
+ - lib/vagrant-terraform/action/read_state.rb
52
+ - lib/vagrant-terraform/action/setup_terraform.rb
53
+ - lib/vagrant-terraform/action/start_vm.rb
54
+ - lib/vagrant-terraform/action/wait_for_vm_up.rb
55
+ - lib/vagrant-terraform/config.rb
56
+ - lib/vagrant-terraform/errors.rb
57
+ - lib/vagrant-terraform/plugin.rb
58
+ - lib/vagrant-terraform/provider.rb
59
+ - lib/vagrant-terraform/util.rb
60
+ - lib/vagrant-terraform/util/machine_names.rb
61
+ - lib/vagrant-terraform/util/terraform_execute.rb
62
+ - lib/vagrant-terraform/util/timer.rb
63
+ - lib/vagrant-terraform/util/update_vm_state.rb
64
+ - lib/vagrant-terraform/version.rb
65
+ - locales/en.yml
66
+ - vagrant-terraform.gemspec
67
+ homepage: https://github.com/mika-b/vagrant-terraform
68
+ licenses:
69
+ - MIT
70
+ metadata: {}
71
+ post_install_message:
72
+ rdoc_options: []
73
+ require_paths:
74
+ - lib
75
+ required_ruby_version: !ruby/object:Gem::Requirement
76
+ requirements:
77
+ - - ">="
78
+ - !ruby/object:Gem::Version
79
+ version: 3.0.0
80
+ required_rubygems_version: !ruby/object:Gem::Requirement
81
+ requirements:
82
+ - - ">="
83
+ - !ruby/object:Gem::Version
84
+ version: '0'
85
+ requirements: []
86
+ rubygems_version: 3.2.33
87
+ signing_key:
88
+ specification_version: 4
89
+ summary: This vagrant plugin provides the ability to create, control, and destroy
90
+ virtual machines under proxmox
91
+ test_files: []