Skip to content

Commit

Permalink
feat: rename Accounts as AccountStrategy
Browse files Browse the repository at this point in the history
  • Loading branch information
aripalo committed Aug 16, 2022
1 parent 044e528 commit b457cf6
Show file tree
Hide file tree
Showing 5 changed files with 61 additions and 32 deletions.
51 changes: 29 additions & 22 deletions API.md
Original file line number Diff line number Diff line change
Expand Up @@ -2196,14 +2196,21 @@ AccountContext.isShared(scope: Construct)



### Accounts <a name="Accounts" id="@alma-cdk/project.Accounts"></a>
### AccountStrategy <a name="AccountStrategy" id="@alma-cdk/project.AccountStrategy"></a>

#### Initializers <a name="Initializers" id="@alma-cdk/project.Accounts.Initializer"></a>
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 <a name="Initializers" id="@alma-cdk/project.AccountStrategy.Initializer"></a>

```typescript
import { Accounts } from '@alma-cdk/project'
import { AccountStrategy } from '@alma-cdk/project'

new Accounts()
new AccountStrategy()
```

| **Name** | **Type** | **Description** |
Expand All @@ -2216,18 +2223,18 @@ new Accounts()

| **Name** | **Description** |
| --- | --- |
| <code><a href="#@alma-cdk/project.Accounts.one">one</a></code> | Enables single account strategy. |
| <code><a href="#@alma-cdk/project.Accounts.three">three</a></code> | Enables triple account strategy. |
| <code><a href="#@alma-cdk/project.Accounts.two">two</a></code> | Enables dual account strategy. |
| <code><a href="#@alma-cdk/project.AccountStrategy.one">one</a></code> | Enables single account strategy. |
| <code><a href="#@alma-cdk/project.AccountStrategy.three">three</a></code> | Enables triple account strategy. |
| <code><a href="#@alma-cdk/project.AccountStrategy.two">two</a></code> | Enables dual account strategy. |

---

##### `one` <a name="one" id="@alma-cdk/project.Accounts.one"></a>
##### `one` <a name="one" id="@alma-cdk/project.AccountStrategy.one"></a>

```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.
Expand All @@ -2244,26 +2251,26 @@ Enables single account strategy.
*Example*

```typescript
Accounts.ONE({
AccountStrategy.one({
shared: {
id: '111111111111',
},
}),
```


###### `props`<sup>Required</sup> <a name="props" id="@alma-cdk/project.Accounts.one.parameter.props"></a>
###### `props`<sup>Required</sup> <a name="props" id="@alma-cdk/project.AccountStrategy.one.parameter.props"></a>

- *Type:* <a href="#@alma-cdk/project.AccountsOneProps">AccountsOneProps</a>

---

##### `three` <a name="three" id="@alma-cdk/project.Accounts.three"></a>
##### `three` <a name="three" id="@alma-cdk/project.AccountStrategy.three"></a>

```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.
Expand All @@ -2282,7 +2289,7 @@ Enables triple account strategy.
*Example*

```typescript
Accounts.THREE({
AccountStrategy.three({
dev: {
id: '111111111111',
},
Expand All @@ -2296,18 +2303,18 @@ Accounts.THREE({
```


###### `props`<sup>Required</sup> <a name="props" id="@alma-cdk/project.Accounts.three.parameter.props"></a>
###### `props`<sup>Required</sup> <a name="props" id="@alma-cdk/project.AccountStrategy.three.parameter.props"></a>

- *Type:* <a href="#@alma-cdk/project.AccountsThreeProps">AccountsThreeProps</a>

---

##### `two` <a name="two" id="@alma-cdk/project.Accounts.two"></a>
##### `two` <a name="two" id="@alma-cdk/project.AccountStrategy.two"></a>

```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.
Expand All @@ -2325,7 +2332,7 @@ Enables dual account strategy.
*Example*

```typescript
Accounts.TWO({
AccountStrategy.two({
dev: {
id: '111111111111',
},
Expand All @@ -2336,7 +2343,7 @@ Accounts.TWO({
```


###### `props`<sup>Required</sup> <a name="props" id="@alma-cdk/project.Accounts.two.parameter.props"></a>
###### `props`<sup>Required</sup> <a name="props" id="@alma-cdk/project.AccountStrategy.two.parameter.props"></a>

- *Type:* <a href="#@alma-cdk/project.AccountsTwoProps">AccountsTwoProps</a>

Expand Down
20 changes: 18 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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: {
Expand Down Expand Up @@ -199,3 +199,19 @@ Steps required to define a _environmental_ project resources; At first, it might
new Environment(project);
```
<br/>
## 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
16 changes: 11 additions & 5 deletions src/configurations/accounts.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand All @@ -60,7 +66,7 @@ export class Accounts {
* - production
*
* @example
* Accounts.ONE({
* AccountStrategy.one({
* shared: {
* id: '111111111111',
* },
Expand Down Expand Up @@ -104,7 +110,7 @@ export class Accounts {
* - production
*
* @example
* Accounts.TWO({
* AccountStrategy.two({
* dev: {
* id: '111111111111',
* },
Expand Down Expand Up @@ -157,7 +163,7 @@ export class Accounts {
* - production
*
* @example
* Accounts.THREE({
* AccountStrategy.three({
* dev: {
* id: '111111111111',
* },
Expand Down
2 changes: 1 addition & 1 deletion src/configurations/index.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
export {
Accounts,
AccountStrategy,
AccountConfiguration,
AccountsOneProps,
AccountsTwoProps,
Expand Down
4 changes: 2 additions & 2 deletions test/integration.test.ts
Original file line number Diff line number Diff line change
@@ -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';

Expand All @@ -15,7 +15,7 @@ describe('Integration', () => {
email: '[email protected]',
},
defaultRegion: 'eu-west-1',
accounts: Accounts.two({
accounts: AccountStrategy.two({
dev: {
id: '111111111111',
config: {
Expand Down

0 comments on commit b457cf6

Please sign in to comment.