Skip to content

Commit

Permalink
feat: Tag resources with provider name (#582)
Browse files Browse the repository at this point in the history
Resources belonging to providers will be tagged with `GitHubRunners:Provider` containing the CDK node path which includes the provider id. This should make it possible to see what resources are being used for which provider. The resources provisioned for runners by the provider should also be tagged where possible.

For example:
```
{
  "Key": "GitHubRunners:Provider",
  "Value": "github-runners-test/CodeBuildx64"
}
```
  • Loading branch information
kichik authored May 31, 2024
1 parent f0aebce commit 4720271
Show file tree
Hide file tree
Showing 4 changed files with 596 additions and 59 deletions.
2 changes: 2 additions & 0 deletions src/providers/common.ts
Original file line number Diff line number Diff line change
Expand Up @@ -485,6 +485,8 @@ export interface IRunnerProvider extends ec2.IConnectable, iam.IGrantable, ICons
export abstract class BaseProvider extends Construct {
protected constructor(scope: Construct, id: string, _props?: RunnerProviderProps) {
super(scope, id);

cdk.Tags.of(this).add('GitHubRunners:Provider', this.node.path);
}

protected labelsFromProperties(defaultLabel: string, propsLabel: string | undefined, propsLabels: string[] | undefined): string[] {
Expand Down
16 changes: 16 additions & 0 deletions src/providers/ec2.ts
Original file line number Diff line number Diff line change
Expand Up @@ -480,6 +480,22 @@ export class Ec2RunnerProvider extends BaseProvider implements IRunnerProvider {
SpotInstanceType: 'one-time',
},
} : undefined,
TagSpecifications: [ // manually propagate tags
{
ResourceType: 'instance',
Tags: [{
Key: 'GitHubRunners:Provider',
Value: this.node.path,
}],
},
{
ResourceType: 'volume',
Tags: [{
Key: 'GitHubRunners:Provider',
Value: this.node.path,
}],
},
],
},
iamResources: ['*'],
});
Expand Down
4 changes: 2 additions & 2 deletions test/default.integ.snapshot/github-runners-test.assets.json
Original file line number Diff line number Diff line change
Expand Up @@ -209,15 +209,15 @@
}
}
},
"e376a00434ff844e4066a874db82613a7fb1dba5b0b64df2dcba11a03f81ac3a": {
"54ea0c28666f3fa077b83dbc9a02d3d6d3304dbd52deb343fc69e6a7ca821b0e": {
"source": {
"path": "github-runners-test.template.json",
"packaging": "file"
},
"destinations": {
"current_account-current_region": {
"bucketName": "cdk-hnb659fds-assets-${AWS::AccountId}-${AWS::Region}",
"objectKey": "e376a00434ff844e4066a874db82613a7fb1dba5b0b64df2dcba11a03f81ac3a.json",
"objectKey": "54ea0c28666f3fa077b83dbc9a02d3d6d3304dbd52deb343fc69e6a7ca821b0e.json",
"assumeRoleArn": "arn:${AWS::Partition}:iam::${AWS::AccountId}:role/cdk-hnb659fds-file-publishing-role-${AWS::AccountId}-${AWS::Region}"
}
}
Expand Down
Loading

0 comments on commit 4720271

Please sign in to comment.