diff --git a/tests/rspec/lib/aws_cluster.rb b/tests/rspec/lib/aws_cluster.rb index 1d40c5a864..6a5d06460a 100644 --- a/tests/rspec/lib/aws_cluster.rb +++ b/tests/rspec/lib/aws_cluster.rb @@ -8,6 +8,7 @@ require 'env_var' require 'aws_iam' require 'aws_support' +require 'tfstate_file' # AWSCluster represents a k8s cluster on AWS cloud provider class AwsCluster < Cluster @@ -110,4 +111,30 @@ def tectonic_console_url ingress_ext end end + + private + + def destroy + # For debugging purposes (see: https://github.com/terraform-providers/terraform-provider-aws/pull/1051) + describe_network_interfaces + + super + + # For debugging purposes (see: https://github.com/terraform-providers/terraform-provider-aws/pull/1051) + describe_network_interfaces + end + + def describe_network_interfaces + puts 'describing network interfaces for debugging purposes' + vpc_id = @tfstate_file.value('module.vpc.aws_vpc.cluster_vpc', 'id') + filter = "--filters=Name=vpc-id,Values=#{vpc_id}" + region = "--region #{@aws_region}" + + success = system("aws ec2 describe-network-interfaces #{filter} #{region}") + raise 'failed to describe network interfaces by vpc' unless success + + # Do not fail build. This is only for debugging purposes + rescue => e + puts e + end end diff --git a/tests/rspec/lib/cluster.rb b/tests/rspec/lib/cluster.rb index c372ebf1c2..ad54659eab 100644 --- a/tests/rspec/lib/cluster.rb +++ b/tests/rspec/lib/cluster.rb @@ -4,6 +4,7 @@ require 'securerandom' require 'jenkins' require 'tfvars_file' +require 'tfstate_file' require 'fileutils' require 'name_generator' require 'password_generator' @@ -12,7 +13,7 @@ # Cluster represents a k8s cluster class Cluster attr_reader :tfvars_file, :kubeconfig, :manifest_path, :build_path, - :tectonic_admin_email, :tectonic_admin_password + :tectonic_admin_email, :tectonic_admin_password, :tfstate_file def initialize(tfvars_file) @tfvars_file = tfvars_file @@ -26,6 +27,8 @@ def initialize(tfvars_file) @build_path = File.join(File.realpath('../../'), "build/#{@name}") @manifest_path = File.join(@build_path, 'generated') @kubeconfig = File.join(manifest_path, 'auth/kubeconfig') + @tfstate_file = TFStateFile.new(@build_path) + check_prerequisites localconfig prepare_assets diff --git a/tests/rspec/lib/tfstate_file.rb b/tests/rspec/lib/tfstate_file.rb new file mode 100644 index 0000000000..db517a90e4 --- /dev/null +++ b/tests/rspec/lib/tfstate_file.rb @@ -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