-
Notifications
You must be signed in to change notification settings - Fork 3.9k
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
ec2: grantAttachVolume
results in circular dependency
#29298
Comments
I should also mention (let me know if this should be a separate issue) using the Change above to repro:
This is a little bit less obvious of a solution, but AWS should consider setting this to the resolved AZ (and other props) rather than the instance attribute: https://github.com/aws/aws-cdk/blob/v2.130.0/packages/aws-cdk-lib/aws-ec2/lib/instance.ts#L479
The underlying attribute would still be accessible from |
grantAttachVolume
results in circular dependencygrantAttachVolume
results in circular dependency
Looks like we have to break this circular dependency but I have so solution off the top of my head: instance -> role -> policy -> instance According to the document, we probably should not specify the instance ID but the condition instead. Being said, I guess you will need to create the policy like this and optionally apply your own condition like this: ec2Instance.addToRolePolicy(new iam.PolicyStatement({
actions: ['ec2:AttachVolume'],
resources: [
`arn:${stack.partition}:ec2:${stack.region}:${stack.account}:volume/${volume.volumeId}`,
],
}));
ec2Instance.addToRolePolicy(new iam.PolicyStatement({
actions: ['ec2:AttachVolume'],
resources: [
`arn:${stack.partition}:ec2:${stack.region}:${stack.account}:instance/*`,
],
conditions: {
"StringEquals": {"aws:ResourceTag/Department": "Development"}
},
})); |
Sorry I might be missing something but I think creating a separate policy would break the dependency loop
The role doesn't actually need to depend on the policy it just happens in the way this is implemented (default inline policy on role) if we create a separate This is to make it super obvious but the instanceRole can also get create in the instance code and referenced as a property since it's not actually a CF Attr of the underlying CF resource
|
Describe the bug
When creating an ec2 instance and then granting attach volume, it results in a circular dependency because it tries to add to the role's default policy which the instance depends on, and then the grant depends on the instance to include the instance id in the policy.
Expected Behavior
It should not result in a circular dependency
Current Behavior
The text was updated successfully, but these errors were encountered: