cloud
template_error
ai_generated
true
Circular dependency between resources: [SecurityGroup, LaunchTemplate, SecurityGroup]
ID: cloud/aws-cloudformation-circular-dependency
85%Fix Rate
88%Confidence
3Evidence
2023-01-01First Seen
Version Compatibility
| Version | Status | Introduced | Deprecated | Notes |
|---|---|---|---|---|
| any | active | — | — | — |
Root Cause
CloudFormation circular dependencies often arise from security groups referencing each other, or EC2 instances referencing their own security group. The error message lists the cycle but the fix requires restructuring.
genericWorkarounds
-
95% success Use SecurityGroupIngress/Egress as separate resources to break SG cycles
Instead of inline ingress in SG, create separate AWS::EC2::SecurityGroupIngress resource referencing both SGs
-
82% success Split the stack into nested stacks with cross-stack references
Create SGs in one stack, reference them via Fn::ImportValue in another stack
-
88% success Use Fn::GetAtt and separate the creation from the rule attachment
Create SGs with no rules -> Create rules as separate resources referencing SG IDs
Dead Ends
Common approaches that don't work:
-
Add explicit DependsOn to break the cycle
88% fail
DependsOn only adds dependencies, never removes them. Adding more DependsOn to a cycle makes it worse.
-
Merge the circular resources into one resource
72% fail
Merging security groups loses fine-grained access control and makes the template harder to maintain.