Skip to content
This repository has been archived by the owner on Oct 22, 2024. It is now read-only.

Commit

Permalink
Remove TF_WARN_OUTPUT_ERRORS from terraform apply (#320)
Browse files Browse the repository at this point in the history
* Only set TF_WARN_OUTPUT_ERRORS on destroy

Setting this variable on apply can hide configuration issues which would
normally generate an error.

* Implement the spec

* Disable redundant Code Climate plugins

These plugins duplicate behaviour performed by Code Climate checks.

* Include erroneously excluded spec/ in Code Climate

* Update version to 4.3.0

* Add entry to CHANGELOG

* Cache chocolately downloads

* Revert "Cache chocolately downloads"

This reverts commit c2f5a89.

* Update release date
  • Loading branch information
aaron-lane authored Jan 21, 2019
1 parent 4065a99 commit 7cdfa11
Show file tree
Hide file tree
Showing 13 changed files with 254 additions and 208 deletions.
4 changes: 2 additions & 2 deletions .codeclimate.yml
Original file line number Diff line number Diff line change
Expand Up @@ -4,14 +4,14 @@ plugins:
bundler-audit:
enabled: false
duplication:
enabled: true
enabled: false
config:
languages:
- "ruby"
fixme:
enabled: true
flog:
enabled: true
enabled: false
markdownlint:
enabled: true
reek:
Expand Down
11 changes: 10 additions & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,14 @@ adheres to [Semantic Versioning](http://semver.org/spec/v2.0.0.html).

## [Unreleased][unreleased]

## [4.3.0] - 2019-01-20

### Changed

- `TF_WARN_OUTPUT_ERRORS` is no longer automatically set when running
`terraform apply` during `kitchen converge`. This change should allow
output errors to be more quickly exposed to the user.

## [4.2.1] - 2019-01-19

### Changed
Expand Down Expand Up @@ -588,7 +596,8 @@ Gandalf the Free-As-In-Beer

- Initial release

[unreleased]: https://github.com/newcontext/kitchen-terraform/compare/v4.2.1...HEAD
[unreleased]: https://github.com/newcontext/kitchen-terraform/compare/v4.3.0...HEAD
[4.3.0]: https://github.com/newcontext/kitchen-terraform/compare/v4.2.1...v4.3.0
[4.2.1]: https://github.com/newcontext/kitchen-terraform/compare/v4.2.0...v4.2.1
[4.2.0]: https://github.com/newcontext/kitchen-terraform/compare/v4.1.1...v4.2.0
[4.1.1]: https://github.com/newcontext/kitchen-terraform/compare/v4.1.0...v4.1.1
Expand Down
2 changes: 1 addition & 1 deletion Gemfile.lock
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ GIT
PATH
remote: .
specs:
kitchen-terraform (4.2.1)
kitchen-terraform (4.3.0)
dry-types (~> 0.9)
dry-validation (~> 0.10)
inspec (~> 3.0)
Expand Down
1 change: 1 addition & 0 deletions lib/kitchen/driver/terraform.rb
Original file line number Diff line number Diff line change
Expand Up @@ -397,6 +397,7 @@ def destroy_run_destroy
"#{variable_files_flags}",
options: {
cwd: config_root_module_directory,
environment: {"TF_WARN_OUTPUT_ERRORS" => "true"},
live_stream: logger,
timeout: config_command_timeout,
},
Expand Down
26 changes: 12 additions & 14 deletions lib/kitchen/terraform/shell_out.rb
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@ module ::Kitchen::Terraform::ShellOut
# command.
# @option options [::Integer] :timeout the maximum duration in seconds to run the command.
# @param command [::String] the command to run.
# @option options [::Hash] :environment environment variables to define when running the command.
# @param options [::Hash] options which adjust the execution of the command.
# @raise [::Kitchen::Terraform::Error] if running the command fails.
# @return [::String] the standard output from running the command.
Expand Down Expand Up @@ -67,22 +68,19 @@ def self.handle(error:)

# @api private
def self.run_shell_out(command:, options:)
yield(
standard_output:
::Mixlib::ShellOut
.new(
yield(standard_output: ::Mixlib::ShellOut.new(
"terraform #{command}",
options.merge(environment: {"TF_IN_AUTOMATION" => "true", "TF_WARN_OUTPUT_ERRORS" => "1"})
)
.tap do |shell_out|
shell_out
.live_stream
.warn "Running command `#{shell_out.command}` in directory #{shell_out.cwd}"

options.merge(
environment: {"TF_IN_AUTOMATION" => "true", "TF_WARN_OUTPUT_ERRORS" => "1"}.merge(
options.fetch(:environment) do
{}
end
),
)
).tap do |shell_out|
shell_out.live_stream.warn "Running command `#{shell_out.command}` in directory #{shell_out.cwd}"
shell_out.run_command
shell_out.error!
end
.stdout
)
end.stdout)
end
end
2 changes: 1 addition & 1 deletion lib/kitchen/terraform/version.rb
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,7 @@ def temporarily_override(version:)

# @api private
def value
self.value = ::Gem::Version.new "4.2.1" if not @value
self.value = ::Gem::Version.new "4.3.0" if not @value
@value
end

Expand Down
2 changes: 1 addition & 1 deletion ruby-2.3/Gemfile.lock
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ GIT
PATH
remote: ..
specs:
kitchen-terraform (4.2.1)
kitchen-terraform (4.3.0)
dry-types (~> 0.9)
dry-validation (~> 0.10)
inspec (~> 3.0)
Expand Down
2 changes: 1 addition & 1 deletion ruby-2.4/Gemfile.lock
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ GIT
PATH
remote: ..
specs:
kitchen-terraform (4.2.1)
kitchen-terraform (4.3.0)
dry-types (~> 0.9)
dry-validation (~> 0.10)
inspec (~> 3.0)
Expand Down
2 changes: 1 addition & 1 deletion ruby-2.5/Gemfile.lock
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ GIT
PATH
remote: ..
specs:
kitchen-terraform (4.2.1)
kitchen-terraform (4.3.0)
dry-types (~> 0.9)
dry-validation (~> 0.10)
inspec (~> 3.0)
Expand Down
20 changes: 17 additions & 3 deletions spec/lib/kitchen/driver/terraform_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -524,7 +524,15 @@ def shell_out_run_yield(command:, standard_output: "mocked `terraform` success")

context "when `terraform destroy` results in failure" do
before do
shell_out_run_failure command: /destroy/, message: "mocked `terraform destroy` failure"
allow(shell_out).to receive(:run).with(
command: /destroy/,
options: {
cwd: kitchen_root,
environment: {"TF_WARN_OUTPUT_ERRORS" => "true"},
live_stream: kitchen_logger,
timeout: command_timeout,
},
).and_raise ::Kitchen::Terraform::Error, "mocked `terraform destroy` failure"
end

specify "should result in an action failed error with the failed command output" do
Expand All @@ -536,7 +544,7 @@ def shell_out_run_yield(command:, standard_output: "mocked `terraform` success")

context "when `terraform destroy` results in success" do
before do
shell_out_run_success(
allow(shell_out).to receive(:run).with(
command: "destroy " \
"-auto-approve " \
"-lock=true " \
Expand All @@ -549,7 +557,13 @@ def shell_out_run_yield(command:, standard_output: "mocked `terraform` success")
"-var=\"map={ key = \\\"A Value\\\" }\" " \
"-var=\"list=[ \\\"Element One\\\", \\\"Element Two\\\" ]\" " \
"-var-file=\"/Arbitrary Directory/Variable File.tfvars\"",
)
options: {
cwd: kitchen_root,
environment: {"TF_WARN_OUTPUT_ERRORS" => "true"},
live_stream: kitchen_logger,
timeout: command_timeout,
},
).and_return "mocked `terraform` success"
end

context "when `terraform select default` results in failure" do
Expand Down
Loading

0 comments on commit 7cdfa11

Please sign in to comment.