From b457cf609df1ff4da97e9e54513a626f721143cd Mon Sep 17 00:00:00 2001 From: Ari Palo Date: Tue, 16 Aug 2022 15:06:06 +0300 Subject: [PATCH] feat: rename Accounts as AccountStrategy --- API.md | 51 +++++++++++++++++++--------------- README.md | 20 +++++++++++-- src/configurations/accounts.ts | 16 +++++++---- src/configurations/index.ts | 2 +- test/integration.test.ts | 4 +-- 5 files changed, 61 insertions(+), 32 deletions(-) diff --git a/API.md b/API.md index 8793e03..5c17b1e 100644 --- a/API.md +++ b/API.md @@ -2196,14 +2196,21 @@ AccountContext.isShared(scope: Construct) -### Accounts +### AccountStrategy -#### Initializers +Use static methods of Accounts abstract class to define your account strategy. + +Available strategies are: +- One Account: `shared` +- Two Accounts: `dev`+`prod` – _recommended_ +- Three Accounts: `dev`+`preprod`+`prod` + +#### Initializers ```typescript -import { Accounts } from '@alma-cdk/project' +import { AccountStrategy } from '@alma-cdk/project' -new Accounts() +new AccountStrategy() ``` | **Name** | **Type** | **Description** | @@ -2216,18 +2223,18 @@ new Accounts() | **Name** | **Description** | | --- | --- | -| one | Enables single account strategy. | -| three | Enables triple account strategy. | -| two | Enables dual account strategy. | +| one | Enables single account strategy. | +| three | Enables triple account strategy. | +| two | Enables dual account strategy. | --- -##### `one` +##### `one` ```typescript -import { Accounts } from '@alma-cdk/project' +import { AccountStrategy } from '@alma-cdk/project' -Accounts.one(props: AccountsOneProps) +AccountStrategy.one(props: AccountsOneProps) ``` Enables single account strategy. @@ -2244,7 +2251,7 @@ Enables single account strategy. *Example* ```typescript -Accounts.ONE({ +AccountStrategy.one({ shared: { id: '111111111111', }, @@ -2252,18 +2259,18 @@ Accounts.ONE({ ``` -###### `props`Required +###### `props`Required - *Type:* AccountsOneProps --- -##### `three` +##### `three` ```typescript -import { Accounts } from '@alma-cdk/project' +import { AccountStrategy } from '@alma-cdk/project' -Accounts.three(props: AccountsThreeProps) +AccountStrategy.three(props: AccountsThreeProps) ``` Enables triple account strategy. @@ -2282,7 +2289,7 @@ Enables triple account strategy. *Example* ```typescript -Accounts.THREE({ +AccountStrategy.three({ dev: { id: '111111111111', }, @@ -2296,18 +2303,18 @@ Accounts.THREE({ ``` -###### `props`Required +###### `props`Required - *Type:* AccountsThreeProps --- -##### `two` +##### `two` ```typescript -import { Accounts } from '@alma-cdk/project' +import { AccountStrategy } from '@alma-cdk/project' -Accounts.two(props: AccountsTwoProps) +AccountStrategy.two(props: AccountsTwoProps) ``` Enables dual account strategy. @@ -2325,7 +2332,7 @@ Enables dual account strategy. *Example* ```typescript -Accounts.TWO({ +AccountStrategy.two({ dev: { id: '111111111111', }, @@ -2336,7 +2343,7 @@ Accounts.TWO({ ``` -###### `props`Required +###### `props`Required - *Type:* AccountsTwoProps diff --git a/README.md b/README.md index dc92faa..c2736d6 100644 --- a/README.md +++ b/README.md @@ -73,7 +73,7 @@ Steps required to define a _environmental_ project resources; At first, it might ```ts // bin/app.ts - import { Project, Accounts } from '@alma-cdk/project'; + import { Project, AccountStrategy } from '@alma-cdk/project'; const project = new Project({ // Basic info, you could also read these from package.json if you want @@ -88,7 +88,7 @@ Steps required to define a _environmental_ project resources; At first, it might defaultRegion: 'eu-west-1', // Configures the project to use 2 AWS accounts (recommended) - accounts: Accounts.two({ + accounts: AccountStrategy.two({ dev: { id: '111111111111', config: { @@ -199,3 +199,19 @@ Steps required to define a _environmental_ project resources; At first, it might new Environment(project); ``` + +
+ + +## Documentation + +See detailed documentation for specific classes & methods at [constructs.dev](http://constructs.dev/packages/@alma-cdk/project). + +Generally speaking you would be most interested in the following: +- Project +- AccountStrategy +- SmartStack +- AccountWrapper & EnvironmentWrapper +- AccountContext (AC) +- EnvironmentContext (EC) +- Name / UrlName / PathName diff --git a/src/configurations/accounts.ts b/src/configurations/accounts.ts index c4c7501..7cd36c6 100644 --- a/src/configurations/accounts.ts +++ b/src/configurations/accounts.ts @@ -44,8 +44,14 @@ const emptyMockAccountProps: AccountConfiguration = { id: '123456789012', }; - -export class Accounts { +/** + * Use static methods of Accounts abstract class to define your account strategy. + * Available strategies are: + * - One Account: `shared` + * - Two Accounts: `dev`+`prod` – _recommended_ + * - Three Accounts: `dev`+`preprod`+`prod` + */ +export abstract class AccountStrategy { /** * Enables single account strategy. @@ -60,7 +66,7 @@ export class Accounts { * - production * * @example - * Accounts.ONE({ + * AccountStrategy.one({ * shared: { * id: '111111111111', * }, @@ -104,7 +110,7 @@ export class Accounts { * - production * * @example - * Accounts.TWO({ + * AccountStrategy.two({ * dev: { * id: '111111111111', * }, @@ -157,7 +163,7 @@ export class Accounts { * - production * * @example - * Accounts.THREE({ + * AccountStrategy.three({ * dev: { * id: '111111111111', * }, diff --git a/src/configurations/index.ts b/src/configurations/index.ts index 3e2fe24..b978b49 100644 --- a/src/configurations/index.ts +++ b/src/configurations/index.ts @@ -1,5 +1,5 @@ export { - Accounts, + AccountStrategy, AccountConfiguration, AccountsOneProps, AccountsTwoProps, diff --git a/test/integration.test.ts b/test/integration.test.ts index 6fd3a7e..1709f3c 100644 --- a/test/integration.test.ts +++ b/test/integration.test.ts @@ -1,5 +1,5 @@ import { Match } from 'aws-cdk-lib/assertions'; -import { Accounts } from '../src'; +import { AccountStrategy } from '../src'; import { generateTestApp } from './helpers/app'; import { sortTagsByKey, tagsAsDictionary, TagValue } from './helpers/tags'; @@ -15,7 +15,7 @@ describe('Integration', () => { email: 'mad.scientists@acme.example.com', }, defaultRegion: 'eu-west-1', - accounts: Accounts.two({ + accounts: AccountStrategy.two({ dev: { id: '111111111111', config: {