forked from coreos/tectonic-installer
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
tests: Log network interfaces before and after destroy
For better upstream Terraform debugging we would like to log the network interfaces related to the VPC. For further details see: hashicorp/terraform-provider-aws#1051
- Loading branch information
Showing
3 changed files
with
63 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,32 @@ | ||
# frozen_string_literal: true | ||
|
||
# TFStateFile represents a Terraform state file | ||
class TFStateFile | ||
def initialize(build_path) | ||
@build_path = build_path | ||
end | ||
|
||
def value(address, wanted_key) | ||
file_exists? | ||
|
||
Dir.chdir(@build_path) do | ||
state = `terraform state show #{address}`.chomp.split("\n") | ||
state.each do |value| | ||
key, value = value.split('=') | ||
key = key.strip.chomp | ||
value = value.strip.chomp | ||
return value if key == wanted_key | ||
end | ||
end | ||
|
||
msg = "could not find value for key \"#{wanted_key}\" in tfstate file #{@build_path}" | ||
raise TFStateFileValueForKeyDoesNotExist, msg | ||
end | ||
|
||
def file_exists? | ||
tfstate_file = File.join(@build_path, 'terraform.tfstate') | ||
raise "tfstate file #{tfstate_file} does not exist" unless File.exist? tfstate_file | ||
end | ||
end | ||
|
||
class TFStateFileValueForKeyDoesNotExist < StandardError; end |