From 029ecf8667e1eb2c45ba53b2375a3c78dbda09b3 Mon Sep 17 00:00:00 2001 From: Daniel Fleming Date: Thu, 28 May 2020 10:30:55 -0400 Subject: [PATCH] :bug: Unable to Destroy Create Failed Bucket - Fixes bug https://github.com/sparkleformation/sfn-bucketpurge/issues/2 where the callback was unable to destroy a stack that contains a bucket in the 'CREATE_FAILED' state. To Reproduce: 1. Create a stack with an improper bucket name. ``` SparkleFormation.new(:bucket_test, :provider => :aws) do dynamic!(:bucket, :bucket_one) do depends_on 'Bucket2Bucket' properties do bucket_name 'Bad-bucketname2334' end end dynamic!(:bucket, :bucket2) do properties do bucket_name 'test122354' end end end ``` 2. Try to destroy the stack with sfn_bucketpurge 0.0.1 enabled, and find the following error along with remaining stack. ``` [ERROR]: no implicit conversion of nil into String ``` --- CHANGELOG.md | 5 +++++ lib/sfn-bucketpurge/bucket_purge.rb | 4 ++++ lib/sfn-bucketpurge/version.rb | 2 +- 3 files changed, 10 insertions(+), 1 deletion(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 71125f1..9d5fb4e 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,2 +1,7 @@ +# v0.0.2 +* Fixes bug where a bucket in a failed state + (bucket was not created) exists in a stack + and this causes the callback to fail. + # v0.0.1 * Initial release diff --git a/lib/sfn-bucketpurge/bucket_purge.rb b/lib/sfn-bucketpurge/bucket_purge.rb index 497c22c..867cdfa 100644 --- a/lib/sfn-bucketpurge/bucket_purge.rb +++ b/lib/sfn-bucketpurge/bucket_purge.rb @@ -11,6 +11,10 @@ def before_destroy(args) rescue next end + if resource.name.nil? + ui.info "Found a failed resource, whose name is nil, skipping..." + next + end next unless resource.is_a?(Miasma::Models::Storage::Bucket) files = resource.files.all next if files.empty? diff --git a/lib/sfn-bucketpurge/version.rb b/lib/sfn-bucketpurge/version.rb index 0b3631a..9415b5a 100644 --- a/lib/sfn-bucketpurge/version.rb +++ b/lib/sfn-bucketpurge/version.rb @@ -1,3 +1,3 @@ module SfnBucketPurge - VERSION = Gem::Version.new('0.0.1') + VERSION = Gem::Version.new('0.0.2') end