diff --git a/CHANGELOG.md b/CHANGELOG.md index 02334b377..060f14cae 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -8,9 +8,15 @@ adheres to [Semantic Versioning](http://semver.org/spec/v2.0.0.html). ## [Unreleased][unreleased] +## [4.1.1] - 2018-12-13 + +### Fixed + +- The Terraform workspace is selected before outputs are retrieved. + ## [4.1.0] - 2018-12-09 -## Changed +### Changed - The bundled version of InSpec is now ~> 3.0. Despite the major version change, it is intended to be backward compatible. @@ -564,7 +570,8 @@ Gandalf the Free-As-In-Beer - Initial release -[unreleased]: https://github.com/newcontext/kitchen-terraform/compare/v4.1.0...HEAD +[unreleased]: https://github.com/newcontext/kitchen-terraform/compare/v4.1.1...HEAD +[4.1.1]: https://github.com/newcontext/kitchen-terraform/compare/v4.1.0...v4.1.1 [4.1.0]: https://github.com/newcontext/kitchen-terraform/compare/v4.0.6...v4.1.0 [4.0.6]: https://github.com/newcontext/kitchen-terraform/compare/v4.0.5...v4.0.6 [4.0.5]: https://github.com/newcontext/kitchen-terraform/compare/v4.0.4...v4.0.5 diff --git a/Gemfile.lock b/Gemfile.lock index 25395329f..0c4f329b1 100644 --- a/Gemfile.lock +++ b/Gemfile.lock @@ -1,7 +1,7 @@ PATH remote: . specs: - kitchen-terraform (4.1.0) + kitchen-terraform (4.1.1) dry-types (~> 0.9) dry-validation (~> 0.10) inspec (~> 3.0) @@ -20,13 +20,13 @@ GEM public_suffix (>= 2.0.2, < 4.0) autoprefixer-rails (8.6.5) execjs - aws-sdk (2.11.188) - aws-sdk-resources (= 2.11.188) - aws-sdk-core (2.11.188) + aws-sdk (2.11.189) + aws-sdk-resources (= 2.11.189) + aws-sdk-core (2.11.189) aws-sigv4 (~> 1.0) jmespath (~> 1.0) - aws-sdk-resources (2.11.188) - aws-sdk-core (= 2.11.188) + aws-sdk-resources (2.11.189) + aws-sdk-core (= 2.11.189) aws-sigv4 (1.0.3) azure_graph_rbac (0.17.0) ms_rest_azure (~> 0.11.0) @@ -264,7 +264,7 @@ GEM mixlib-versioning thor mixlib-log (2.0.4) - mixlib-shellout (2.4.2) + mixlib-shellout (2.4.4) mixlib-versioning (1.2.2) ms_rest (0.7.3) concurrent-ruby (~> 1.0) @@ -340,7 +340,7 @@ GEM rubyntlm (0.6.2) rubyzip (1.2.2) sass (3.4.25) - semverse (2.0.0) + semverse (3.0.0) servolux (0.13.0) shellany (0.0.1) signet (0.11.0) @@ -357,7 +357,7 @@ GEM temple (0.8.0) term-ansicolor (1.7.0) tins (~> 1.0) - test-kitchen (1.23.3) + test-kitchen (1.23.5) mixlib-install (~> 3.6) mixlib-shellout (>= 1.2, < 3.0) net-scp (~> 1.1) @@ -373,7 +373,7 @@ GEM timeliness (0.3.8) tins (1.20.2) tomlrb (1.2.7) - train (1.5.6) + train (1.5.11) aws-sdk (~> 2) azure_graph_rbac (~> 0.16) azure_mgmt_key_vault (~> 0.17) @@ -455,4 +455,4 @@ RUBY VERSION ruby 2.5.3p105 BUNDLED WITH - 1.17.1 + 1.17.2 diff --git a/lib/kitchen/driver/terraform.rb b/lib/kitchen/driver/terraform.rb index 8591fb3ea..20cf1aa59 100644 --- a/lib/kitchen/driver/terraform.rb +++ b/lib/kitchen/driver/terraform.rb @@ -257,12 +257,14 @@ def destroy(_state) ) end - # Retrieves the Terraform state outputs. + # Retrieves the Terraform state outputs for a Kitchen instance by selecting the test workspace and fetching the + # outputs. # # @raise [::Kitchen::Terraform::Error] if the retrieval fails. # @return [void] - # @yieldparam output [::String] the state output. + # @yieldparam output [::Hash] the state output. def retrieve_outputs(&block) + run_workspace_select_instance ::Kitchen::Terraform::Command::Output.run( options: { cwd: config_root_module_directory, live_stream: logger, timeout: config_command_timeout, diff --git a/lib/kitchen/terraform/command/output.rb b/lib/kitchen/terraform/command/output.rb index 149c30d68..cdaa70c6c 100644 --- a/lib/kitchen/terraform/command/output.rb +++ b/lib/kitchen/terraform/command/output.rb @@ -30,7 +30,7 @@ class << self # command. # @option options [::Integer] :timeout the maximum duration in seconds to run the command. # @param options [::Hash] options which adjust the execution of the command. - # @yieldparam output [::String] the standard output of the command parsed as JSON. + # @yieldparam output [::Hash] the standard output of the command parsed as JSON. def run(options:, &block) run_shell_out( options: options, diff --git a/lib/kitchen/terraform/version.rb b/lib/kitchen/terraform/version.rb index 672a0d951..06b5293cc 100644 --- a/lib/kitchen/terraform/version.rb +++ b/lib/kitchen/terraform/version.rb @@ -72,7 +72,7 @@ def temporarily_override(version:) # @api private def value - self.value = ::Gem::Version.new "4.1.0" if not @value + self.value = ::Gem::Version.new "4.1.1" if not @value @value end diff --git a/ruby-2.3/Gemfile.lock b/ruby-2.3/Gemfile.lock index 2da35484a..a33585d0a 100644 --- a/ruby-2.3/Gemfile.lock +++ b/ruby-2.3/Gemfile.lock @@ -1,7 +1,7 @@ PATH remote: .. specs: - kitchen-terraform (4.1.0) + kitchen-terraform (4.1.1) dry-types (~> 0.9) dry-validation (~> 0.10) inspec (~> 3.0) @@ -20,13 +20,13 @@ GEM public_suffix (>= 2.0.2, < 4.0) autoprefixer-rails (8.6.5) execjs - aws-sdk (2.11.188) - aws-sdk-resources (= 2.11.188) - aws-sdk-core (2.11.188) + aws-sdk (2.11.189) + aws-sdk-resources (= 2.11.189) + aws-sdk-core (2.11.189) aws-sigv4 (~> 1.0) jmespath (~> 1.0) - aws-sdk-resources (2.11.188) - aws-sdk-core (= 2.11.188) + aws-sdk-resources (2.11.189) + aws-sdk-core (= 2.11.189) aws-sigv4 (1.0.3) azure_graph_rbac (0.17.0) ms_rest_azure (~> 0.11.0) @@ -264,7 +264,7 @@ GEM mixlib-versioning thor mixlib-log (2.0.4) - mixlib-shellout (2.4.2) + mixlib-shellout (2.4.4) mixlib-versioning (1.2.2) ms_rest (0.7.3) concurrent-ruby (~> 1.0) @@ -340,7 +340,7 @@ GEM rubyntlm (0.6.2) rubyzip (1.2.2) sass (3.4.25) - semverse (2.0.0) + semverse (3.0.0) servolux (0.13.0) shellany (0.0.1) signet (0.11.0) @@ -357,7 +357,7 @@ GEM temple (0.8.0) term-ansicolor (1.7.0) tins (~> 1.0) - test-kitchen (1.23.3) + test-kitchen (1.23.5) mixlib-install (~> 3.6) mixlib-shellout (>= 1.2, < 3.0) net-scp (~> 1.1) @@ -373,7 +373,7 @@ GEM timeliness (0.3.8) tins (1.20.2) tomlrb (1.2.7) - train (1.5.6) + train (1.5.11) aws-sdk (~> 2) azure_graph_rbac (~> 0.16) azure_mgmt_key_vault (~> 0.17) @@ -455,4 +455,4 @@ RUBY VERSION ruby 2.3.8p459 BUNDLED WITH - 1.17.1 + 1.17.2 diff --git a/ruby-2.4/Gemfile.lock b/ruby-2.4/Gemfile.lock index 8d8e4d3b5..490e8b69b 100644 --- a/ruby-2.4/Gemfile.lock +++ b/ruby-2.4/Gemfile.lock @@ -1,7 +1,7 @@ PATH remote: .. specs: - kitchen-terraform (4.1.0) + kitchen-terraform (4.1.1) dry-types (~> 0.9) dry-validation (~> 0.10) inspec (~> 3.0) @@ -20,13 +20,13 @@ GEM public_suffix (>= 2.0.2, < 4.0) autoprefixer-rails (8.6.5) execjs - aws-sdk (2.11.188) - aws-sdk-resources (= 2.11.188) - aws-sdk-core (2.11.188) + aws-sdk (2.11.189) + aws-sdk-resources (= 2.11.189) + aws-sdk-core (2.11.189) aws-sigv4 (~> 1.0) jmespath (~> 1.0) - aws-sdk-resources (2.11.188) - aws-sdk-core (= 2.11.188) + aws-sdk-resources (2.11.189) + aws-sdk-core (= 2.11.189) aws-sigv4 (1.0.3) azure_graph_rbac (0.17.0) ms_rest_azure (~> 0.11.0) @@ -265,7 +265,7 @@ GEM mixlib-versioning thor mixlib-log (2.0.4) - mixlib-shellout (2.4.2) + mixlib-shellout (2.4.4) mixlib-versioning (1.2.2) ms_rest (0.7.3) concurrent-ruby (~> 1.0) @@ -345,7 +345,7 @@ GEM rubyntlm (0.6.2) rubyzip (1.2.2) sass (3.4.25) - semverse (2.0.0) + semverse (3.0.0) servolux (0.13.0) shellany (0.0.1) signet (0.11.0) @@ -362,7 +362,7 @@ GEM temple (0.8.0) term-ansicolor (1.7.0) tins (~> 1.0) - test-kitchen (1.23.3) + test-kitchen (1.23.5) mixlib-install (~> 3.6) mixlib-shellout (>= 1.2, < 3.0) net-scp (~> 1.1) @@ -378,7 +378,7 @@ GEM timeliness (0.3.8) tins (1.20.2) tomlrb (1.2.7) - train (1.5.6) + train (1.5.11) aws-sdk (~> 2) azure_graph_rbac (~> 0.16) azure_mgmt_key_vault (~> 0.17) @@ -463,4 +463,4 @@ RUBY VERSION ruby 2.4.5p335 BUNDLED WITH - 1.17.1 + 1.17.2 diff --git a/spec/lib/kitchen/driver/terraform_spec.rb b/spec/lib/kitchen/driver/terraform_spec.rb index 08cb5d8b0..dc6851de4 100644 --- a/spec/lib/kitchen/driver/terraform_spec.rb +++ b/spec/lib/kitchen/driver/terraform_spec.rb @@ -189,7 +189,7 @@ def shell_out_run_yield(command:, standard_output: "mocked `terraform` success") described_instance.finalize_config! kitchen_instance end - shared_examples "terraform: get; validate; apply; output" do + shared_examples "terraform: get; validate; apply" do context "when `terraform get` results in failure" do before do shell_out_run_failure( @@ -295,7 +295,7 @@ def shell_out_run_yield(command:, standard_output: "mocked `terraform` success") shell_out_run_success command: "workspace new kitchen-terraform-test-suite-test-platform" end - it_behaves_like "terraform: get; validate; apply; output" + it_behaves_like "terraform: get; validate; apply" end end @@ -304,7 +304,7 @@ def shell_out_run_yield(command:, standard_output: "mocked `terraform` success") shell_out_run_success command: "workspace select kitchen-terraform-test-suite-test-platform" end - it_behaves_like "terraform: get; validate; apply; output" + it_behaves_like "terraform: get; validate; apply" end end @@ -586,66 +586,108 @@ def shell_out_run_yield(command:, standard_output: "mocked `terraform` success") described_instance.finalize_config! kitchen_instance end - context "when the command results in failure due to no outputs defined" do - before do - shell_out_run_failure command: "output -json", message: "no outputs defined" - end + shared_examples "`terraform output` is run" do + context "when the command results in failure due to no outputs defined" do + before do + shell_out_run_failure command: "output -json", message: "no outputs defined" + end - specify "should ignore the failure and yield an empty hash" do - expect do |block| - subject.retrieve_outputs(&block) - end.to yield_with_args outputs: {} + specify "should ignore the failure and yield an empty hash" do + expect do |block| + subject.retrieve_outputs(&block) + end.to yield_with_args outputs: {} + end end - end - context "when the command results in failure not due to no outputs defined" do - before do - shell_out_run_failure command: "output -json", message: "mocked `terraform output` failure" + context "when the command results in failure not due to no outputs defined" do + before do + shell_out_run_failure command: "output -json", message: "mocked `terraform output` failure" + end + + specify "should result in failure with the command failure message" do + expect do + subject.retrieve_outputs + end.to result_in_failure.with_message "mocked `terraform output` failure" + end end - specify "should result in failure with the command failure message" do - expect do - subject.retrieve_outputs - end.to result_in_failure.with_message "mocked `terraform output` failure" + context "when the command results in success" do + before do + shell_out_run_yield command: "output -json", standard_output: terraform_output_value + end + + context "when the value of the command result is not valid JSON" do + let :terraform_output_value do + "not valid JSON" + end + + specify "should result in failure with a message which indicates the output is not valid JSON" do + expect do + subject.retrieve_outputs + end.to result_in_failure.with_message(/Parsing Terraform output as JSON failed:/) + end + end + + context "when the value of the command result is valid JSON" do + let :terraform_output_value do + ::JSON.dump value_as_hash + end + + let :value_as_hash do + {output_name: {sensitive: false, type: "list", value: ["output_value_1"]}} + end + + specify "should yield the hash which results from processing the output as JSON" do + expect do |block| + subject.retrieve_outputs(&block) + end.to yield_with_args( + outputs: { + "output_name" => {"sensitive" => false, "type" => "list", "value" => ["output_value_1"]}, + }, + ) + end + end end end - context "when the command results in success" do + context "when `terraform workspace select ` results in failure" do before do - shell_out_run_yield command: "output -json", standard_output: terraform_output_value + shell_out_run_failure( + command: "workspace select kitchen-terraform-test-suite-test-platform", + message: "mocked `terraform workspace select ` failure", + ) end - context "when the value of the command result is not valid JSON" do - let :terraform_output_value do - "not valid JSON" + context "when `terraform workspace new ` results in failure" do + before do + shell_out_run_failure( + command: "workspace new kitchen-terraform-test-suite-test-platform", + message: "mocked `terraform workspace new ` failure", + ) end - specify "should result in failure with a message which indicates the output is not valid JSON" do + specify "should result in failure with the command failure message" do expect do subject.retrieve_outputs - end.to result_in_failure.with_message(/Parsing Terraform output as JSON failed:/) + end.to result_in_failure.with_message "mocked `terraform workspace new ` failure" end end - context "when the value of the command result is valid JSON" do - let :terraform_output_value do - ::JSON.dump value_as_hash + context "when `terraform workspace new ` results in success" do + before do + shell_out_run_success command: "workspace new kitchen-terraform-test-suite-test-platform" end - let :value_as_hash do - {output_name: {sensitive: false, type: "list", value: ["output_value_1"]}} - end + it_behaves_like "`terraform output` is run" + end + end - specify "should yield the hash which results from processing the output as JSON" do - expect do |block| - subject.retrieve_outputs(&block) - end.to yield_with_args( - outputs: { - "output_name" => {"sensitive" => false, "type" => "list", "value" => ["output_value_1"]}, - }, - ) - end + context "when `terraform workspace select ` results in success" do + before do + shell_out_run_success command: "workspace select kitchen-terraform-test-suite-test-platform" end + + it_behaves_like "`terraform output` is run" end end diff --git a/spec/lib/kitchen/terraform/version_spec.rb b/spec/lib/kitchen/terraform/version_spec.rb index 854899b7d..cf7aaf562 100644 --- a/spec/lib/kitchen/terraform/version_spec.rb +++ b/spec/lib/kitchen/terraform/version_spec.rb @@ -24,7 +24,7 @@ end let :version do - ::Gem::Version.new "4.1.0" + ::Gem::Version.new "4.1.1" end describe ".assign_plugin_version" do diff --git a/spec/support/kitchen/terraform/configurable_examples.rb b/spec/support/kitchen/terraform/configurable_examples.rb index bc7d3de0e..4dc7033fb 100644 --- a/spec/support/kitchen/terraform/configurable_examples.rb +++ b/spec/support/kitchen/terraform/configurable_examples.rb @@ -35,7 +35,7 @@ end it "equals the gem version" do - expect(subject.instance_variable_get(:@plugin_version)).to eq "4.1.0" + expect(subject.instance_variable_get(:@plugin_version)).to eq "4.1.1" end end