-
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
Cyclic Reference Error (test-cdk-dev/test-cdk-dev-ecs.AWS::URLSuffix) would create a cyclic reference. #3970
Comments
Hi @btotharye, This might not be a bug and the error will not appear if you put Also a nitpick: |
Ill test and that was just something I forgot to remove to hide things... |
Also @iamhopaul123 is there any easier way than having to pass all these objects like I am or is that my only way? |
Not so sure about that since I personally mostly use TypeScript. However, from my experience using TypeScript, you might also try putting them (VpcStack, EcsStack) together if the construct is not that complicated. However, if you want to separate them out. I need to do more investigation about the dependency rule. |
@btotharye And also putting them into two separate files will actually results in two CFN templates (two different stacks). Not sure if that's what you want. I would suggest use one stack will be much easier. |
@iamhopaul123 I only started down the multi stack path because on a recent call AWS said it would be better to do it this way and split up the VPC and such into one stack, then have the ECS etc be in another stack. I'm still not sure how the ECR image location in this circumstance would also cause the cyclic reference? I'm going to update it and see if it fixes it by moving it to the vpc stack it was just odd IMO. Can you shed any light why the ECR repo in this case would cause the cyclic reference? |
So updating the stack and moving the ECR reference to the vpc stack resolved the cyclic issue but still not sure why that had to be there necessarily, maybe I don't understand fully how some of the multi stack stuff and dependencies work. |
@btotharye From my understanding it seems like when you do a nested stack, all the resources of the nested stack has to come from the parent stack. And this might be the reason why you cannot put ECR reference in the nested stack because AWS::URLSuffix does not come from its parent. However, I don't think nested stacks is currently supported in CDK (see here). Also I think the most common use cases for multiple stacks are deploying in different regions (see here), or separate staging/QA instances of the same app (see here). |
I think this might be an issue with the stack object losing its identity when being passed over the jsii barrier. Seeing the last line of the error message:
In this line, it looks like the |
`stack.urlSuffix` used to be a scoped Token. By the use of roles defined in another stack (using a `ServicePrincipal` which uses a `urlSuffix` token), this could lead to unintentional stack references. Two changes here: * URL Suffix (seems to) only change when Partition changes. Since Partition is unscoped (cross-partition references won't work anyway), we might as well make URL Suffix unscoped too. * `ServicePrincipalToken` should not have used the stack's `urlSuffix`, but constructed an unscoped `URL_SUFFIX` itself, since it was never intended to potentially create a cross-stack reference. It couldn't have, since it doesn't know where it is being defined, it just knows where it's being used. Technically, the second change isn't necessary anymore after we apply the first, but I made both anyway since the bug is still resolved even if find out we need roll back the first change because of a future region build. Fixes #3970.
`stack.urlSuffix` used to be a scoped Token. By the use of roles defined in another stack (using a `ServicePrincipal` which uses a `urlSuffix` token), this could lead to unintentional stack references. Two changes here: * URL Suffix (seems to) only change when Partition changes. Since Partition is unscoped (cross-partition references won't work anyway), we might as well make URL Suffix unscoped too. * `ServicePrincipalToken` should not have used the stack's `urlSuffix`, but constructed an unscoped `URL_SUFFIX` itself, since it was never intended to potentially create a cross-stack reference. It couldn't have, since it doesn't know where it is being defined, it just knows where it's being used. Technically, the second change isn't necessary anymore after we apply the first, but I made both anyway since the bug is still resolved even if find out we need roll back the first change because of a future region build. Fixes #3970.
🐛 Bug Report
What is the problem?
So when trying to setup a multi stack setup it works fine until I add some parts in around ecs.FargateTaskDefinition requirement then I get the following error:
I have example code in a gist at https://gist.github.com/btotharye/d9de3ed45b17cc4ba87ea7d902b8ec65 if you look at the ecs_stack.py file you will see that on lines 49-73 if I remove this part everything works fine, but if I add that part back in I get the URLSuffix cylic error and I'm not sure why.
Reproduction Steps
I basically can do a
cdk diff '*' -c stage=dev
on the gist at https://gist.github.com/btotharye/d9de3ed45b17cc4ba87ea7d902b8ec65 I have omitted the cdk.json for some special values but its nothing special just props I pass in.Verbose Log
Environment
Other information
The text was updated successfully, but these errors were encountered: