Skip to content

test(e2e): clean redundant task stack for task e2e test#1267

Merged
mergify[bot] merged 2 commits intoaws:mainlinefrom
iamhopaul123:e2e/quick-fix
Aug 14, 2020
Merged

test(e2e): clean redundant task stack for task e2e test#1267
mergify[bot] merged 2 commits intoaws:mainlinefrom
iamhopaul123:e2e/quick-fix

Conversation

@iamhopaul123
Copy link
Copy Markdown
Contributor

Currently our task e2e test doesn't delete the task stack after running the task e2e test. And the task stack is very difficult to remove because the CFN Execution Role that used to manage the task stack is deleted when we delete copilot environment. Also, the remaining task stacks piles up in our Copilot pipeline account.

This PR fixes this issue by removing task stack before we delete copilot app/env.

By submitting this pull request, I confirm that you can use, modify, copy, and redistribute this contribution, under the terms of your choice.

@iamhopaul123 iamhopaul123 requested a review from a team as a code owner August 13, 2020 19:28
@iamhopaul123 iamhopaul123 requested a review from kohidave August 13, 2020 19:28
@iamhopaul123 iamhopaul123 added the do-not-merge Pull requests that mergify shouldn't merge until the requester allows it. label Aug 13, 2020
@huanjani
Copy link
Copy Markdown
Contributor

Does the env get deleted, too?

@iamhopaul123
Copy link
Copy Markdown
Contributor Author

Does the env get deleted, too?

yeah copilot app delete automatically deletes all env/svc in the app and then deletes the app.

@efekarakus efekarakus changed the title fix(e2e): clean redundant task stack for task e2e test test(e2e): clean redundant task stack for task e2e test Aug 13, 2020
@iamhopaul123 iamhopaul123 removed the do-not-merge Pull requests that mergify shouldn't merge until the requester allows it. label Aug 14, 2020
err := command.Run("aws", []string{"ecr", "delete-repository", "--repository-name", repoName, "--force"})
Expect(err).NotTo(HaveOccurred(), "delete ecr repo")
// Delete task stack.
err = command.Run("aws", []string{"cloudformation", "delete-stack", "--stack-name", taskStackName})
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.

So I'm trying to understand based on the error that you saw yesterday while trying to delete from console:

Role arn:aws:iam::xxx:role/e2e-task-1597338546-test-CFNExecutionRole is invalid or cannot be assumed

Will this have the necessary permissions? how come?

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.

yeah it will have. I tested that. So it's because we still have the CFN execution role since we haven't deleted the environment yet.

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.

Ok thanks that totally makes sense!

I think one thing that these tests made us realize is that if a customer uses the same task group name to run their tasks both in a Copilot env and then in default, they won't be able to delete the stack in case the Copilot environment is deleted which is slightly surprising:

It is not possible to remove a service role attached to a stack after the stack is created.

https://docs.aws.amazon.com/AWSCloudFormation/latest/UserGuide/using-iam-servicerole.html

Maybe, when we implement task delete we can provide a nicer err message with action items when this err occurs.

err := command.Run("aws", []string{"ecr", "delete-repository", "--repository-name", repoName, "--force"})
Expect(err).NotTo(HaveOccurred(), "delete ecr repo")
// Delete task stack.
err = command.Run("aws", []string{"cloudformation", "delete-stack", "--stack-name", taskStackName})
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.

Ok thanks that totally makes sense!

I think one thing that these tests made us realize is that if a customer uses the same task group name to run their tasks both in a Copilot env and then in default, they won't be able to delete the stack in case the Copilot environment is deleted which is slightly surprising:

It is not possible to remove a service role attached to a stack after the stack is created.

https://docs.aws.amazon.com/AWSCloudFormation/latest/UserGuide/using-iam-servicerole.html

Maybe, when we implement task delete we can provide a nicer err message with action items when this err occurs.

@mergify mergify bot merged commit 35679bb into aws:mainline Aug 14, 2020
thrau pushed a commit to localstack/copilot-cli-local that referenced this pull request Dec 9, 2022
<!-- Provide summary of changes -->
Currently our task e2e test doesn't delete the task stack after running the task e2e test. And the task stack is very difficult to remove because the CFN Execution Role that used to manage the task stack is deleted when we delete copilot environment.  Also, the remaining task stacks piles up in our Copilot pipeline account.

This PR fixes this issue by removing task stack before we delete copilot app/env.
<!-- Issue number, if available. E.g. "Fixes aws#31", "Addresses aws#42, 77" -->

By submitting this pull request, I confirm that you can use, modify, copy, and redistribute this contribution, under the terms of your choice.
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.

4 participants