-
Notifications
You must be signed in to change notification settings - Fork 4k
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
feat(codepipeline): allow cross-account CloudFormation Actions #3208
feat(codepipeline): allow cross-account CloudFormation Actions #3208
Conversation
packages/@aws-cdk/aws-codepipeline-actions/lib/cloudformation/pipeline-actions.ts
Outdated
Show resolved
Hide resolved
packages/@aws-cdk/aws-codepipeline-actions/lib/cloudformation/pipeline-actions.ts
Show resolved
Hide resolved
let targetAccountStack: Stack | undefined = this._crossAccountSupport[targetAccount]; | ||
if (!targetAccountStack) { | ||
const app = this.requireApp(); | ||
targetAccountStack = new Stack(app, `cross-account-support-stack-${targetAccount}`, { |
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.
No need to add the stack directly under the app. Add it inside the pipeline's scope
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.
Done.
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.
Scratch that. This does not work for some reason. The unit test in the codepipeline-actions
package that tests the new behavior for the CFN actions fail when anchoring the new stack under the pipeline:
Error: Can only reference cross stacks in the same region and account. target = PipelineStack/Pipeline/cross-account-support-stack-123456789012/PipelineStackPipeline9DB740AF-Deploy-CFN-DeploymentRole/Resource
It seems to me like the cross-account behavior is not triggered at all when I add the new stack under the pipeline's scope (this is an error message from CfnReference
).
Any ideas why might that be...? Could it be because Stack.of(...)
does not work correctly if stacks are nested under constructs...?
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 think you are right. I think there is a bug in how substacks consume references. I will run some more tests tomorrow morning and hope to have some better understanding of this.
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.
This actually makes sense. The pipeline stack references the role in the other account and the automatic cross-stack references are triggered, but those only work for same-environment since they use exports/imports.
Digging further...
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.
Okay, haven't managed to figure out what the issue is. I still think there is a bug somewhere, but you'll have to dig further from your end. I've added a bunch of tests to verify some assumptions: #3373
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.
Ok. I've updated the PR to fix the out of order imports. Let's see if the build passes this time.
44bd30e
to
15d43cb
Compare
Updated with the comments on the previous revision. |
packages/@aws-cdk/aws-codepipeline-actions/lib/cloudformation/pipeline-actions.ts
Outdated
Show resolved
Hide resolved
packages/@aws-cdk/aws-codepipeline-actions/lib/cloudformation/pipeline-actions.ts
Show resolved
Hide resolved
15d43cb
to
fee4c7a
Compare
I've updated the PR with all comments. The only exception is changing the parent of the newly created stack, as anchoring it under the pipeline construct makes the unit test fail (see above comment). |
if (this.isAwsOwned(action)) { | ||
return action.actionProperties.role; | ||
} else { | ||
throw new Error("Specifying a Role is not supported for actions with an owner different than 'AWS' - " + |
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.
The terminology "owner" here is extremely confusing (especially since we use it to indicate "owned resources"). How about something like "The action X does not support specifying a role".
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.
Just to be clear: I'm talking here about this property.
Given that, does the error message makes sense? (I'm not worried about the isAwsOwned()
method, it's private anyway)
EDIT: maybe this is a better explanation of the owner
property
fee4c7a
to
54dacc8
Compare
Newest batch of addressed comments. |
Feel free to re-review @eladb . |
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.
Please update README
Can the conflicts here be resolved and the PR merged? |
Please hold off on merging this ATM. I'll handle it. |
54dacc8
to
9a35fd3
Compare
I realized something while working on the cross-account events in #3323. In previous revisions of this PR, I was caching the "scaffold stacks" (the ones generated for the IAM roles needed for cross-account deployments) for the actions on the Pipeline level. But that doesn't make sense; it should be global, on the |
9a35fd3
to
696e2ee
Compare
Rebased. |
This adds a property 'account' to all CloudFormation CodePipeline actions, and properly handles passing it in the pipeline construct.
696e2ee
to
5f04f2b
Compare
Updated the ReadMe. |
This adds a property 'account' to all CloudFormation CodePipeline Actions,
and properly handles passing it in the Pipeline construct.
Please read the contribution guidelines and follow the pull-request checklist.
By submitting this pull request, I confirm that my contribution is made under the terms of the Apache-2.0 license