Skip to content

Commit

Permalink
Refactor updateTargetGroups function to filter environments based on …
Browse files Browse the repository at this point in the history
…their status
  • Loading branch information
tmshkr committed Jan 2, 2024
1 parent b108e0e commit 655689a
Showing 1 changed file with 9 additions and 11 deletions.
20 changes: 9 additions & 11 deletions src/updateListenerRules.ts
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,9 @@ export async function removeTargetGroups(inputs: ActionInputs) {

export async function updateTargetGroups(inputs: ActionInputs) {
const { prodEnv, stagingEnv } = await getEnvironments(inputs);
const environments = [prodEnv, stagingEnv].filter((env) => !!env);
const environments = [prodEnv, stagingEnv].filter(
(env) => env?.Status === "Ready"
);
const resources = await getEnvironmentResources(environments);
const rules = await getRules(resources);
const targetGroupARNs = await findTargetGroupArns(
Expand Down Expand Up @@ -239,18 +241,14 @@ async function getRules(resources: EnvironmentResourceDescription[]) {
throw new Error("Environments must use the same load balancer");
}

const loadBalancerArn = Array.from(loadBalancerArns)[0];
const listeners: Listener[] = [];
await elbv2Client
.send(
new DescribeListenersCommand({
LoadBalancerArn: loadBalancerArn,
})
)
.then(({ Listeners }) => listeners.push(...Listeners));
const { Listeners } = await elbv2Client.send(
new DescribeListenersCommand({
LoadBalancerArn: Array.from(loadBalancerArns)[0],
})
);

const rules: Rule[] = [];
for (const { ListenerArn } of listeners) {
for (const { ListenerArn } of Listeners) {
await elbv2Client
.send(new DescribeRulesCommand({ ListenerArn: ListenerArn }))
.then(({ Rules }) => {
Expand Down

0 comments on commit 655689a

Please sign in to comment.