Skip to content
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
6 changes: 3 additions & 3 deletions .github/workflows/build.yml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

8 changes: 4 additions & 4 deletions .github/workflows/release.yml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion .github/workflows/upgrade-main.yml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

5 changes: 5 additions & 0 deletions .projen/deps.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion .projen/tasks.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

11 changes: 10 additions & 1 deletion .projenrc.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,10 +9,19 @@ const project = new awscdk.AwsCdkConstructLibrary({
name: '@gammarers/aws-codeconnections-host-custom-resource',
projenrcTs: true,
repositoryUrl: 'https://github.com/gammarers/aws-codeconnections-host-custom-resource.git',
// deps: [
// '@gammarers/aws-resource-naming@^0.8.0',
// ],
// devDeps: [
// '@gammarers/[email protected]',
// ],
peerDeps: [
'@gammarers/aws-resource-naming@^0.8.0',
],
releaseToNpm: true,
npmAccess: javascript.NpmAccess.PUBLIC,
minNodeVersion: '18.0.0',
workflowNodeVersion: '22.4.x',
workflowNodeVersion: '22.5.x',
depsUpgradeOptions: {
workflowOptions: {
labels: ['auto-approve', 'auto-merge'],
Expand Down
61 changes: 61 additions & 0 deletions API.md

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 2 additions & 0 deletions package.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

75 changes: 69 additions & 6 deletions src/index.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import * as crypto from 'crypto';
import { ResourceAutoNaming, ResourceDefaultNaming, ResourceNaming, ResourceNamingOptions, ResourceNamingType } from '@gammarers/aws-resource-naming';
import * as cdk from 'aws-cdk-lib';
import * as iam from 'aws-cdk-lib/aws-iam';
import * as cr from 'aws-cdk-lib/custom-resources';
Expand All @@ -17,26 +17,88 @@ export enum ResponseField {
HOST_ARN = 'HostArn',
}

//export type Names = {
// functionName: string;
// functionRoleName: string;
//}
//export interface Names {
// readonly functionName: string;
// readonly functionRoleName: string;
//}
//
//export type CustomNaming = {
// type: ResourceNaming.NamingType.CUSTOM;
// // functionName: string;
// // functionRoleName: string;
// names: Names;
//}

//export interface ResourceNamingOptions {
// readonly naming: ResourceNaming.AutoNaming | ResourceNaming.DefaultNaming | {
// type: ResourceNaming.NamingType.CUSTOM;
// names: {
// functionName: string;
// functionRoleName: string;
// };
// };
//}

//export interface ResourceNamingOptions {
// readonly naming: ResourceNaming.AutoNaming | ResourceNaming.DefaultNaming;
//}
//export type Naming = { type: ResourceNaming.NamingType.DEFAULT } | { type: ResourceNaming.NamingType.AUTO } | CustomNaming;
//export type Naming = { type: ResourceNaming.NamingType.DEFAULT } | { type: ResourceNaming.NamingType.AUTO } | CustomNaming;
//export type Naming = CustomNaming;

//export interface ResourceNamingOptions {
// readonly naming: Naming;
//}
//export interface DefaultNamingOption {
// readonly type: ResourceNaming.NamingType.DEFAULT;
//}
//
//export interface AutoNamingOption {
// readonly type: ResourceNaming.NamingType.AUTO;
//}

export interface CustomNaming {
readonly type: ResourceNamingType.CUSTOM;
// readonly names: Names; // CUSTOM の場合に必須
readonly functionName: string; // フラット化
readonly functionRoleName: string; // フラット化
}

export type ResourceNamingOption = ResourceDefaultNaming | ResourceAutoNaming | CustomNaming;

export interface CodeConnectionsHostCustomResourceProps {
readonly name: string;
readonly providerEndpoint: string;
readonly providerType: CodeConnectionsHostProviderType;
//readonly resouceNamingOption?: ResourceNamingOptions;
// readonly resouceNamingOption?: { type: ResourceNaming.NamingType.DEFAULT } | { type: ResourceNaming.NamingType.AUTO } | CustomNaming;
readonly resouceNamingOption?: ResourceNamingOption;
}

export class CodeConnectionsHostCustomResource extends cr.AwsCustomResource {

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

// 👇 Create random 8 length string
const random: string = crypto.createHash('shake256', { outputLength: 4 })
.update(`${cdk.Names.uniqueId(scope)}.${props.name}.${props.providerEndpoint}.${props.providerType}`)
.digest('hex');
const random = ResourceNaming.createRandomString(`${cdk.Names.uniqueId(scope)}.${props.name}.${props.providerEndpoint}.${props.providerType}`);
const autoNaming = {
functionName: `custom-resource-codeconnection-host-${random}-func`,
functionRoleName: `custom-resource-codeconnection-host-${random}-func-exc-role`,
};
const names = ResourceNaming.naming(autoNaming, props.resouceNamingOption as ResourceNamingOptions);
// const naming = {
// names: autoNaming,
// };

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

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

super(scope, id, {
functionName: `custom-resource-codeconnection-host-${random}-func`,
functionName: names.functionName,
role: functionRole,
timeout: cdk.Duration.seconds(15),
installLatestAwsSdk: true,
//logGroup: todo
onCreate: {
service: 'CodeConnections',
action: 'createHost',
Expand Down
Loading