npm package: @rawrus-cdk/tester
Description: ## Table of Contents
Author: James Hoegrel
Latest version: 0.0.20

# README

## Table of Contents

- [README](#readme)
  - [Table of Contents](#table-of-contents)
  - [Introduction](#introduction)
  - [Quick Start](#quick-start)
  - [Listener Priority Reservations](#listener-priority-reservations)
  - [Repo Layout](#repo-layout)
  - [Testing](#testing)
  - [Default Opinions](#default-opinions)
  - [Useful commands](#useful-commands)


## Introduction

<p align="center">
    This is a collection of internally maintained CDK constructs used by various projects.
</p>

Buildkite pipeline: [a-cloud-guru/infra-cdk-constructs](https://buildkite.com/a-cloud-guru/infra-cdk-constructs)

## Quick Start

- Using a construct:

  1. Add this package to your projects `package.json`:

        `yarn add @a-cloud-guru/cdk-constructs`

  2. Inside your CDK application you can now import constructs
        ```
        import { RdsCluster, Engine } from '@a-cloud-guru/cdk-constructs';
        ```

- Adding a new construct:

  3. Create a file for the construct in `./lib/` with the naming convention `<ConstructName>.ts`. This will house the construct itself.
  4. Create tests for the construct in `./test/` with the naming convention `<ConstructName>.test.ts`. This will house jest tests for the construct.
  5. Update `./lib/index.ts` to ensure that the new construct is being exported
  6. Update the package's `version` number in `./package.json`

- Building a new package:

  3. Update `./package.json` to ensure a new `version` is being published
  4. Run available tests `yarn test` and fix any breakages
  5. Use `npm` to create a release candidate: `npm run build`
  6. Use `npm` to publish the package (requires an `NPM_TOKEN` env var): `npm publish`

     ```
     # Build package
     npm run build
     # Publish release
     NPM_TOKEN=<x>
     ```

## Listener Priority Reservations

  Each use of the `ContainerizedApp` pattern requires a unique listener priority
to use in the shared Application Load Balancer listener rule. Because of this
requiremet a list of the currently reserved priorities is being tracked within
confluence.

List of [Application Listener Priority Reservations](https://pluralsight.atlassian.net/wiki/spaces/PE/pages/33071563192/Application+Listener+Priority+Reservations)

When using this pattern in staging or production ensure to use/update this list.

## Repo Layout

These are some of the major landmarks inside this repo:

```
./lib               -- Contains each of the constructs being made available
./lib/index.ts      -- Main entrypoint, only meant to export availble constructs
./test              -- Contains jest tests for IaC constructs
./examples          -- Contains usage examples of available constructs
./package.json      -- Dependency management and versioning
```
## Testing

   This project is currently being tested using the [jest framework](https://jestjs.io/) as described by the [CDK's getting started guide on testing](https://docs.aws.amazon.com/cdk/latest/guide/testing.html).

   All tests can be found in the `./test/` directory and must end with a prefix of `.test.js`. Ideally each construct has an accompanied test suite with the same name as the construct in `./lib/`

To run all available IaC tests use the following:

```
yarn test
```

## Default Opinions

Almost all of the opinions expressed below can be overriden at synth time

 - ALB:
    - Deletion protection enabled for "production" stage.
    - internetFacing: true

 - ECR:

 - ContainerizedApp:
   - Services are deployed to Fargate clusters
   - When `desiredServiceCount` is unspecified a default of `3` is used._
   - Container Image can be pinned to a specific commit using the `COMMIT_HASH` environment variable
   - LoadBalancer attached to services is publicly exposed
   - When `registrationTimeout` is unspecified a default of `300` is used
   - When `circuitBreakerRollback` is unspecified rollbacks are set to `true`
   - When `containerInsights` is unspecified containerInsights default to `true`.

 - RdsCluster:
   - When no `databaseEngine` is specified `PostgreSQL` is the default
   - Storage is encrypted with a `kms_key`, if no `kms_key_arn` is provided one is created.
   - When no `backupRetention` period is specified the default is `35` days (cdk enforces `Retention period must be between 1 and 35.`)
   - When no `backupWindow` is specified a default of `08:00-09:00` is used (this is UTC and must be at least 30 minutes long).
   - Due to limited support (Only Legacy Aurora MySQL) no support for `backtrackWindow` is provided.
   - All parameter groups, by default, have `max_connections` set to `16000`
   - When `enablePerformanceInsights` is unspecified it defaults to `true`
   - When `deletionProtection` is unspecified it defaults to `true`
    - Serverless:
      - `backupWindow` has no effect on Serverless clusters
      - Serverless does not support `backtrackWindow`.
      - Serverless does not support `enablePerformanceInsights`
    - Legacy MySQL:
      - Performance insights requires a InstanceClass higher than t3, we default to `r3.large`.
    - Legacy PostgreSQL
      - Aurora PostgreSQL does not support a `backtrackWindow`.

 - RedisCluster:
   - One Redis cluster per application
   - When `cacheNodeType` is unspecified a size of `cache.t2.small` is used
   - When `numCacheNodes` is unspecified a size of `1` is used

 - Security Groups:
   - Default security groups whitelist the following
     - Internal: 0.0.0.0/0:0 => 0.0.0.0/0:(3306|5432) (RDS)
     - Internal: 0.0.0.0/0:0 => 0.0.0.0/0:6379 (Redis)
     - Public:   0.0.0.0/0:0 => 0.0.0.0/0:(80) (Expose ALB to internet traffic)

## Useful commands

 * `npm run build`   compile typescript to js
 * `npm run watch`   watch for changes and compile
 * `npm run test`    perform the jest unit tests