Skip to content

Commit 0fc55fa

Browse files
committed
fix(integ): assert zero inline SecurityGroupIngress on both SGs in sg-circular verify.sh
The fixture comments (verify.sh, the lib stack JSDoc, and README.md) claim the script confirms zero inline SecurityGroupIngress entries on either SG, but verify.sh only ran positive checks (>= 2 standalone AWS::EC2::SecurityGroupIngress resources, >= 2 carrying SourceSecurityGroupId). It never asserted the inline Properties.SecurityGroupIngress was empty, so the comment's claim was not enforced. Add a jq guard against the synthesized template asserting NO AWS::EC2::SecurityGroup carries a non-empty Properties.SecurityGroupIngress array (an inline ingress pointing at the other SG is exactly what would reintroduce the CFn cycle this fixture exists to avoid). The check fails with a clear message naming the offending SG logical id(s). BSD/macOS-portable (no grep -P). The existing comments now match the enforced behavior (review fix).
1 parent af2ee04 commit 0fc55fa

1 file changed

Lines changed: 17 additions & 0 deletions

File tree

  • tests/integration/sg-circular-dependency

tests/integration/sg-circular-dependency/verify.sh

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -168,6 +168,23 @@ if [ "${CROSS_REF_COUNT}" -lt 2 ]; then
168168
exit 1
169169
fi
170170
echo " OK: ${CROSS_REF_COUNT} ingress resources carry a SG-to-SG SourceSecurityGroupId (true circular ref)"
171+
172+
# Confirm NO AWS::EC2::SecurityGroup carries a non-empty inline
173+
# `Properties.SecurityGroupIngress` array — the circular refs MUST be emitted
174+
# ONLY as standalone AWS::EC2::SecurityGroupIngress resources (an inline ingress
175+
# entry pointing at the other SG is exactly what reintroduces the CFn cycle this
176+
# fixture exists to avoid). Names the offending SG logical id on failure.
177+
INLINE_INGRESS_SGS=$(jq -r '[.Resources | to_entries[]
178+
| select(.value.Type == "AWS::EC2::SecurityGroup")
179+
| select((.value.Properties.SecurityGroupIngress // []) | length > 0)
180+
| .key] | join(", ")' "${TEMPLATE_FILE}")
181+
if [ -n "${INLINE_INGRESS_SGS}" ]; then
182+
echo "FAIL: SecurityGroup(s) carry a non-empty inline Properties.SecurityGroupIngress: ${INLINE_INGRESS_SGS} — the circular refs must be emitted ONLY as standalone AWS::EC2::SecurityGroupIngress resources, not inline ingress" >&2
183+
jq '.Resources | to_entries[] | select(.value.Type == "AWS::EC2::SecurityGroup") | {id: .key, ingress: .value.Properties.SecurityGroupIngress}' "${TEMPLATE_FILE}" >&2
184+
rm -rf "${SYNTH_DIR}"
185+
exit 1
186+
fi
187+
echo " OK: zero inline Properties.SecurityGroupIngress on any SecurityGroup (cross-refs are standalone-only)"
171188
rm -rf "${SYNTH_DIR}"
172189

173190
# --- Phase 1: deploy --------------------------------------------------------

0 commit comments

Comments
 (0)