Skip to content

Commit 562e68f

Browse files
authored
Merge pull request #17 from gammarers/feature/resource-naming
feat: resource naming
2 parents 120be12 + 45c60c7 commit 562e68f

18 files changed

+349
-24
lines changed

.github/workflows/build.yml

Lines changed: 3 additions & 3 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

.github/workflows/release.yml

Lines changed: 4 additions & 4 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

.github/workflows/upgrade-main.yml

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

.projen/deps.json

Lines changed: 5 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

.projen/tasks.json

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

.projenrc.ts

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,10 +9,19 @@ const project = new awscdk.AwsCdkConstructLibrary({
99
name: '@gammarers/aws-codeconnections-host-custom-resource',
1010
projenrcTs: true,
1111
repositoryUrl: 'https://github.com/gammarers/aws-codeconnections-host-custom-resource.git',
12+
// deps: [
13+
// '@gammarers/aws-resource-naming@^0.8.0',
14+
// ],
15+
// devDeps: [
16+
// '@gammarers/[email protected]',
17+
// ],
18+
peerDeps: [
19+
'@gammarers/aws-resource-naming@^0.8.0',
20+
],
1221
releaseToNpm: true,
1322
npmAccess: javascript.NpmAccess.PUBLIC,
1423
minNodeVersion: '18.0.0',
15-
workflowNodeVersion: '22.4.x',
24+
workflowNodeVersion: '22.5.x',
1625
depsUpgradeOptions: {
1726
workflowOptions: {
1827
labels: ['auto-approve', 'auto-merge'],

API.md

Lines changed: 61 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

Lines changed: 2 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

src/index.ts

Lines changed: 69 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import * as crypto from 'crypto';
1+
import { ResourceAutoNaming, ResourceDefaultNaming, ResourceNaming, ResourceNamingOptions, ResourceNamingType } from '@gammarers/aws-resource-naming';
22
import * as cdk from 'aws-cdk-lib';
33
import * as iam from 'aws-cdk-lib/aws-iam';
44
import * as cr from 'aws-cdk-lib/custom-resources';
@@ -17,26 +17,88 @@ export enum ResponseField {
1717
HOST_ARN = 'HostArn',
1818
}
1919

20+
//export type Names = {
21+
// functionName: string;
22+
// functionRoleName: string;
23+
//}
24+
//export interface Names {
25+
// readonly functionName: string;
26+
// readonly functionRoleName: string;
27+
//}
28+
//
29+
//export type CustomNaming = {
30+
// type: ResourceNaming.NamingType.CUSTOM;
31+
// // functionName: string;
32+
// // functionRoleName: string;
33+
// names: Names;
34+
//}
35+
36+
//export interface ResourceNamingOptions {
37+
// readonly naming: ResourceNaming.AutoNaming | ResourceNaming.DefaultNaming | {
38+
// type: ResourceNaming.NamingType.CUSTOM;
39+
// names: {
40+
// functionName: string;
41+
// functionRoleName: string;
42+
// };
43+
// };
44+
//}
45+
46+
//export interface ResourceNamingOptions {
47+
// readonly naming: ResourceNaming.AutoNaming | ResourceNaming.DefaultNaming;
48+
//}
49+
//export type Naming = { type: ResourceNaming.NamingType.DEFAULT } | { type: ResourceNaming.NamingType.AUTO } | CustomNaming;
50+
//export type Naming = { type: ResourceNaming.NamingType.DEFAULT } | { type: ResourceNaming.NamingType.AUTO } | CustomNaming;
51+
//export type Naming = CustomNaming;
52+
53+
//export interface ResourceNamingOptions {
54+
// readonly naming: Naming;
55+
//}
56+
//export interface DefaultNamingOption {
57+
// readonly type: ResourceNaming.NamingType.DEFAULT;
58+
//}
59+
//
60+
//export interface AutoNamingOption {
61+
// readonly type: ResourceNaming.NamingType.AUTO;
62+
//}
63+
64+
export interface CustomNaming {
65+
readonly type: ResourceNamingType.CUSTOM;
66+
// readonly names: Names; // CUSTOM の場合に必須
67+
readonly functionName: string; // フラット化
68+
readonly functionRoleName: string; // フラット化
69+
}
70+
71+
export type ResourceNamingOption = ResourceDefaultNaming | ResourceAutoNaming | CustomNaming;
72+
2073
export interface CodeConnectionsHostCustomResourceProps {
2174
readonly name: string;
2275
readonly providerEndpoint: string;
2376
readonly providerType: CodeConnectionsHostProviderType;
77+
//readonly resouceNamingOption?: ResourceNamingOptions;
78+
// readonly resouceNamingOption?: { type: ResourceNaming.NamingType.DEFAULT } | { type: ResourceNaming.NamingType.AUTO } | CustomNaming;
79+
readonly resouceNamingOption?: ResourceNamingOption;
2480
}
2581

2682
export class CodeConnectionsHostCustomResource extends cr.AwsCustomResource {
2783

2884
constructor(scope: Construct, id: string, props: CodeConnectionsHostCustomResourceProps) {
2985

3086
// 👇 Create random 8 length string
31-
const random: string = crypto.createHash('shake256', { outputLength: 4 })
32-
.update(`${cdk.Names.uniqueId(scope)}.${props.name}.${props.providerEndpoint}.${props.providerType}`)
33-
.digest('hex');
87+
const random = ResourceNaming.createRandomString(`${cdk.Names.uniqueId(scope)}.${props.name}.${props.providerEndpoint}.${props.providerType}`);
88+
const autoNaming = {
89+
functionName: `custom-resource-codeconnection-host-${random}-func`,
90+
functionRoleName: `custom-resource-codeconnection-host-${random}-func-exc-role`,
91+
};
92+
const names = ResourceNaming.naming(autoNaming, props.resouceNamingOption as ResourceNamingOptions);
93+
// const naming = {
94+
// names: autoNaming,
95+
// };
3496

3597
const account = cdk.Stack.of(scope).account;
3698
const region = cdk.Stack.of(scope).region;
3799

38100
const functionRole = new iam.Role(scope, 'FunctionRole', {
39-
roleName: `custom-resource-codeconnection-host-${random}-func-exc-role`,
101+
roleName: names.functionRoleName,
40102
description: 'Custom Resource Function Execution Role.',
41103
assumedBy: new iam.ServicePrincipal('lambda.amazonaws.com'),
42104
managedPolicies: [
@@ -62,10 +124,11 @@ export class CodeConnectionsHostCustomResource extends cr.AwsCustomResource {
62124
});
63125

64126
super(scope, id, {
65-
functionName: `custom-resource-codeconnection-host-${random}-func`,
127+
functionName: names.functionName,
66128
role: functionRole,
67129
timeout: cdk.Duration.seconds(15),
68130
installLatestAwsSdk: true,
131+
//logGroup: todo
69132
onCreate: {
70133
service: 'CodeConnections',
71134
action: 'createHost',

0 commit comments

Comments
 (0)