Skip to content
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

Merged
merged 2 commits into from
Feb 13, 2023
Merged

Cleanup AWS resources in case of warm up error #315

merged 2 commits into from
Feb 13, 2023

Conversation

rollwagen
Copy link
Contributor

What does this PR do?

  • Bug fix

Motivation

Address #293

@christophetd
Copy link
Contributor

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)
Copy link
Contributor

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

Copy link
Contributor Author

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)
		}()

Copy link
Contributor

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

@rollwagen
Copy link
Contributor Author

rollwagen commented Feb 10, 2023

would it make sense to add/edit an existing test case

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"])
},
},
{
Copy link
Contributor

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)
Copy link
Contributor

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

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.

None yet

2 participants