Skip to content

Commit

Permalink
Merge pull request #123 from fourTheorem/fix/allow-alb-no-tg-ref
Browse files Browse the repository at this point in the history
fix(alb): allow actions with no TargetGroup
  • Loading branch information
eoinsha authored Nov 12, 2024
2 parents c7a788e + 3963629 commit d532930
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 1 deletion.
2 changes: 1 addition & 1 deletion core/alarms/alb-target-group.ts
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ export function findLoadBalancersForTargetGroup (targetGroupLogicalId: string, c
for (const [listenerRuleLogicalId, listenerRule] of Object.entries(listenerRuleResources)) {
for (const action of listenerRule.Properties?.Actions ?? []) {
const targetGroupArn = action.TargetGroupArn
if (targetGroupArn.Ref === targetGroupLogicalId) {
if (typeof targetGroupArn === 'object' && targetGroupArn.Ref === targetGroupLogicalId) {
allListenerRules[listenerRuleLogicalId] = listenerRule
break
}
Expand Down
24 changes: 24 additions & 0 deletions core/alarms/tests/alb-target-group.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -79,6 +79,7 @@ test('findLoadBalancersForTargetGroup', (t) => {
t.equal(loadBalancerLogicalIds.length, 0)
t.end()
})

test('finds load balancers through listener rule target groups', (t) => {
const compiledTemplate = {
Resources: {
Expand Down Expand Up @@ -189,6 +190,29 @@ test('findLoadBalancersForTargetGroup', (t) => {
t.end()
})

test('handles actions without a target group', (t) => {
const compiledTemplate = {
Resources: {
listenerRuleA: {
Type: 'AWS::ElasticLoadBalancingV2::ListenerRule',
Properties: {
Actions: [{ AuthenticateOidcConfig: {} }],
ListenerArn: { Ref: 'listener' }
}
},
listener: {
Type: 'AWS::ElasticLoadBalancingV2::Listener',
Properties: {
LoadBalancerArn: 'arn:aws:elasticloadbalancing:us-west-2:123456789012:loadbalancer/app/my-load-balancer/50dc6c495c0c9188'
}
}
}
}
const loadBalancerLogicalIds = findLoadBalancersForTargetGroup('tgA', compiledTemplate)
t.equal(loadBalancerLogicalIds.length, 0)
t.end()
})

test('ALB Target Group alarms are created', (t) => {
const testConfig = createTestConfig(
defaultConfig.alarms,
Expand Down

0 comments on commit d532930

Please sign in to comment.