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

Optional CodeDeploy IAM Roles #25

Merged

Conversation

MrThomasWagner
Copy link
Contributor

Hello, awesome plugin!

For security reasons, I cannot create IAM Roles using the same credentials that I have for my normal AWS workflow. So, I can't use the plugin as-is since it attempts to create an IAM role for CodeDeploy.

I've added a configuration parameter to deploymentSettings named codeDeployRole. If it's given in the serverless.yml with an arn as the value, the templates will not attempt to create a CodeDeploy role and instead reference the existing one.

Lemme know what you think -

p.s. JS is not my primary language so please bear with me - I'd happily make changes if anything here doesn't follow your conventions.

Tommy Wagner added 2 commits April 4, 2018 09:44
…nfiguration,

in which case an IamRole for CodeDeploy will be referenced in the CloudFormation config
instead of created
Copy link
Owner

@davidgf davidgf left a comment

Choose a reason for hiding this comment

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

Thanks a lot for your contribution! Please, check out the review and let me know if it makes sense to you

if(typeof deploymentSettings.codeDeployRole === "undefined") {
Object.assign(codeDeployRole, this.buildCodeDeployRole());
}

Copy link
Owner

Choose a reason for hiding this comment

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

By shifting the role creation to the .buildFunctionResources() function, you'd be creating as many roles as functions with deploymentSettings, while we only need one. The codeDeployRole configuration should be global, not per function, so you could place it in the custom section of serverless.yml:

custom:
  deploymentSettings:
    codeDeployRole: <...>

Actually, this section is already being used for setting defaults, although it is not documented (shame on me 😅 ). So, it would probably make sense to move the logic for generating the role back to the .addCanaryDeploymentResources() function, and check if there's a role configured in .buildCodeDeployRole(), returning an empty object it exists.

]
}

if (typeof codeDeployRole != 'undefined') {
Copy link
Owner

Choose a reason for hiding this comment

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

This could be simplified with something like:

const role =  codeDeployRole || lookupRole;
Object.assign(deploymentGroup.Properties, { SericeRoleArn: role });

@MrThomasWagner
Copy link
Contributor Author

MrThomasWagner commented Apr 4, 2018

Still todo:

  • Update readme to document 'global' behavior of codeDeployRole config

@MrThomasWagner
Copy link
Contributor Author

@davidgf I made your requested changes. Lemme know if that looks good

@davidgf
Copy link
Owner

davidgf commented Apr 8, 2018

@MrThomasWagner thanks a lot, it looks fine. I'd like to perform some tests, if everything is OK I'll merge it. Thanks!

@MrThomasWagner
Copy link
Contributor Author

@davidgf Any idea of an ETA on a merge for this?

@davidgf davidgf merged commit 0cafa60 into davidgf:master Apr 16, 2018
@davidgf
Copy link
Owner

davidgf commented Apr 16, 2018

@MrThomasWagner sorry for the delay! I've already merged it and published it to npm

samcon pushed a commit to samcon/serverless-plugin-canary-deployments that referenced this pull request Sep 6, 2020
* Allow for a CodeDeploy role to be specified via deploymentSettings configuration,
in which case an IamRole for CodeDeploy will be referenced in the CloudFormation config
instead of created

* Update the readme with the new configuration option and add in an example of the policy used for codedeploy

* Move codeDeployRole creation into the 'globalresources' section - i.e. dont create a role for every function

* Udpate readme to document codedeploy role

* Minor tweaks
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