Module: Kitchen::Terraform::Client::Command
- Extended by:
- Dry::Monads::Either::Mixin, Dry::Monads::Try::Mixin
- Defined in:
- lib/kitchen/terraform/client/command.rb
Overview
Represents the result of running a Terraform command.
Class Method Summary collapse
-
.apply(options:, working_directory:) ⇒ ::Dry::Monads::Either
Creates the apply command shell out.
- .create(options:, subcommand:, working_directory:) ⇒ Object private
-
.destroy(options:, working_directory:) ⇒ ::Dry::Monads::Either
Creates the destroy command shell out.
-
.init(options:, working_directory:) ⇒ ::Dry::Monads::Either
Creates the init command shell out.
-
.output(options:, working_directory:) ⇒ ::Dry::Monads::Either
Creates the output command shell out.
-
.run(logger:, shell_out:, timeout:) ⇒ ::Dry::Monads::Either
Runs a command shell out.
- .try_to_run(logger:, shell_out:, timeout:) ⇒ Object
-
.validate(options:, working_directory:) ⇒ ::Dry::Monads::Either
Creates the validate command shell out.
-
.version(options: ::Kitchen::Terraform::Client::Options, working_directory:) ⇒ ::Dry::Monads::Either
Creates the version command shell out.
Class Method Details
.apply(options:, working_directory:) ⇒ ::Dry::Monads::Either
Creates the apply command shell out.
36 37 38 39 40 41 42 |
# File 'lib/kitchen/terraform/client/command.rb', line 36 def self.apply(options:, working_directory:) create( options: , subcommand: "apply", working_directory: working_directory ) end |
.create(options:, subcommand:, working_directory:) ⇒ Object
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
141 142 143 144 145 146 147 148 149 150 151 152 |
# File 'lib/kitchen/terraform/client/command.rb', line 141 def self.create(options:, subcommand:, working_directory:) Try ::Mixlib::ShellOut::InvalidCommandOption do ::Mixlib::ShellOut.new( "terraform #{subcommand} #{}".strip, cwd: working_directory ) end .to_either .or do |error| Left "Failed to create `terraform #{subcommand}`: #{error}" end end |
.destroy(options:, working_directory:) ⇒ ::Dry::Monads::Either
Creates the destroy command shell out.
51 52 53 54 55 56 57 |
# File 'lib/kitchen/terraform/client/command.rb', line 51 def self.destroy(options:, working_directory:) create( options: , subcommand: "destroy", working_directory: working_directory ) end |
.init(options:, working_directory:) ⇒ ::Dry::Monads::Either
Creates the init command shell out.
65 66 67 68 69 70 71 |
# File 'lib/kitchen/terraform/client/command.rb', line 65 def self.init(options:, working_directory:) create( options: , subcommand: "init", working_directory: working_directory ) end |
.output(options:, working_directory:) ⇒ ::Dry::Monads::Either
Creates the output command shell out.
79 80 81 82 83 84 85 |
# File 'lib/kitchen/terraform/client/command.rb', line 79 def self.output(options:, working_directory:) create( options: , subcommand: "output", working_directory: working_directory ) end |
.run(logger:, shell_out:, timeout:) ⇒ ::Dry::Monads::Either
Runs a command shell out.
93 94 95 96 97 98 99 100 101 102 103 104 105 |
# File 'lib/kitchen/terraform/client/command.rb', line 93 def self.run(logger:, shell_out:, timeout:) try_to_run( logger: logger, shell_out: shell_out, timeout: timeout ) .bind do Right shell_out.stdout end .or do |error| Left error.to_s end end |
.try_to_run(logger:, shell_out:, timeout:) ⇒ Object
154 155 156 157 158 159 160 161 162 163 164 165 166 167 |
# File 'lib/kitchen/terraform/client/command.rb', line 154 def self.try_to_run(logger:, shell_out:, timeout:) Try( ::Errno::EACCES, ::Errno::ENOENT, ::Mixlib::ShellOut::CommandTimeout, ::Mixlib::ShellOut::ShellCommandFailed ) do shell_out.live_stream = logger shell_out.timeout = timeout shell_out.run_command shell_out.error! end .to_either end |
.validate(options:, working_directory:) ⇒ ::Dry::Monads::Either
Creates the validate command shell out.
113 114 115 116 117 118 119 |
# File 'lib/kitchen/terraform/client/command.rb', line 113 def self.validate(options:, working_directory:) create( options: , subcommand: "validate", working_directory: working_directory ) end |
.version(options: ::Kitchen::Terraform::Client::Options, working_directory:) ⇒ ::Dry::Monads::Either
Creates the version command shell out.
127 128 129 130 131 132 133 |
# File 'lib/kitchen/terraform/client/command.rb', line 127 def self.version(options: ::Kitchen::Terraform::Client::Options, working_directory:) create( options: , subcommand: "version", working_directory: working_directory ) end |