Skip to content

fix: Check to see if an application exists globally before creating it #4113

Merged
mergify[bot] merged 16 commits intoaws:mainlinefrom
KollaAdithya:appglobal
Nov 14, 2022
Merged

fix: Check to see if an application exists globally before creating it #4113
mergify[bot] merged 16 commits intoaws:mainlinefrom
KollaAdithya:appglobal

Conversation

@KollaAdithya
Copy link
Copy Markdown
Contributor

@KollaAdithya KollaAdithya commented Oct 26, 2022

This PR resolves #815
For example, if you run copilot app init my-proj in us-east-1, then run copilot app init my-proj in us-west-2  the second init will fail.
This happens because CloudFormation creates an adminrole for the application of the form {app-name}-adminrole. CloudFormation can't create two roles with the same name since roles are global.

Currently, CloudFormation errors out saying
failed to create: [AdministrationRole]
stack {app-name}-infrastructure-roles did not complete successfully and exited with status ROLLBACK_COMPLETE

This PR will do the following

  1. Check to see if the application name exists in SSM
  2. If it doesn't, check to see if the role exists
  3. If the role exists, but the application doesn't exist shows an error: application named {app-name} already exists in another region
    Case 1:
    If you run copilot app init test-project in us-east-1 and If run copilot app init test-project in us-west-2 Then an error message shows application named test-project already exists in another region
    Case 2:
    If there is already a role existing in the account with same name as applicationname-adminrole then we will error out IAM admin role {applicationname}-adminrole already exists in this account

By submitting this pull request, I confirm that you can use, modify, copy, and redistribute this contribution, under the Apache 2.0 License.

@KollaAdithya KollaAdithya requested a review from a team as a code owner October 26, 2022 16:05
@KollaAdithya KollaAdithya requested review from efekarakus and removed request for a team October 26, 2022 16:05
Copy link
Copy Markdown
Contributor

@paragbhingre paragbhingre left a comment

Choose a reason for hiding this comment

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

Overall looks good 😎 I just have a question and a suggestion.

Comment thread internal/pkg/cli/app_init.go Outdated
Comment thread internal/pkg/cli/app_init.go Outdated
@paragbhingre
Copy link
Copy Markdown
Contributor

  1. Check to see if the application name exists in SSM

Are we actually checking anywhere that application does exist in the SSM?

@KollaAdithya
Copy link
Copy Markdown
Contributor Author

KollaAdithya commented Oct 26, 2022

There already a function func (s *Store) GetApplication(applicationName string) (*Application, error) that fetches the params in ssm by application name.
https://github.com/KollaAdithya/copilot-cli/blob/mainline/internal/pkg/config/app.go#L77

@paragbhingre
Copy link
Copy Markdown
Contributor

paragbhingre commented Oct 26, 2022

There already a function func (s *Store) GetApplication(applicationName string) (*Application, error) that fetches the params in ssm by application name.
https://github.com/KollaAdithya/copilot-cli/blob/mainline/internal/pkg/config/app.go#L77

So just trying to understand the flow here. So currently we create admin-role and then add application to SSM? Is that why we are specifically checking if SSM doesn't have the application and admin-role exist before erroring out?

@KollaAdithya
Copy link
Copy Markdown
Contributor Author

There already a function func (s *Store) GetApplication(applicationName string) (*Application, error) that fetches the params in ssm by application name.
https://github.com/KollaAdithya/copilot-cli/blob/mainline/internal/pkg/config/app.go#L77

So just trying to understand the flow here. So currently we create admin-role and then add application to SSM? Is that why we are specifically checking if SSM doesn't have the application and admin-role exist before erroring out?

Yes, when you are trying to deploy an application we create appname-adminrole and add application to Parameter Store. That is the reason we are checking SSM. So if the app name does not exist in SSM but appname-adminrole already exists means there is already an application with same name in other region. In this case we are erroring out that there is already an application with this name in another region.

Comment thread internal/pkg/cli/app_init.go Outdated
Comment thread internal/pkg/cli/app_init.go Outdated
@codecov-commenter
Copy link
Copy Markdown

codecov-commenter commented Oct 26, 2022

Codecov Report

Merging #4113 (a1fb088) into mainline (0fec236) will increase coverage by 0.02%.
The diff coverage is 78.26%.

@@             Coverage Diff              @@
##           mainline    #4113      +/-   ##
============================================
+ Coverage     69.27%   69.29%   +0.02%     
============================================
  Files           250      250              
  Lines         35887    35919      +32     
  Branches        264      264              
============================================
+ Hits          24861    24891      +30     
- Misses         9834     9837       +3     
+ Partials       1192     1191       -1     
Impacted Files Coverage Δ
internal/pkg/cli/app_init.go 64.16% <77.77%> (+3.62%) ⬆️
internal/pkg/cli/validate.go 73.77% <100.00%> (ø)

Help us with your feedback. Take ten seconds to tell us how you rate us. Have a feature suggestion? Share it here.

Comment thread internal/pkg/cli/app_init.go Outdated
Comment thread internal/pkg/cli/app_init.go Outdated
Copy link
Copy Markdown
Contributor

@Lou1415926 Lou1415926 left a comment

Choose a reason for hiding this comment

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

Looks good! Just some nits around the recommendations!

Comment thread internal/pkg/cli/app_init.go Outdated
Comment thread internal/pkg/cli/app_init.go Outdated
Comment thread internal/pkg/cli/app_init.go Outdated
Comment thread internal/pkg/cli/app_init.go Outdated
Comment thread internal/pkg/cli/app_init.go Outdated
Comment thread internal/pkg/cli/app_init.go Outdated
Comment thread internal/pkg/cli/app_init.go Outdated
Comment thread internal/pkg/cli/app_init.go Outdated
Comment thread internal/pkg/cli/app_init.go Outdated
@dannyrandall dannyrandall added the do-not-merge Pull requests that mergify shouldn't merge until the requester allows it. label Oct 31, 2022
@huanjani huanjani removed the do-not-merge Pull requests that mergify shouldn't merge until the requester allows it. label Nov 1, 2022
Comment thread internal/pkg/cli/app_init.go Outdated
Comment thread internal/pkg/cli/app_init.go Outdated
Comment thread internal/pkg/cli/app_init.go Outdated
Comment thread internal/pkg/cli/app_init.go
Comment thread internal/pkg/cli/app_init.go Outdated
Comment thread internal/pkg/cli/app_init.go Outdated
@github-actions
Copy link
Copy Markdown

github-actions Bot commented Nov 9, 2022

🍕 Here are the new binary sizes!

Name New size (kiB) v1.23.0 size (kiB) Delta (%)
macOS (amd) 47572 47548 +0.05
macOS (arm) 47572 48200 ❤️ -1.30
linux (amd) 41836 41812 +0.06
linux (arm) 41836 41220 🥺 +1.49
windows (amd) 38684 38664 +0.05

Copy link
Copy Markdown
Contributor

@dannyrandall dannyrandall left a comment

Choose a reason for hiding this comment

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

lgtm!

@Lou1415926 Lou1415926 added do-not-merge Pull requests that mergify shouldn't merge until the requester allows it. and removed do-not-merge Pull requests that mergify shouldn't merge until the requester allows it. labels Nov 11, 2022
Copy link
Copy Markdown
Contributor

@Lou1415926 Lou1415926 left a comment

Choose a reason for hiding this comment

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

The tests LGTM but why is the coverage dropping 😭

Comment thread internal/pkg/cli/app_init.go Outdated
Comment thread internal/pkg/cli/app_init.go
@KollaAdithya KollaAdithya removed the do-not-merge Pull requests that mergify shouldn't merge until the requester allows it. label Nov 14, 2022
@mergify mergify Bot merged commit 4b5837e into aws:mainline Nov 14, 2022
KollaAdithya added a commit to KollaAdithya/copilot-cli that referenced this pull request Nov 21, 2022
aws#4113)

This PR resolves aws#815
For example, if you run `copilot app init my-proj` in `us-east-1`, then run `copilot app init my-proj` in `us-west-2`  the second init will fail.
This happens because CloudFormation creates an adminrole for the application of the form `{app-name}-adminrole`. CloudFormation can't create two roles with the same name since roles are global.

Currently, CloudFormation errors out saying
failed to create: [AdministrationRole]
`stack {app-name}-infrastructure-roles did not complete successfully and exited with status ROLLBACK_COMPLETE`

This PR will do the following
1. Check to see if the application name  exists in SSM
2. If it doesn't, check to see if the role exists
3. If the role exists, but the application doesn't exist shows an error: `application named  {app-name} already exists in another region`
Case 1:
If you run `copilot app init test-project` in `us-east-1` and If run `copilot app init test-project `in `us-west-2` Then an error message shows `application named test-project already exists in another region`
Case 2: 
If there is already a role existing in the account with same name as `applicationname-adminrole` then we will error out `IAM admin role  {applicationname}-adminrole already exists in this account`






By submitting this pull request, I confirm that you can use, modify, copy, and redistribute this contribution, under the Apache 2.0 License.
@KollaAdithya KollaAdithya deleted the appglobal branch February 7, 2023 01:59
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.

Check to see if an application exists globally before creating it

8 participants