How would you break a dependency cycle between two resources?
AdvancedConceptLifecycle, Dependencies, Provisioners and Drift
Answer
Find the loop (terraform graph | dot -Tsvg, or the error's list of nodes). The usual cause is two security groups referencing each other inline: split the rules into separate aws_security_group_rule or aws_vpc_security_group_ingress_rule resources so both groups exist first. Another trick is introducing an intermediate resource or passing a static name instead of an attribute.
More on Lifecycle, Dependencies, Provisioners and Drift
What are meta-arguments?BeginnerWhat lifecycle options are available?BeginnerHow does `create_before_destroy` work and what can go wrong?AdvancedWhat does `prevent_destroy` guarantee and what does it not?AdvancedWhen do you use `ignore_changes`?IntermediateWhat does `replace_triggered_by` do?Advanced