Skip to content
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

fix(alb): allow actions with no TargetGroup #123

Merged
merged 1 commit into from
Nov 12, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading