From eb822fe8df3bb9766f053db5d2e2919aba4e7f07 Mon Sep 17 00:00:00 2001 From: Justinon Date: Wed, 19 Oct 2022 15:48:30 -0700 Subject: [PATCH 01/11] feat(infra): Initial commit [CLK-173516] --- .eslintrc.json | 13 +- .projen/deps.json | 4 + .projen/tasks.json | 4 +- .projenrc.js => .projenrc.ts | 11 +- API.md | 537 +++++++++++++++++++++++++++++++++++ package.json | 9 +- src/NamedEnv.ts | 174 ++++++++++++ src/Shard.ts | 22 ++ src/index.ts | 7 +- test/NamedEnv.test.ts | 87 ++++++ test/hello.test.ts | 5 - tsconfig.dev.json | 4 +- yarn.lock | 5 + 13 files changed, 857 insertions(+), 25 deletions(-) rename .projenrc.js => .projenrc.ts (60%) create mode 100644 API.md create mode 100644 src/NamedEnv.ts create mode 100644 src/Shard.ts create mode 100644 test/NamedEnv.test.ts delete mode 100644 test/hello.test.ts diff --git a/.eslintrc.json b/.eslintrc.json index db33bef..56dd570 100644 --- a/.eslintrc.json +++ b/.eslintrc.json @@ -37,11 +37,13 @@ }, "ignorePatterns": [ "*.js", - "!.projenrc.js", + "!.projenrc.ts", "*.d.ts", "node_modules/", "*.generated.ts", - "coverage" + "coverage", + "!.projenrc.ts", + "!projenrc/**/*.ts" ], "rules": { "prettier/prettier": [ @@ -55,7 +57,10 @@ { "devDependencies": [ "**/test/**", - "**/build-tools/**" + "**/build-tools/**", + "**/projenrc/**", + ".projenrc.ts", + "projenrc/**/*.ts" ], "optionalDependencies": false, "peerDependencies": true @@ -130,7 +135,7 @@ "overrides": [ { "files": [ - ".projenrc.js" + ".projenrc.ts" ], "rules": { "@typescript-eslint/no-require-imports": "off", diff --git a/.projen/deps.json b/.projen/deps.json index 4b1b558..2968c6b 100644 --- a/.projen/deps.json +++ b/.projen/deps.json @@ -138,6 +138,10 @@ "name": "constructs", "version": "^10.0.5", "type": "peer" + }, + { + "name": "multi-convention-namer", + "type": "runtime" } ], "//": "~~ Generated by projen. To modify, edit .projenrc.js and run \"npx projen\"." diff --git a/.projen/tasks.json b/.projen/tasks.json index 6dfb31d..b8648df 100644 --- a/.projen/tasks.json +++ b/.projen/tasks.json @@ -96,7 +96,7 @@ "description": "Synthesize project files", "steps": [ { - "exec": "node .projenrc.js" + "exec": "ts-node --project tsconfig.dev.json .projenrc.ts" } ] }, @@ -126,7 +126,7 @@ "description": "Runs eslint against the codebase", "steps": [ { - "exec": "eslint --ext .ts,.tsx --fix --no-error-on-unmatched-pattern src test build-tools .projenrc.js" + "exec": "eslint --ext .ts,.tsx --fix --no-error-on-unmatched-pattern src test build-tools projenrc .projenrc.ts" } ] }, diff --git a/.projenrc.js b/.projenrc.ts similarity index 60% rename from .projenrc.js rename to .projenrc.ts index b184121..512ea78 100644 --- a/.projenrc.js +++ b/.projenrc.ts @@ -1,14 +1,15 @@ -const { clickupCdk } = require('@time-loop/clickup-projen'); +import { clickupCdk } from '@time-loop/clickup-projen'; const project = new clickupCdk.ClickUpCdkConstructLibrary({ - author: 'Justinon', - authorAddress: 'jglommen@gmail.com', + author: 'ClickUp', + authorAddress: 'devops@clickup.com', cdkVersion: '2.1.0', defaultReleaseBranch: 'main', devDeps: ['@time-loop/clickup-projen'], name: 'cdk-environments', - repositoryUrl: 'https://github.com/jglommen/cdk-environments.git', + repositoryUrl: 'https://github.com/time-loop/cdk-environments.git', + projenrcTs: true, - // deps: [], /* Runtime dependencies of this module. */ + deps: ['multi-convention-namer'], // description: undefined, /* The description is just a string that helps people understand the purpose of the package. */ // packageName: undefined, /* The "name" in package.json. */ }); diff --git a/API.md b/API.md new file mode 100644 index 0000000..3962f16 --- /dev/null +++ b/API.md @@ -0,0 +1,537 @@ +# API Reference + + +## Structs + +### NamedEnv + +#### Initializer + +```typescript +import { environments } from '@time-loop/cdk-environments' + +const namedEnv: environments.NamedEnv = { ... } +``` + +#### Properties + +| **Name** | **Type** | **Description** | +| --- | --- | --- | +| account | string | The AWS account ID for this environment. | +| region | string | The AWS region for this environment. | +| asn | number | The asn to be used for TransitGateways. | +| attachmentZoneName | string | The DNS zone for attachments. | +| cidr | string | Currently the vpc cidr for the region. | +| defaultRegion | string | If a region isn't specified, where should we default to. | +| name | string | The kebab-name of the environment. | +| organizationalUnit | string | What kind of an account is this? | +| regionDetails | {[ key: string ]: @time-loop/cdk-environments.environments.RegionalDetails} | CIDR details for all regions. | +| shard | IShard | The shard for clickup. | +| shortRegion | string | The ClickUp shorthand for the region. | +| zoneName | string | The DNS zone into which services should be deployed. | +| ssoRegion | string | In which region does SSO live in? | +| ssoStartUrl | string | Is this an SSO accessible account? | + +--- + +##### `account`Optional + +```typescript +public readonly account: string; +``` + +- *Type:* string +- *Default:* Aws.accountId which means that the stack will be account-agnostic. + +The AWS account ID for this environment. + +This can be either a concrete value such as `585191031104` or `Aws.accountId` which +indicates that account ID will only be determined during deployment (it +will resolve to the CloudFormation intrinsic `{"Ref":"AWS::AccountId"}`). +Note that certain features, such as cross-stack references and +environmental context providers require concerete region information and +will cause this stack to emit synthesis errors. + +--- + +##### `region`Optional + +```typescript +public readonly region: string; +``` + +- *Type:* string +- *Default:* Aws.region which means that the stack will be region-agnostic. + +The AWS region for this environment. + +This can be either a concrete value such as `eu-west-2` or `Aws.region` +which indicates that account ID will only be determined during deployment +(it will resolve to the CloudFormation intrinsic `{"Ref":"AWS::Region"}`). +Note that certain features, such as cross-stack references and +environmental context providers require concerete region information and +will cause this stack to emit synthesis errors. + +--- + +##### ~~`asn`~~Required + +- *Deprecated:* we aren't using tgw (maybe at the regional level for shard support though) + +```typescript +public readonly asn: number; +``` + +- *Type:* number + +The asn to be used for TransitGateways. + +--- + +##### `attachmentZoneName`Required + +```typescript +public readonly attachmentZoneName: string; +``` + +- *Type:* string + +The DNS zone for attachments. + +--- + +##### ~~`cidr`~~Required + +- *Deprecated:* you probably want the shard specific cidrs + +```typescript +public readonly cidr: string; +``` + +- *Type:* string + +Currently the vpc cidr for the region. + +--- + +##### `defaultRegion`Required + +```typescript +public readonly defaultRegion: string; +``` + +- *Type:* string + +If a region isn't specified, where should we default to. + +Mostly used by `click aws-config`. +Also considered for centralized resources. + +--- + +##### `name`Required + +```typescript +public readonly name: string; +``` + +- *Type:* string + +The kebab-name of the environment. + +--- + +##### `organizationalUnit`Required + +```typescript +public readonly organizationalUnit: string; +``` + +- *Type:* string + +What kind of an account is this? + +--- + +##### `regionDetails`Required + +```typescript +public readonly regionDetails: {[ key: string ]: RegionalDetails}; +``` + +- *Type:* {[ key: string ]: @time-loop/cdk-environments.environments.RegionalDetails} + +CIDR details for all regions. + +--- + +##### `shard`Required + +```typescript +public readonly shard: IShard; +``` + +- *Type:* IShard + +The shard for clickup. + +--- + +##### ~~`shortRegion`~~Required + +- *Deprecated:* use shard.name + +```typescript +public readonly shortRegion: string; +``` + +- *Type:* string + +The ClickUp shorthand for the region. + +--- + +##### `zoneName`Required + +```typescript +public readonly zoneName: string; +``` + +- *Type:* string + +The DNS zone into which services should be deployed. + +--- + +##### `ssoRegion`Optional + +```typescript +public readonly ssoRegion: string; +``` + +- *Type:* string + +In which region does SSO live in? + +--- + +##### `ssoStartUrl`Optional + +```typescript +public readonly ssoStartUrl: string; +``` + +- *Type:* string + +Is this an SSO accessible account? + +If so, what's the start url? + +--- + +### NamedEnvFactory + +#### Initializer + +```typescript +import { environments } from '@time-loop/cdk-environments' + +const namedEnvFactory: environments.NamedEnvFactory = { ... } +``` + +#### Properties + +| **Name** | **Type** | **Description** | +| --- | --- | --- | +| environmentName | string | *No description.* | +| regionDetails | {[ key: string ]: @time-loop/cdk-environments.environments.RegionalDetails} | *No description.* | + +--- + +##### `environmentName`Required + +```typescript +public readonly environmentName: string; +``` + +- *Type:* string + +--- + +##### `regionDetails`Required + +```typescript +public readonly regionDetails: {[ key: string ]: RegionalDetails}; +``` + +- *Type:* {[ key: string ]: @time-loop/cdk-environments.environments.RegionalDetails} + +--- + +### NamedEnvironmentProps + +Used by newNamedEnvFactory. + +Is it used elsewhere? + +#### Initializer + +```typescript +import { environments } from '@time-loop/cdk-environments' + +const namedEnvironmentProps: environments.NamedEnvironmentProps = { ... } +``` + +#### Properties + +| **Name** | **Type** | **Description** | +| --- | --- | --- | +| account | string | The numeric account id as used by cdk.Environment.account. | +| attachmentZoneName | string | The DNS zone for attachments. | +| defaultRegion | string | If a region isn't specified, where should we default to. | +| name | string | The proper name of the environment in kebab-format. | +| organizationalUnit | string | What kind of an account is this? | +| regionDetails | {[ key: string ]: @time-loop/cdk-environments.environments.RegionalDetails} | A map of region => { asn, cidr }. | +| zoneName | string | The name of the route53 zone for this account. | +| ssoRegion | string | In which region does SSO live in? | +| ssoStartUrl | string | Is this an SSO accessible account? | + +--- + +##### `account`Required + +```typescript +public readonly account: string; +``` + +- *Type:* string + +The numeric account id as used by cdk.Environment.account. + +--- + +##### `attachmentZoneName`Required + +```typescript +public readonly attachmentZoneName: string; +``` + +- *Type:* string + +The DNS zone for attachments. + +--- + +##### `defaultRegion`Required + +```typescript +public readonly defaultRegion: string; +``` + +- *Type:* string + +If a region isn't specified, where should we default to. + +Mostly used by `click aws-config`. +Also considered for centralized resources. + +--- + +##### `name`Required + +```typescript +public readonly name: string; +``` + +- *Type:* string + +The proper name of the environment in kebab-format. + +--- + +##### `organizationalUnit`Required + +```typescript +public readonly organizationalUnit: string; +``` + +- *Type:* string + +What kind of an account is this? + +--- + +##### `regionDetails`Required + +```typescript +public readonly regionDetails: {[ key: string ]: RegionalDetails}; +``` + +- *Type:* {[ key: string ]: @time-loop/cdk-environments.environments.RegionalDetails} + +A map of region => { asn, cidr }. + +--- + +##### `zoneName`Required + +```typescript +public readonly zoneName: string; +``` + +- *Type:* string + +The name of the route53 zone for this account. + +--- + +##### `ssoRegion`Optional + +```typescript +public readonly ssoRegion: string; +``` + +- *Type:* string + +In which region does SSO live in? + +--- + +##### `ssoStartUrl`Optional + +```typescript +public readonly ssoStartUrl: string; +``` + +- *Type:* string + +Is this an SSO accessible account? + +If so, what's the start url? + +--- + +### RegionalDetails + +#### Initializer + +```typescript +import { environments } from '@time-loop/cdk-environments' + +const regionalDetails: environments.RegionalDetails = { ... } +``` + +#### Properties + +| **Name** | **Type** | **Description** | +| --- | --- | --- | +| asn | number | *No description.* | +| cidr | string | *No description.* | + +--- + +##### `asn`Required + +```typescript +public readonly asn: number; +``` + +- *Type:* number + +--- + +##### ~~`cidr`~~Required + +- *Deprecated:* you should probably be using the shard's cidr. + +```typescript +public readonly cidr: string; +``` + +- *Type:* string + +--- + + +## Protocols + +### IShard + +- *Implemented By:* IShard + +#### Methods + +| **Name** | **Description** | +| --- | --- | +| toString | *No description.* | + +--- + +##### `toString` + +```typescript +public toString(): string +``` + +#### Properties + +| **Name** | **Type** | **Description** | +| --- | --- | --- | +| cidr | string | The cidr for a shard's vpc. | +| name | string | The proper name for a shard (without numeric suffix). | +| number | number | The shard-number within the region. | +| region | string | The AWS region for a shard. | + +--- + +##### `cidr`Required + +```typescript +public readonly cidr: string; +``` + +- *Type:* string + +The cidr for a shard's vpc. + +Regions typically receive a 10.?.0.0/12 address space, +within which there are 16 /16 subnets for shards. + +--- + +##### `name`Required + +```typescript +public readonly name: string; +``` + +- *Type:* string + +The proper name for a shard (without numeric suffix). + +--- + +##### `number`Required + +```typescript +public readonly number: number; +``` + +- *Type:* number + +The shard-number within the region. + +--- + +##### `region`Required + +```typescript +public readonly region: string; +``` + +- *Type:* string + +The AWS region for a shard. + +--- + diff --git a/package.json b/package.json index ba6a335..7dead57 100644 --- a/package.json +++ b/package.json @@ -2,7 +2,7 @@ "name": "@time-loop/cdk-environments", "repository": { "type": "git", - "url": "https://github.com/jglommen/cdk-environments.git" + "url": "https://github.com/time-loop/cdk-environments.git" }, "scripts": { "build": "npx projen build", @@ -30,8 +30,8 @@ "projen": "npx projen" }, "author": { - "name": "Justinon", - "email": "jglommen@gmail.com", + "name": "ClickUp", + "email": "devops@clickup.com", "organization": true }, "devDependencies": { @@ -69,6 +69,9 @@ "aws-cdk-lib": "^2.1.0", "constructs": "^10.0.5" }, + "dependencies": { + "multi-convention-namer": "^0.1.12" + }, "keywords": [ "cdk" ], diff --git a/src/NamedEnv.ts b/src/NamedEnv.ts new file mode 100644 index 0000000..c34b638 --- /dev/null +++ b/src/NamedEnv.ts @@ -0,0 +1,174 @@ +import { Environment } from 'aws-cdk-lib'; +import { IShard } from './Shard'; + +export module environments { + export interface RegionalDetails { + readonly asn: number; + /** + * @deprecated you should probably be using the shard's cidr. + */ + readonly cidr: string; // in '0.0.0.0/32' format + } + + export interface NamedEnv extends Environment { + /** + * The asn to be used for TransitGateways + * @deprecated we aren't using tgw (maybe at the regional level for shard support though) + */ + readonly asn: number; + /** + * Currently the vpc cidr for the region. + * @deprecated you probably want the shard specific cidrs + */ + readonly cidr: string; + /** + * The shard for clickup. + */ + readonly shard: IShard; + /** + * If a region isn't specified, where should we default to. + * Mostly used by `click aws-config`. + * Also considered for centralized resources. + */ + readonly defaultRegion: string; + /** + * The kebab-name of the environment. + */ + readonly name: string; + /** + * What kind of an account is this? + */ + readonly organizationalUnit: string; + /** + * CIDR details for all regions. + */ + readonly regionDetails: Record; + /** + * The ClickUp shorthand for the region. + * + * @deprecated use shard.name + */ + readonly shortRegion: string; + /** + * In which region does SSO live in? + */ + readonly ssoRegion?: string; + /** + * Is this an SSO accessible account? If so, what's the start url? + */ + readonly ssoStartUrl?: string; + /** + * The DNS zone into which services should be deployed. + */ + readonly zoneName: string; + /** + * The DNS zone for attachments + */ + readonly attachmentZoneName: string; + } + + /** + * Used by newNamedEnvFactory. Is it used elsewhere? + */ + export interface NamedEnvironmentProps { + /** + * The numeric account id as used by cdk.Environment.account + */ + readonly account: string; + /** + * Mapping of regions to CIDR bases. + * Only override if you need to have subnets from one account not over-lapping subnets from another. + * This is an anti-pattern and we should avoid it where possible. + * + * @default - see belos + * { + * 'ap-northeast-2': '10.0.0.0/12', + * 'ap-south-1': '10.16.0.0/12', + * 'ap-southeast-2': '10.32.0.0/12', + * 'eu-central-1': '10.48.0.0/12' , + * 'eu-west-1': '10.64.0.0/12', + * 'sa-east-1': '10.80.0.0/12', + * 'us-east-1': '10.96.0.0/12', + * 'us-east-2': '10.112.0.0/12', + * 'us-west-1': '10.128.0.0/12', + * 'us-west-2': '10.144.0.0/12', + * }, + */ + /** + * If a region isn't specified, where should we default to. + * Mostly used by `click aws-config`. + * Also considered for centralized resources. + */ + readonly defaultRegion: string; + /** + * A map of region => { asn, cidr } + */ + readonly regionDetails: Record; + /** + * The proper name of the environment in kebab-format. + */ + readonly name: string; + /** + * What kind of an account is this? + */ + readonly organizationalUnit: string; + /** + * In which region does SSO live in? + */ + readonly ssoRegion?: string; + /** + * Is this an SSO accessible account? If so, what's the start url? + */ + readonly ssoStartUrl?: string; + /** + * The name of the route53 zone for this account. + */ + readonly zoneName: string; + /** + * The DNS zone for attachments + */ + readonly attachmentZoneName: string; + } + + export interface NamedEnvFactory { + // TODO: should we add shardDetails here? + readonly environmentName: string; + readonly regionDetails: Record; + (shard: IShard, overrideAsn?: number): NamedEnv; + } + + /** + * Generates a function which creates a NamedEnv when given a region + * @param props + * @returns NamedEnv + */ + export function newNamedEnvFactory(props: NamedEnvironmentProps): NamedEnvFactory { + if ((props.ssoStartUrl || props.ssoRegion) && !(props.ssoStartUrl && props.ssoRegion)) { + console.warn( + `Something is wrong for ${props.name}: ssoStartUrl = ${JSON.stringify(props.ssoStartUrl)} and ssoRegion = ${ + props.ssoRegion + }, but either both or neither of these should be set.`, + ); + } + + const namedEnvFactory = function (shard: IShard, asnOverride?: number): NamedEnv { + const region = shard.region; + const regionDetails = props.regionDetails[region]; + const asn = asnOverride || regionDetails?.asn || -1; + const cidr = shard.cidr; + const shortRegion = shard.name; + + return { + ...props, + asn, + shard, + cidr, + region, + shortRegion, + }; + }; + namedEnvFactory.environmentName = props.name; + namedEnvFactory.regionDetails = props.regionDetails; + return namedEnvFactory; + } +} diff --git a/src/Shard.ts b/src/Shard.ts new file mode 100644 index 0000000..07d28c5 --- /dev/null +++ b/src/Shard.ts @@ -0,0 +1,22 @@ +export interface IShard { + /** + * The cidr for a shard's vpc. + * Regions typically receive a 10.?.0.0/12 address space, + * within which there are 16 /16 subnets for shards. + */ + readonly cidr: string; + /** + * The AWS region for a shard. + */ + readonly region: string; + /** + * The proper name for a shard (without numeric suffix). + */ + readonly name: string; + /** + * The shard-number within the region. + */ + readonly number: number; + + toString(): string; +} diff --git a/src/index.ts b/src/index.ts index fb2fabc..a5874d1 100644 --- a/src/index.ts +++ b/src/index.ts @@ -1,5 +1,2 @@ -export class Hello { - public sayHello() { - return 'hello, world!'; - } -} +export * from './NamedEnv'; +export * from './Shard'; diff --git a/test/NamedEnv.test.ts b/test/NamedEnv.test.ts new file mode 100644 index 0000000..fb24a90 --- /dev/null +++ b/test/NamedEnv.test.ts @@ -0,0 +1,87 @@ +import 'process'; +import { IShard } from '../src'; +import { environments } from '../src/NamedEnv'; + +enum TestOrganizationalUnit { + Test = 'dev', +} + +let fakeEnvProps: environments.NamedEnvironmentProps; + +describe('NamedEnv', () => { + describe('functionality', () => { + beforeEach(() => { + fakeEnvProps = { + name: 'sandbox', + account: 'fakeAccount', + defaultRegion: 'fakeRegion', + zoneName: 'fake.com', + attachmentZoneName: 'fakeAttachment.com', + regionDetails: {}, + organizationalUnit: TestOrganizationalUnit.Test, + }; + }); + + it('warns when has ssoStartUrl, but not ssoRegion', () => { + const fakeWarn = jest.spyOn(global.console, 'warn').mockImplementation(() => {}); + environments.newNamedEnvFactory({ ...fakeEnvProps, ssoStartUrl: 'fakeStartUrl' }); + expect(fakeWarn).toHaveBeenCalledTimes(1); + expect(fakeWarn).toHaveBeenCalledWith( + 'Something is wrong for sandbox: ssoStartUrl = "fakeStartUrl" and ssoRegion = undefined, but either both or neither of these should be set.', + ); + }); + it('throws when has ssoRegion, but not ssoStartUrl', () => { + const fakeWarn = jest.spyOn(global.console, 'warn').mockImplementation(() => {}); + environments.newNamedEnvFactory({ ...fakeEnvProps, ssoRegion: 'fakeSsoRegion' }); + expect(fakeWarn).toHaveBeenCalledTimes(1); + expect(fakeWarn).toHaveBeenCalledWith( + 'Something is wrong for sandbox: ssoStartUrl = undefined and ssoRegion = fakeSsoRegion, but either both or neither of these should be set.', + ); + }); + describe('namedEnvFactory', () => { + let shard: IShard; + let factory: environments.NamedEnvFactory; + beforeEach(() => { + fakeEnvProps = { + name: 'sandbox', + account: 'fakeAccount', + defaultRegion: 'fakeRegion', + zoneName: 'fake.com', + attachmentZoneName: 'fakeAttachment.com', + regionDetails: {}, + organizationalUnit: TestOrganizationalUnit.Test, + }; + + shard = { + cidr: '10.0.0.0/0', + region: 'us-west-2', + name: 'TestShard', + number: 1, + }; + factory = environments.newNamedEnvFactory(fakeEnvProps); + }); + + it('has default ASN', () => { + const namedEnv = factory(shard); + expect(namedEnv.asn).toBe(-1); + }); + it('respects overrideAsn', () => { + const namedEnv = factory(shard, 666); // 😈 + expect(namedEnv.asn).toBe(666); + }); + it('can pull ASN from regionDetails', () => { + factory = environments.newNamedEnvFactory({ + ...fakeEnvProps, + regionDetails: { + 'us-west-2': { + asn: 10, + cidr: '10.0.0.0/32', + }, + }, + }); + const namedEnv = factory(shard); + expect(namedEnv.asn).toBe(10); + }); + }); + }); +}); diff --git a/test/hello.test.ts b/test/hello.test.ts deleted file mode 100644 index 88b4d93..0000000 --- a/test/hello.test.ts +++ /dev/null @@ -1,5 +0,0 @@ -import { Hello } from '../src'; - -test('hello', () => { - expect(new Hello().sayHello()).toBe('hello, world!'); -}); diff --git a/tsconfig.dev.json b/tsconfig.dev.json index 2e29dba..24ccaa6 100644 --- a/tsconfig.dev.json +++ b/tsconfig.dev.json @@ -27,7 +27,9 @@ "include": [ ".projenrc.js", "src/**/*.ts", - "test/**/*.ts" + "test/**/*.ts", + ".projenrc.ts", + "projenrc/**/*.ts" ], "exclude": [ "node_modules" diff --git a/yarn.lock b/yarn.lock index 94d0dbc..51c1b9d 100644 --- a/yarn.lock +++ b/yarn.lock @@ -4688,6 +4688,11 @@ ms@^2.0.0, ms@^2.1.1: resolved "https://registry.yarnpkg.com/ms/-/ms-2.1.3.tgz#574c8138ce1d2b5861f0b44579dbadd60c6615b2" integrity sha512-6FlzubTLZG3J2a/NVCAleEhjzq5oxgHyaCU9yYXvcLsvoVaHJq/s5xXI6/XXP6tz7R9xAOtHnSO/tXtF3WRTlA== +multi-convention-namer@^0.1.12: + version "0.1.12" + resolved "https://registry.yarnpkg.com/multi-convention-namer/-/multi-convention-namer-0.1.12.tgz#386aa3194a82c91c968ca727a6d83a9f6bb13caa" + integrity sha512-yNE7N3vGfLL/2atbDdtNkI3HvVc40QNBPqSzYLDFr8nQwEpehZL6AKYAyQ0rQPvJr53eb3t0/Ke43YK/PJoYvw== + natural-compare@^1.4.0: version "1.4.0" resolved "https://registry.yarnpkg.com/natural-compare/-/natural-compare-1.4.0.tgz#4abebfeed7541f2c27acfb29bdbbd15c8d5ba4f7" From 636268c80b5b37507bc2f2d25c9cfbed667283d0 Mon Sep 17 00:00:00 2001 From: Justinon Date: Wed, 19 Oct 2022 15:57:05 -0700 Subject: [PATCH 02/11] chore(infra): Remove references to clickup [CLK-173516] --- src/NamedEnv.ts | 6 ++---- 1 file changed, 2 insertions(+), 4 deletions(-) diff --git a/src/NamedEnv.ts b/src/NamedEnv.ts index c34b638..e9330a9 100644 --- a/src/NamedEnv.ts +++ b/src/NamedEnv.ts @@ -22,12 +22,11 @@ export module environments { */ readonly cidr: string; /** - * The shard for clickup. + * The shard within a region. */ readonly shard: IShard; /** * If a region isn't specified, where should we default to. - * Mostly used by `click aws-config`. * Also considered for centralized resources. */ readonly defaultRegion: string; @@ -44,7 +43,7 @@ export module environments { */ readonly regionDetails: Record; /** - * The ClickUp shorthand for the region. + * The shorthand for the region. * * @deprecated use shard.name */ @@ -96,7 +95,6 @@ export module environments { */ /** * If a region isn't specified, where should we default to. - * Mostly used by `click aws-config`. * Also considered for centralized resources. */ readonly defaultRegion: string; From 5f6ac04b51edccd55f70058d7e77fc13c865e54c Mon Sep 17 00:00:00 2001 From: github-actions Date: Wed, 19 Oct 2022 22:59:04 +0000 Subject: [PATCH 03/11] chore: self mutation Signed-off-by: github-actions --- API.md | 10 ++++------ 1 file changed, 4 insertions(+), 6 deletions(-) diff --git a/API.md b/API.md index 3962f16..c96f67d 100644 --- a/API.md +++ b/API.md @@ -26,8 +26,8 @@ const namedEnv: environments.NamedEnv = { ... } | name | string | The kebab-name of the environment. | | organizationalUnit | string | What kind of an account is this? | | regionDetails | {[ key: string ]: @time-loop/cdk-environments.environments.RegionalDetails} | CIDR details for all regions. | -| shard | IShard | The shard for clickup. | -| shortRegion | string | The ClickUp shorthand for the region. | +| shard | IShard | The shard within a region. | +| shortRegion | string | The shorthand for the region. | | zoneName | string | The DNS zone into which services should be deployed. | | ssoRegion | string | In which region does SSO live in? | | ssoStartUrl | string | Is this an SSO accessible account? | @@ -124,7 +124,6 @@ public readonly defaultRegion: string; If a region isn't specified, where should we default to. -Mostly used by `click aws-config`. Also considered for centralized resources. --- @@ -173,7 +172,7 @@ public readonly shard: IShard; - *Type:* IShard -The shard for clickup. +The shard within a region. --- @@ -187,7 +186,7 @@ public readonly shortRegion: string; - *Type:* string -The ClickUp shorthand for the region. +The shorthand for the region. --- @@ -332,7 +331,6 @@ public readonly defaultRegion: string; If a region isn't specified, where should we default to. -Mostly used by `click aws-config`. Also considered for centralized resources. --- From 78658e6a1d44b5d7e15d1eea554a6dfd63211bc9 Mon Sep 17 00:00:00 2001 From: Justinon Date: Wed, 19 Oct 2022 16:00:27 -0700 Subject: [PATCH 04/11] chore(infra): Remove unused dependency [CLK-173516] --- .projen/deps.json | 4 ---- .projenrc.ts | 2 +- package.json | 3 --- yarn.lock | 5 ----- 4 files changed, 1 insertion(+), 13 deletions(-) diff --git a/.projen/deps.json b/.projen/deps.json index 2968c6b..4b1b558 100644 --- a/.projen/deps.json +++ b/.projen/deps.json @@ -138,10 +138,6 @@ "name": "constructs", "version": "^10.0.5", "type": "peer" - }, - { - "name": "multi-convention-namer", - "type": "runtime" } ], "//": "~~ Generated by projen. To modify, edit .projenrc.js and run \"npx projen\"." diff --git a/.projenrc.ts b/.projenrc.ts index 512ea78..ea45b11 100644 --- a/.projenrc.ts +++ b/.projenrc.ts @@ -9,7 +9,7 @@ const project = new clickupCdk.ClickUpCdkConstructLibrary({ repositoryUrl: 'https://github.com/time-loop/cdk-environments.git', projenrcTs: true, - deps: ['multi-convention-namer'], + // deps: [], // description: undefined, /* The description is just a string that helps people understand the purpose of the package. */ // packageName: undefined, /* The "name" in package.json. */ }); diff --git a/package.json b/package.json index 7dead57..7c58bc6 100644 --- a/package.json +++ b/package.json @@ -69,9 +69,6 @@ "aws-cdk-lib": "^2.1.0", "constructs": "^10.0.5" }, - "dependencies": { - "multi-convention-namer": "^0.1.12" - }, "keywords": [ "cdk" ], diff --git a/yarn.lock b/yarn.lock index 51c1b9d..94d0dbc 100644 --- a/yarn.lock +++ b/yarn.lock @@ -4688,11 +4688,6 @@ ms@^2.0.0, ms@^2.1.1: resolved "https://registry.yarnpkg.com/ms/-/ms-2.1.3.tgz#574c8138ce1d2b5861f0b44579dbadd60c6615b2" integrity sha512-6FlzubTLZG3J2a/NVCAleEhjzq5oxgHyaCU9yYXvcLsvoVaHJq/s5xXI6/XXP6tz7R9xAOtHnSO/tXtF3WRTlA== -multi-convention-namer@^0.1.12: - version "0.1.12" - resolved "https://registry.yarnpkg.com/multi-convention-namer/-/multi-convention-namer-0.1.12.tgz#386aa3194a82c91c968ca727a6d83a9f6bb13caa" - integrity sha512-yNE7N3vGfLL/2atbDdtNkI3HvVc40QNBPqSzYLDFr8nQwEpehZL6AKYAyQ0rQPvJr53eb3t0/Ke43YK/PJoYvw== - natural-compare@^1.4.0: version "1.4.0" resolved "https://registry.yarnpkg.com/natural-compare/-/natural-compare-1.4.0.tgz#4abebfeed7541f2c27acfb29bdbbd15c8d5ba4f7" From 1cf5005a65d31d3ec62c762fc58818958f493fa8 Mon Sep 17 00:00:00 2001 From: Justinon Date: Mon, 24 Oct 2022 09:53:20 -0700 Subject: [PATCH 05/11] chore(infra): Repo name change [CLK-173516] --- .github/workflows/release.yml | 6 +++--- .projenrc.ts | 4 ++-- package.json | 4 ++-- 3 files changed, 7 insertions(+), 7 deletions(-) diff --git a/.github/workflows/release.yml b/.github/workflows/release.yml index cd4aec9..c2e42ef 100644 --- a/.github/workflows/release.yml +++ b/.github/workflows/release.yml @@ -134,7 +134,7 @@ jobs: with: datadog_api_key: ${{ secrets.DD_PROJEN_RELEASE_API_KEY }} datadog_us: true - event_title: Released @time-loop/cdk-environments version ${{ steps.event_metadata.outputs.release_tag }} - event_text: Released @time-loop/cdk-environments version ${{ steps.event_metadata.outputs.release_tag }} + event_title: Released @time-loop/cdk-named-environments version ${{ steps.event_metadata.outputs.release_tag }} + event_text: Released @time-loop/cdk-named-environments version ${{ steps.event_metadata.outputs.release_tag }} event_priority: normal - event_tags: "['project:@time-loop/cdk-environments','release:true','version:${{ steps.event_metadata.outputs.release_tag }}','actor:${{ github.actor }}']" + event_tags: "['project:@time-loop/cdk-named-environments','release:true','version:${{ steps.event_metadata.outputs.release_tag }}','actor:${{ github.actor }}']" diff --git a/.projenrc.ts b/.projenrc.ts index ea45b11..6026974 100644 --- a/.projenrc.ts +++ b/.projenrc.ts @@ -5,8 +5,8 @@ const project = new clickupCdk.ClickUpCdkConstructLibrary({ cdkVersion: '2.1.0', defaultReleaseBranch: 'main', devDeps: ['@time-loop/clickup-projen'], - name: 'cdk-environments', - repositoryUrl: 'https://github.com/time-loop/cdk-environments.git', + name: 'cdk-named-environments', + repositoryUrl: 'https://github.com/time-loop/cdk-named-environments.git', projenrcTs: true, // deps: [], diff --git a/package.json b/package.json index 7c58bc6..4935669 100644 --- a/package.json +++ b/package.json @@ -1,8 +1,8 @@ { - "name": "@time-loop/cdk-environments", + "name": "@time-loop/cdk-named-environments", "repository": { "type": "git", - "url": "https://github.com/time-loop/cdk-environments.git" + "url": "https://github.com/time-loop/cdk-named-environments.git" }, "scripts": { "build": "npx projen build", From 429b42791fde82d2b245cb27a862184efca7e7f7 Mon Sep 17 00:00:00 2001 From: github-actions Date: Mon, 24 Oct 2022 16:55:23 +0000 Subject: [PATCH 06/11] chore: self mutation Signed-off-by: github-actions --- API.md | 164 ++++++++++++++++++++++++++++----------------------------- 1 file changed, 82 insertions(+), 82 deletions(-) diff --git a/API.md b/API.md index c96f67d..081aa0e 100644 --- a/API.md +++ b/API.md @@ -3,12 +3,12 @@ ## Structs -### NamedEnv +### NamedEnv -#### Initializer +#### Initializer ```typescript -import { environments } from '@time-loop/cdk-environments' +import { environments } from '@time-loop/cdk-named-environments' const namedEnv: environments.NamedEnv = { ... } ``` @@ -17,24 +17,24 @@ const namedEnv: environments.NamedEnv = { ... } | **Name** | **Type** | **Description** | | --- | --- | --- | -| account | string | The AWS account ID for this environment. | -| region | string | The AWS region for this environment. | -| asn | number | The asn to be used for TransitGateways. | -| attachmentZoneName | string | The DNS zone for attachments. | -| cidr | string | Currently the vpc cidr for the region. | -| defaultRegion | string | If a region isn't specified, where should we default to. | -| name | string | The kebab-name of the environment. | -| organizationalUnit | string | What kind of an account is this? | -| regionDetails | {[ key: string ]: @time-loop/cdk-environments.environments.RegionalDetails} | CIDR details for all regions. | -| shard | IShard | The shard within a region. | -| shortRegion | string | The shorthand for the region. | -| zoneName | string | The DNS zone into which services should be deployed. | -| ssoRegion | string | In which region does SSO live in? | -| ssoStartUrl | string | Is this an SSO accessible account? | +| account | string | The AWS account ID for this environment. | +| region | string | The AWS region for this environment. | +| asn | number | The asn to be used for TransitGateways. | +| attachmentZoneName | string | The DNS zone for attachments. | +| cidr | string | Currently the vpc cidr for the region. | +| defaultRegion | string | If a region isn't specified, where should we default to. | +| name | string | The kebab-name of the environment. | +| organizationalUnit | string | What kind of an account is this? | +| regionDetails | {[ key: string ]: @time-loop/cdk-named-environments.environments.RegionalDetails} | CIDR details for all regions. | +| shard | IShard | The shard within a region. | +| shortRegion | string | The shorthand for the region. | +| zoneName | string | The DNS zone into which services should be deployed. | +| ssoRegion | string | In which region does SSO live in? | +| ssoStartUrl | string | Is this an SSO accessible account? | --- -##### `account`Optional +##### `account`Optional ```typescript public readonly account: string; @@ -54,7 +54,7 @@ will cause this stack to emit synthesis errors. --- -##### `region`Optional +##### `region`Optional ```typescript public readonly region: string; @@ -74,7 +74,7 @@ will cause this stack to emit synthesis errors. --- -##### ~~`asn`~~Required +##### ~~`asn`~~Required - *Deprecated:* we aren't using tgw (maybe at the regional level for shard support though) @@ -88,7 +88,7 @@ The asn to be used for TransitGateways. --- -##### `attachmentZoneName`Required +##### `attachmentZoneName`Required ```typescript public readonly attachmentZoneName: string; @@ -100,7 +100,7 @@ The DNS zone for attachments. --- -##### ~~`cidr`~~Required +##### ~~`cidr`~~Required - *Deprecated:* you probably want the shard specific cidrs @@ -114,7 +114,7 @@ Currently the vpc cidr for the region. --- -##### `defaultRegion`Required +##### `defaultRegion`Required ```typescript public readonly defaultRegion: string; @@ -128,7 +128,7 @@ Also considered for centralized resources. --- -##### `name`Required +##### `name`Required ```typescript public readonly name: string; @@ -140,7 +140,7 @@ The kebab-name of the environment. --- -##### `organizationalUnit`Required +##### `organizationalUnit`Required ```typescript public readonly organizationalUnit: string; @@ -152,31 +152,31 @@ What kind of an account is this? --- -##### `regionDetails`Required +##### `regionDetails`Required ```typescript public readonly regionDetails: {[ key: string ]: RegionalDetails}; ``` -- *Type:* {[ key: string ]: @time-loop/cdk-environments.environments.RegionalDetails} +- *Type:* {[ key: string ]: @time-loop/cdk-named-environments.environments.RegionalDetails} CIDR details for all regions. --- -##### `shard`Required +##### `shard`Required ```typescript public readonly shard: IShard; ``` -- *Type:* IShard +- *Type:* IShard The shard within a region. --- -##### ~~`shortRegion`~~Required +##### ~~`shortRegion`~~Required - *Deprecated:* use shard.name @@ -190,7 +190,7 @@ The shorthand for the region. --- -##### `zoneName`Required +##### `zoneName`Required ```typescript public readonly zoneName: string; @@ -202,7 +202,7 @@ The DNS zone into which services should be deployed. --- -##### `ssoRegion`Optional +##### `ssoRegion`Optional ```typescript public readonly ssoRegion: string; @@ -214,7 +214,7 @@ In which region does SSO live in? --- -##### `ssoStartUrl`Optional +##### `ssoStartUrl`Optional ```typescript public readonly ssoStartUrl: string; @@ -228,12 +228,12 @@ If so, what's the start url? --- -### NamedEnvFactory +### NamedEnvFactory -#### Initializer +#### Initializer ```typescript -import { environments } from '@time-loop/cdk-environments' +import { environments } from '@time-loop/cdk-named-environments' const namedEnvFactory: environments.NamedEnvFactory = { ... } ``` @@ -242,12 +242,12 @@ const namedEnvFactory: environments.NamedEnvFactory = { ... } | **Name** | **Type** | **Description** | | --- | --- | --- | -| environmentName | string | *No description.* | -| regionDetails | {[ key: string ]: @time-loop/cdk-environments.environments.RegionalDetails} | *No description.* | +| environmentName | string | *No description.* | +| regionDetails | {[ key: string ]: @time-loop/cdk-named-environments.environments.RegionalDetails} | *No description.* | --- -##### `environmentName`Required +##### `environmentName`Required ```typescript public readonly environmentName: string; @@ -257,26 +257,26 @@ public readonly environmentName: string; --- -##### `regionDetails`Required +##### `regionDetails`Required ```typescript public readonly regionDetails: {[ key: string ]: RegionalDetails}; ``` -- *Type:* {[ key: string ]: @time-loop/cdk-environments.environments.RegionalDetails} +- *Type:* {[ key: string ]: @time-loop/cdk-named-environments.environments.RegionalDetails} --- -### NamedEnvironmentProps +### NamedEnvironmentProps Used by newNamedEnvFactory. Is it used elsewhere? -#### Initializer +#### Initializer ```typescript -import { environments } from '@time-loop/cdk-environments' +import { environments } from '@time-loop/cdk-named-environments' const namedEnvironmentProps: environments.NamedEnvironmentProps = { ... } ``` @@ -285,19 +285,19 @@ const namedEnvironmentProps: environments.NamedEnvironmentProps = { ... } | **Name** | **Type** | **Description** | | --- | --- | --- | -| account | string | The numeric account id as used by cdk.Environment.account. | -| attachmentZoneName | string | The DNS zone for attachments. | -| defaultRegion | string | If a region isn't specified, where should we default to. | -| name | string | The proper name of the environment in kebab-format. | -| organizationalUnit | string | What kind of an account is this? | -| regionDetails | {[ key: string ]: @time-loop/cdk-environments.environments.RegionalDetails} | A map of region => { asn, cidr }. | -| zoneName | string | The name of the route53 zone for this account. | -| ssoRegion | string | In which region does SSO live in? | -| ssoStartUrl | string | Is this an SSO accessible account? | +| account | string | The numeric account id as used by cdk.Environment.account. | +| attachmentZoneName | string | The DNS zone for attachments. | +| defaultRegion | string | If a region isn't specified, where should we default to. | +| name | string | The proper name of the environment in kebab-format. | +| organizationalUnit | string | What kind of an account is this? | +| regionDetails | {[ key: string ]: @time-loop/cdk-named-environments.environments.RegionalDetails} | A map of region => { asn, cidr }. | +| zoneName | string | The name of the route53 zone for this account. | +| ssoRegion | string | In which region does SSO live in? | +| ssoStartUrl | string | Is this an SSO accessible account? | --- -##### `account`Required +##### `account`Required ```typescript public readonly account: string; @@ -309,7 +309,7 @@ The numeric account id as used by cdk.Environment.account. --- -##### `attachmentZoneName`Required +##### `attachmentZoneName`Required ```typescript public readonly attachmentZoneName: string; @@ -321,7 +321,7 @@ The DNS zone for attachments. --- -##### `defaultRegion`Required +##### `defaultRegion`Required ```typescript public readonly defaultRegion: string; @@ -335,7 +335,7 @@ Also considered for centralized resources. --- -##### `name`Required +##### `name`Required ```typescript public readonly name: string; @@ -347,7 +347,7 @@ The proper name of the environment in kebab-format. --- -##### `organizationalUnit`Required +##### `organizationalUnit`Required ```typescript public readonly organizationalUnit: string; @@ -359,19 +359,19 @@ What kind of an account is this? --- -##### `regionDetails`Required +##### `regionDetails`Required ```typescript public readonly regionDetails: {[ key: string ]: RegionalDetails}; ``` -- *Type:* {[ key: string ]: @time-loop/cdk-environments.environments.RegionalDetails} +- *Type:* {[ key: string ]: @time-loop/cdk-named-environments.environments.RegionalDetails} A map of region => { asn, cidr }. --- -##### `zoneName`Required +##### `zoneName`Required ```typescript public readonly zoneName: string; @@ -383,7 +383,7 @@ The name of the route53 zone for this account. --- -##### `ssoRegion`Optional +##### `ssoRegion`Optional ```typescript public readonly ssoRegion: string; @@ -395,7 +395,7 @@ In which region does SSO live in? --- -##### `ssoStartUrl`Optional +##### `ssoStartUrl`Optional ```typescript public readonly ssoStartUrl: string; @@ -409,12 +409,12 @@ If so, what's the start url? --- -### RegionalDetails +### RegionalDetails -#### Initializer +#### Initializer ```typescript -import { environments } from '@time-loop/cdk-environments' +import { environments } from '@time-loop/cdk-named-environments' const regionalDetails: environments.RegionalDetails = { ... } ``` @@ -423,12 +423,12 @@ const regionalDetails: environments.RegionalDetails = { ... } | **Name** | **Type** | **Description** | | --- | --- | --- | -| asn | number | *No description.* | -| cidr | string | *No description.* | +| asn | number | *No description.* | +| cidr | string | *No description.* | --- -##### `asn`Required +##### `asn`Required ```typescript public readonly asn: number; @@ -438,7 +438,7 @@ public readonly asn: number; --- -##### ~~`cidr`~~Required +##### ~~`cidr`~~Required - *Deprecated:* you should probably be using the shard's cidr. @@ -453,19 +453,19 @@ public readonly cidr: string; ## Protocols -### IShard +### IShard -- *Implemented By:* IShard +- *Implemented By:* IShard #### Methods | **Name** | **Description** | | --- | --- | -| toString | *No description.* | +| toString | *No description.* | --- -##### `toString` +##### `toString` ```typescript public toString(): string @@ -475,14 +475,14 @@ public toString(): string | **Name** | **Type** | **Description** | | --- | --- | --- | -| cidr | string | The cidr for a shard's vpc. | -| name | string | The proper name for a shard (without numeric suffix). | -| number | number | The shard-number within the region. | -| region | string | The AWS region for a shard. | +| cidr | string | The cidr for a shard's vpc. | +| name | string | The proper name for a shard (without numeric suffix). | +| number | number | The shard-number within the region. | +| region | string | The AWS region for a shard. | --- -##### `cidr`Required +##### `cidr`Required ```typescript public readonly cidr: string; @@ -497,7 +497,7 @@ within which there are 16 /16 subnets for shards. --- -##### `name`Required +##### `name`Required ```typescript public readonly name: string; @@ -509,7 +509,7 @@ The proper name for a shard (without numeric suffix). --- -##### `number`Required +##### `number`Required ```typescript public readonly number: number; @@ -521,7 +521,7 @@ The shard-number within the region. --- -##### `region`Required +##### `region`Required ```typescript public readonly region: string; From 592cb8dd4179fc3e4fe3f2b0c88de24dde875c1b Mon Sep 17 00:00:00 2001 From: Justinon Date: Tue, 25 Oct 2022 10:10:43 -0700 Subject: [PATCH 07/11] chore(infra): Remove bad comments, unnused attr [CLK-173516] --- src/NamedEnv.ts | 27 --------------------------- 1 file changed, 27 deletions(-) diff --git a/src/NamedEnv.ts b/src/NamedEnv.ts index e9330a9..85f0396 100644 --- a/src/NamedEnv.ts +++ b/src/NamedEnv.ts @@ -60,10 +60,6 @@ export module environments { * The DNS zone into which services should be deployed. */ readonly zoneName: string; - /** - * The DNS zone for attachments - */ - readonly attachmentZoneName: string; } /** @@ -74,25 +70,6 @@ export module environments { * The numeric account id as used by cdk.Environment.account */ readonly account: string; - /** - * Mapping of regions to CIDR bases. - * Only override if you need to have subnets from one account not over-lapping subnets from another. - * This is an anti-pattern and we should avoid it where possible. - * - * @default - see belos - * { - * 'ap-northeast-2': '10.0.0.0/12', - * 'ap-south-1': '10.16.0.0/12', - * 'ap-southeast-2': '10.32.0.0/12', - * 'eu-central-1': '10.48.0.0/12' , - * 'eu-west-1': '10.64.0.0/12', - * 'sa-east-1': '10.80.0.0/12', - * 'us-east-1': '10.96.0.0/12', - * 'us-east-2': '10.112.0.0/12', - * 'us-west-1': '10.128.0.0/12', - * 'us-west-2': '10.144.0.0/12', - * }, - */ /** * If a region isn't specified, where should we default to. * Also considered for centralized resources. @@ -122,10 +99,6 @@ export module environments { * The name of the route53 zone for this account. */ readonly zoneName: string; - /** - * The DNS zone for attachments - */ - readonly attachmentZoneName: string; } export interface NamedEnvFactory { From c40a8d0c65c5baa06fe4f328b44edd134e80d5ab Mon Sep 17 00:00:00 2001 From: Justinon Date: Tue, 25 Oct 2022 14:04:04 -0700 Subject: [PATCH 08/11] chore(infra): Factor out deprecated code [CLK-173516] --- src/NamedEnv.ts | 91 +++++++++++++------------------------------ test/NamedEnv.test.ts | 27 ++----------- 2 files changed, 30 insertions(+), 88 deletions(-) diff --git a/src/NamedEnv.ts b/src/NamedEnv.ts index 85f0396..527d8c8 100644 --- a/src/NamedEnv.ts +++ b/src/NamedEnv.ts @@ -10,44 +10,24 @@ export module environments { readonly cidr: string; // in '0.0.0.0/32' format } - export interface NamedEnv extends Environment { - /** - * The asn to be used for TransitGateways - * @deprecated we aren't using tgw (maybe at the regional level for shard support though) - */ - readonly asn: number; - /** - * Currently the vpc cidr for the region. - * @deprecated you probably want the shard specific cidrs - */ - readonly cidr: string; - /** - * The shard within a region. - */ - readonly shard: IShard; + interface NamedEnvCommonProps { /** * If a region isn't specified, where should we default to. * Also considered for centralized resources. */ readonly defaultRegion: string; /** - * The kebab-name of the environment. + * A map of region => { asn, cidr }, for each region of the environment. + */ + readonly regionDetails: Record; + /** + * The proper name of the environment in kebab-format. */ readonly name: string; /** * What kind of an account is this? */ readonly organizationalUnit: string; - /** - * CIDR details for all regions. - */ - readonly regionDetails: Record; - /** - * The shorthand for the region. - * - * @deprecated use shard.name - */ - readonly shortRegion: string; /** * In which region does SSO live in? */ @@ -62,43 +42,21 @@ export module environments { readonly zoneName: string; } + export interface NamedEnv extends Environment, NamedEnvCommonProps { + /** + * The shard within a region. + */ + readonly shard: IShard; + } + /** * Used by newNamedEnvFactory. Is it used elsewhere? */ - export interface NamedEnvironmentProps { + export interface NamedEnvironmentProps extends NamedEnvCommonProps { /** * The numeric account id as used by cdk.Environment.account */ readonly account: string; - /** - * If a region isn't specified, where should we default to. - * Also considered for centralized resources. - */ - readonly defaultRegion: string; - /** - * A map of region => { asn, cidr } - */ - readonly regionDetails: Record; - /** - * The proper name of the environment in kebab-format. - */ - readonly name: string; - /** - * What kind of an account is this? - */ - readonly organizationalUnit: string; - /** - * In which region does SSO live in? - */ - readonly ssoRegion?: string; - /** - * Is this an SSO accessible account? If so, what's the start url? - */ - readonly ssoStartUrl?: string; - /** - * The name of the route53 zone for this account. - */ - readonly zoneName: string; } export interface NamedEnvFactory { @@ -113,7 +71,10 @@ export module environments { * @param props * @returns NamedEnv */ - export function newNamedEnvFactory(props: NamedEnvironmentProps): NamedEnvFactory { + export function newNamedEnvFactory( + props: NamedEnvironmentProps, + factory?: (...args: any[]) => NamedEnv, + ): NamedEnvFactory { if ((props.ssoStartUrl || props.ssoRegion) && !(props.ssoStartUrl && props.ssoRegion)) { console.warn( `Something is wrong for ${props.name}: ssoStartUrl = ${JSON.stringify(props.ssoStartUrl)} and ssoRegion = ${ @@ -122,20 +83,20 @@ export module environments { ); } - const namedEnvFactory = function (shard: IShard, asnOverride?: number): NamedEnv { + Object.defineProperties(factory, { + environmentName: { + value: props.name, + writable: false, + }, + regionDetails: { value: props.regionDetails, writable: false }, + }); + const namedEnvFactory = function (shard: IShard): NamedEnv { const region = shard.region; - const regionDetails = props.regionDetails[region]; - const asn = asnOverride || regionDetails?.asn || -1; - const cidr = shard.cidr; - const shortRegion = shard.name; return { ...props, - asn, shard, - cidr, region, - shortRegion, }; }; namedEnvFactory.environmentName = props.name; diff --git a/test/NamedEnv.test.ts b/test/NamedEnv.test.ts index fb24a90..55b34f0 100644 --- a/test/NamedEnv.test.ts +++ b/test/NamedEnv.test.ts @@ -16,7 +16,6 @@ describe('NamedEnv', () => { account: 'fakeAccount', defaultRegion: 'fakeRegion', zoneName: 'fake.com', - attachmentZoneName: 'fakeAttachment.com', regionDetails: {}, organizationalUnit: TestOrganizationalUnit.Test, }; @@ -47,7 +46,6 @@ describe('NamedEnv', () => { account: 'fakeAccount', defaultRegion: 'fakeRegion', zoneName: 'fake.com', - attachmentZoneName: 'fakeAttachment.com', regionDetails: {}, organizationalUnit: TestOrganizationalUnit.Test, }; @@ -60,27 +58,10 @@ describe('NamedEnv', () => { }; factory = environments.newNamedEnvFactory(fakeEnvProps); }); - - it('has default ASN', () => { - const namedEnv = factory(shard); - expect(namedEnv.asn).toBe(-1); - }); - it('respects overrideAsn', () => { - const namedEnv = factory(shard, 666); // 😈 - expect(namedEnv.asn).toBe(666); - }); - it('can pull ASN from regionDetails', () => { - factory = environments.newNamedEnvFactory({ - ...fakeEnvProps, - regionDetails: { - 'us-west-2': { - asn: 10, - cidr: '10.0.0.0/32', - }, - }, - }); - const namedEnv = factory(shard); - expect(namedEnv.asn).toBe(10); + it('takes a shard as input', () => { + const testEnv = factory(shard); + expect(testEnv).toHaveProperty('shard'); + expect(testEnv.shard).toEqual(shard); }); }); }); From 6fc41b9f4db570acf23f4c9b4d6493635a3cc71f Mon Sep 17 00:00:00 2001 From: Justinon Date: Tue, 25 Oct 2022 14:14:42 -0700 Subject: [PATCH 09/11] chore(infra): README update and codecov badge [CLK-173516] --- README.md | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/README.md b/README.md index b3fa7dd..9951835 100644 --- a/README.md +++ b/README.md @@ -1 +1,5 @@ -# replace this \ No newline at end of file +[![codecov](https://codecov.io/gh/time-loop/cdk-named-environments/branch/main/graph/badge.svg?token=vxIlqfu4hL)](https://codecov.io/gh/time-loop/cdk-named-environments) + +# cdk-named-environments + +This repo provides an interface for `NamedEnv`, an extension of the [AWS provided Environment interface](https://docs.aws.amazon.com/cdk/api/v2/docs/aws-cdk-lib.Environment.html). The goal is to allow the operator to abstract away info associated with an Environment, and make them human-intelligible for consumers. For this reason it is recommended that you create your own library and class implementing `NamedEnv`, to automatically abstract for example networking configuration that the average developer should assume will Just Work. From 195fafbf42fcce1dfa1f0266d129cecf49fc45aa Mon Sep 17 00:00:00 2001 From: Justinon Date: Tue, 25 Oct 2022 14:27:35 -0700 Subject: [PATCH 10/11] chore(infra): Remove accidentally committed Object call [CLK-173516] --- src/NamedEnv.ts | 18 +++--------------- 1 file changed, 3 insertions(+), 15 deletions(-) diff --git a/src/NamedEnv.ts b/src/NamedEnv.ts index 527d8c8..2f1fe5b 100644 --- a/src/NamedEnv.ts +++ b/src/NamedEnv.ts @@ -63,7 +63,7 @@ export module environments { // TODO: should we add shardDetails here? readonly environmentName: string; readonly regionDetails: Record; - (shard: IShard, overrideAsn?: number): NamedEnv; + (shard: IShard): NamedEnv; } /** @@ -71,10 +71,7 @@ export module environments { * @param props * @returns NamedEnv */ - export function newNamedEnvFactory( - props: NamedEnvironmentProps, - factory?: (...args: any[]) => NamedEnv, - ): NamedEnvFactory { + export function newNamedEnvFactory(props: NamedEnvironmentProps): NamedEnvFactory { if ((props.ssoStartUrl || props.ssoRegion) && !(props.ssoStartUrl && props.ssoRegion)) { console.warn( `Something is wrong for ${props.name}: ssoStartUrl = ${JSON.stringify(props.ssoStartUrl)} and ssoRegion = ${ @@ -83,20 +80,11 @@ export module environments { ); } - Object.defineProperties(factory, { - environmentName: { - value: props.name, - writable: false, - }, - regionDetails: { value: props.regionDetails, writable: false }, - }); const namedEnvFactory = function (shard: IShard): NamedEnv { - const region = shard.region; - return { ...props, shard, - region, + region: shard.region, }; }; namedEnvFactory.environmentName = props.name; From 9fd45a9b036631780fbeb2cb74f7c61a318e37ee Mon Sep 17 00:00:00 2001 From: github-actions Date: Tue, 25 Oct 2022 21:29:33 +0000 Subject: [PATCH 11/11] chore: self mutation Signed-off-by: github-actions --- API.md | 87 ++++++---------------------------------------------------- 1 file changed, 8 insertions(+), 79 deletions(-) diff --git a/API.md b/API.md index 081aa0e..5b14174 100644 --- a/API.md +++ b/API.md @@ -19,15 +19,11 @@ const namedEnv: environments.NamedEnv = { ... } | --- | --- | --- | | account | string | The AWS account ID for this environment. | | region | string | The AWS region for this environment. | -| asn | number | The asn to be used for TransitGateways. | -| attachmentZoneName | string | The DNS zone for attachments. | -| cidr | string | Currently the vpc cidr for the region. | | defaultRegion | string | If a region isn't specified, where should we default to. | -| name | string | The kebab-name of the environment. | +| name | string | The proper name of the environment in kebab-format. | | organizationalUnit | string | What kind of an account is this? | -| regionDetails | {[ key: string ]: @time-loop/cdk-named-environments.environments.RegionalDetails} | CIDR details for all regions. | +| regionDetails | {[ key: string ]: @time-loop/cdk-named-environments.environments.RegionalDetails} | A map of region => { asn, cidr }, for each region of the environment. | | shard | IShard | The shard within a region. | -| shortRegion | string | The shorthand for the region. | | zoneName | string | The DNS zone into which services should be deployed. | | ssoRegion | string | In which region does SSO live in? | | ssoStartUrl | string | Is this an SSO accessible account? | @@ -74,46 +70,6 @@ will cause this stack to emit synthesis errors. --- -##### ~~`asn`~~Required - -- *Deprecated:* we aren't using tgw (maybe at the regional level for shard support though) - -```typescript -public readonly asn: number; -``` - -- *Type:* number - -The asn to be used for TransitGateways. - ---- - -##### `attachmentZoneName`Required - -```typescript -public readonly attachmentZoneName: string; -``` - -- *Type:* string - -The DNS zone for attachments. - ---- - -##### ~~`cidr`~~Required - -- *Deprecated:* you probably want the shard specific cidrs - -```typescript -public readonly cidr: string; -``` - -- *Type:* string - -Currently the vpc cidr for the region. - ---- - ##### `defaultRegion`Required ```typescript @@ -136,7 +92,7 @@ public readonly name: string; - *Type:* string -The kebab-name of the environment. +The proper name of the environment in kebab-format. --- @@ -160,7 +116,7 @@ public readonly regionDetails: {[ key: string ]: RegionalDetails}; - *Type:* {[ key: string ]: @time-loop/cdk-named-environments.environments.RegionalDetails} -CIDR details for all regions. +A map of region => { asn, cidr }, for each region of the environment. --- @@ -176,20 +132,6 @@ The shard within a region. --- -##### ~~`shortRegion`~~Required - -- *Deprecated:* use shard.name - -```typescript -public readonly shortRegion: string; -``` - -- *Type:* string - -The shorthand for the region. - ---- - ##### `zoneName`Required ```typescript @@ -286,12 +228,11 @@ const namedEnvironmentProps: environments.NamedEnvironmentProps = { ... } | **Name** | **Type** | **Description** | | --- | --- | --- | | account | string | The numeric account id as used by cdk.Environment.account. | -| attachmentZoneName | string | The DNS zone for attachments. | | defaultRegion | string | If a region isn't specified, where should we default to. | | name | string | The proper name of the environment in kebab-format. | | organizationalUnit | string | What kind of an account is this? | -| regionDetails | {[ key: string ]: @time-loop/cdk-named-environments.environments.RegionalDetails} | A map of region => { asn, cidr }. | -| zoneName | string | The name of the route53 zone for this account. | +| regionDetails | {[ key: string ]: @time-loop/cdk-named-environments.environments.RegionalDetails} | A map of region => { asn, cidr }, for each region of the environment. | +| zoneName | string | The DNS zone into which services should be deployed. | | ssoRegion | string | In which region does SSO live in? | | ssoStartUrl | string | Is this an SSO accessible account? | @@ -309,18 +250,6 @@ The numeric account id as used by cdk.Environment.account. --- -##### `attachmentZoneName`Required - -```typescript -public readonly attachmentZoneName: string; -``` - -- *Type:* string - -The DNS zone for attachments. - ---- - ##### `defaultRegion`Required ```typescript @@ -367,7 +296,7 @@ public readonly regionDetails: {[ key: string ]: RegionalDetails}; - *Type:* {[ key: string ]: @time-loop/cdk-named-environments.environments.RegionalDetails} -A map of region => { asn, cidr }. +A map of region => { asn, cidr }, for each region of the environment. --- @@ -379,7 +308,7 @@ public readonly zoneName: string; - *Type:* string -The name of the route53 zone for this account. +The DNS zone into which services should be deployed. ---