Description
Using TagParameterContainerImage
as a property for a stack in a different account causes a resolution error.
Reproduction Steps
const myPipeline = new MyPipeline(app, 'my-pipeline', {
env: nonprod
}
new MyFargateApp(app, 'my-app', {
env: prod
image: myPipeline.tagParameterContainerImage
}
What did you expect to happen?
Stack my-app
should reference the ECR repo from my-pipeline
.
What actually happened?
Error: Resolution error: Resolution error: Resolution error: Resolution error: Resolution error: Cannot use resource 'my-app/FargateService/TaskDef/ExecutionRole' in a cross-environment fashion, the resource's physical name must be explicit set or use 'PhysicalName.GENERATE_IF_NEEDED'.
Environment
- CDK CLI Version : 1.107.0 (build 52c4434)
- Framework Version: 1.107.0
- Node.js Version: 14.16.0
- OS : WSL2 Ubuntu 20.04.02 LTS on Windows 10 1909
- Language (Version): TypeScript (3.9.9)
Other details
I'm using ApplicationLoadBalancedFargateService
.
This is 🐛 Bug Report
Activity
skinny85 commentedon Jun 10, 2021
Thanks for reporting @danwiltshire. Confirming I was able to reproduce it. I'm working on a fix.
In the meantime, you should be able to unblock yourself by passing the
executionRole
of theTaskDefinition
explicitly with a Role that has the name set, like so:If you don't want to set a name yourself, you can pass
roleName
ascdk.PhysicalName.GENERATE_IF_NEEDED
, and the CDK will generate it for you automatically.fix(ecs): TagParameterContainerImage cannot be used across accounts
danwiltshire commentedon Jun 11, 2021
Hey @skinny85 thanks, this got me a bit further. I'm now getting another issue where the ECR policy principal is not valid.
Error:
Invalid parameter at 'PolicyText' failed to satisfy constraint: 'Invalid repository policy provided'
Cause: The
Principal
field must contain an asterisk when a full role ARN is used.Solutions:
Synthed CFN:
Working policy:
Other notes:
Statement[0].Principal must match the following: "/\*/" @ Statement[0].Principal
Workaround
If you need this in a new issue I'm happy to spin one up.
skinny85 commentedon Jun 11, 2021
Hmm, but the error you get and the resolution don't match each other...?
This does not contain a
*
in the Principal of the Statement...?danwiltshire commentedon Jun 11, 2021
Correct, that seems to be the second available solution.
If you were to take a role ARN and put an asterisk in, that works to.
skinny85 commentedon Jun 11, 2021
But an asterisk where? 🤔 Just tack it on randomly at the end of the Role ARN?
danwiltshire commentedon Jun 14, 2021
Yeah pretty much. I wonder if ECR just doesn't allow granting access to roles? Looking at the AWS docs granting a role isn't listed: https://docs.aws.amazon.com/AmazonECR/latest/userguide/repository-policy-examples.html
23 remaining items