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

Simplify props #11

Merged
merged 1 commit into from
Jan 22, 2024
Merged
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
26 changes: 14 additions & 12 deletions index.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import * as pathlib from 'path';
import { Stack, Duration, Arn } from 'aws-cdk-lib';
import * as cdk from 'aws-cdk-lib';
import * as ecs from 'aws-cdk-lib/aws-ecs';
import * as events from 'aws-cdk-lib/aws-events';
import * as eventsTargets from 'aws-cdk-lib/aws-events-targets';
Expand All @@ -13,7 +13,6 @@ export interface MutableTagEcsUpdaterProps {
ecsService: ecs.IBaseService;
pullSecret: secretsmanager.ISecret;
autoUpdateRate?: string;
clusterStack?: Stack;
}

export class MutableTagEcsUpdater extends Construct {
Expand All @@ -28,13 +27,13 @@ export class MutableTagEcsUpdater extends Construct {
ECS_CLUSTER_NAME: props.ecsCluster.clusterName,
ECS_SERVICE_NAME: props.ecsService.serviceName,
GHCR_PULL_SECRET_NAME: props.pullSecret.secretName,
GHCR_PULL_SECRET_CACHE_SECONDS_TTL: String(Duration.days(1).toSeconds()),
GHCR_PULL_SECRET_CACHE_SECONDS_TTL: String(cdk.Duration.days(1).toSeconds()),
},
memorySize: 512,
});

new events.Rule(this, 'AutoUpdateRule', {
schedule: events.Schedule.rate(Duration.parse(props.autoUpdateRate ?? 'PT5M')),
schedule: events.Schedule.rate(cdk.Duration.parse(props.autoUpdateRate ?? 'PT5M')),
targets: [new eventsTargets.LambdaFunction(tagUpdateLambda)],
});

Expand All @@ -52,19 +51,22 @@ export class MutableTagEcsUpdater extends Construct {
resources: ['*'],
}),
);

const clusterArnParts = cdk.Arn.split(props.ecsCluster.clusterArn, cdk.ArnFormat.SLASH_RESOURCE_NAME);
const clusterTasksArn = cdk.Arn.format(
{
...clusterArnParts,
resource: 'task',
resourceName: `${clusterArnParts.resourceName}/*`,
},
);

tagUpdateLambda.addToRolePolicy(
new iam.PolicyStatement({
actions: ['ecs:DescribeTasks'],
resources: [
`${props.ecsService.serviceArn}/*`,
Arn.format(
{
resource: 'task',
service: 'ecs',
resourceName: `${props.ecsCluster.clusterName}/*`,
},
props.clusterStack,
),
clusterTasksArn,
],
}),
);
Expand Down