-
Notifications
You must be signed in to change notification settings - Fork 200
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Cleanup AWS resources in case of warm up error #315
Conversation
Looks good, would it make sense to add/edit an existing test case? Let me know if you need a bit of help there! |
@@ -84,6 +84,8 @@ func (m *Runner) WarmUp() (map[string]string, error) { | |||
log.Println("Warming up " + m.Technique.ID) | |||
outputs, err := m.TerraformManager.TerraformInitAndApply(m.TerraformDir) | |||
if err != nil { | |||
log.Println("Error during warm up. Cleaning up technique prerequisites with terraform destroy") | |||
_ = m.TerraformManager.TerraformDestroy(m.TerraformDir) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
might make sense to defer
it here? no strong opinions
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Interesting thought; could do something like the below (keeping the _ =
to avoid 'unhandled error' warnings).
However, I believe it won't make a difference because there's is nothing in the way that could fail and thus prevent the .TerraformDestroy()
from being called. Happy to stand corrected though ;)
defer func() {
_ = m.TerraformManager.TerraformDestroy(m.TerraformDir)
}()
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I was thinking of simply defer m.TerraformManager.TerraformDestroy(m.TerraformDir)
, but it might trigger an IDE warning instead. No strong opinion, let's keep it as is
Good point. Probably yes. Let me have a look; need to understand the mock framework a bit (never worked it before). And yes, I might take you up and reach out for help on this if I get stuck. Thanks for offering. |
Extend the mock tests with a test case to verify that 'TerraformDestroy' is called in case of an error during 'TerraformInitAndApply'.
@@ -91,6 +92,18 @@ func TestRunnerWarmUp(t *testing.T) { | |||
assert.Equal(t, "old", outputs["myoutput"]) | |||
}, | |||
}, | |||
{ |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
looks great, thanks!
@@ -84,6 +84,8 @@ func (m *Runner) WarmUp() (map[string]string, error) { | |||
log.Println("Warming up " + m.Technique.ID) | |||
outputs, err := m.TerraformManager.TerraformInitAndApply(m.TerraformDir) | |||
if err != nil { | |||
log.Println("Error during warm up. Cleaning up technique prerequisites with terraform destroy") | |||
_ = m.TerraformManager.TerraformDestroy(m.TerraformDir) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I was thinking of simply defer m.TerraformManager.TerraformDestroy(m.TerraformDir)
, but it might trigger an IDE warning instead. No strong opinion, let's keep it as is
What does this PR do?
Motivation
Address #293