Skip to content

Adds a check for REVIEW_IN_PROGRESS on CF stack.#233

Merged
patrobinson merged 3 commits intomasterfrom
issue_232
Jun 8, 2018
Merged

Adds a check for REVIEW_IN_PROGRESS on CF stack.#233
patrobinson merged 3 commits intomasterfrom
issue_232

Conversation

@denmat
Copy link
Copy Markdown
Contributor

@denmat denmat commented May 16, 2018

relates to issue #232

Adds a check on REVIEW_IN_PROGRESS status in the Cloudformation stack which can be left if that state by a user or someone else.

@denmat denmat requested a review from stevehodgkiss May 16, 2018 12:55
end

context 'stack is in review_in_progress' do

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🔪 whitespace

StackMaster.stderr.puts "Stack currently exists and is in #{stack.stack_status}"
failed! "You will need to delete the stack (#{stack.stack_name}) before continuing"
end
end
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This would be better named without a ? since it isn't used a query method. Something like abort_if_review_in_progress?

Also, rather than return false early, I would add the !stack.nil? && to the if statement. Either that or simply return if stack.nil? since the return value doesn't matter (it'll either fail or return nil or false if stack is not in review currently).

patrobinson
patrobinson previously approved these changes May 17, 2018
Copy link
Copy Markdown
Contributor

@patrobinson patrobinson left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes! @julianenvato ran into this also yesterday, there are some other edge cases it appears where it can get stuck so I am 💯 for an explicit check to give us a real error rather than the current "fetch is an invalid method for nil class"

@patrobinson patrobinson dismissed their stale review May 17, 2018 00:46

Wait a second

end

def abort_if_review_in_progress
if stack_exists? && stack.stack_status == "REVIEW_IN_PROGRESS"
Copy link
Copy Markdown
Contributor

@patrobinson patrobinson May 17, 2018

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't think REVIEW_IN_PROGRESS is necessarily a bad state? Do we get in this state if we propose a change to an existing stack and select n to applying it?

The main problem we encounter is an empty stack

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

No, it is not a bad state...but..

The main reason we get this state is if we abort (ctrl c) or don't have perms to delete the stack (after selecting n) - and stack_master doesn't get to clean up after itself which it tries to do after selecting n.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We do cleanup if you ctrl c now, but can't if you there are no permissions. I'm just wondering that instead of checking for the status, should we check for an empty stack instead?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

hmm here is the result of stack.inspect when we get this issue.

#<StackMaster::Stack:0x00007fd95d50b070 @region="us-east-1", @stack_name="mistack", @stack_id="arn:aws:cloudformation:us-east-1:123456789:stack/mistack-database/6c029cb0-5901-11e8-a5fa-500c2854b699", @parameters={}, @template_body="", @template_format=:yaml, @outputs=[], @role_arn=nil, @notification_arns=[], @stack_policy_body=nil, @stack_status="REVIEW_IN_PROGRESS">

do you think we can test on template_body?

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@denmat Yep. The issue is not that StackMaster doesn't like the state REVIEW_IN_PROGRESS, just that we have no way to deal with an empty template body.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

So I've been digging a bit and found that this was the cause:

TemplateUtils.template_hash(template).fetch('Parameters', {}).inject({}) do |result, (parameter_name, description)|

It is false in our case and hence the NilClass on .fetch

I added the following:

    def template_default_parameters
      return {} unless TemplateUtils.template_hash(template)
      TemplateUtils.template_hash(template).fetch('Parameters', {}).inject({}) do |result, (parameter_name, description)|
        result[parameter_name] = description['Default']
        result
      end
    end

And that now passes that section but leads to another error:

Aws::CloudFormation::Errors::ValidationError Stack [mistack] does not exist

Maybe a we cannot make an update to a stack that is in REVIEW_IN_PROGRESS and we should abort if that is the case? This sounds all 🐔 🥚

Copy link
Copy Markdown
Contributor

@patrobinson patrobinson left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@patrobinson patrobinson merged commit 64b5e0c into master Jun 8, 2018
@patrobinson patrobinson deleted the issue_232 branch June 8, 2018 09:49
patrobinson pushed a commit that referenced this pull request Jun 8, 2018
Install ldiff binary on windows to avoid error from diffy #240
Print a useful error when stack is stuck in REVIEW_IN_PROGRESS #233
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants