Skip to content

Installation and Setup - Cloud

Requirements

Full deployment time will take roughly an hour with manual steps between (required for most error free/seamless experience)

Installation

  1. clone the project git clone git@github.com:bmiles-development/s6pack-cloud.git and cd into the project diractory.

  2. run npm update

  3. Install AWS, Stripe and dependant CDKTF providers. run cdktf get to install the providers.

  4. Copy and rename the following files:

    .config.blueGreenToggleStack.yaml.template -> .config.blueGreenToggleStack.yaml
    .config.dataStack.yaml.template -> .config.dataStack.yaml
    .config.hostingStack.yaml.template -> .config.hostingStack.yaml
    .config.webStack.yaml.template -> .config.webStack.yaml
  5. run cdktf deploy tfStateBackupStack --auto-approve this stack’s purpose is to setup the Terraform state store on S3 instead of on your local machine. This is for a bunch of good reasons, including better security and avoiding syncing issues when developing with a team.

  6. In your .config.hostingStack.yaml file, change the useS3TfState value to true.

  7. run cd cdktf.out/stacks/tfStateBackupStack && terraform init -migrate-state then answer yes at the prompt

  8. run cd ../../../

  9. run cdktf deploy tfStateBackupStack --auto-approve. This is necessary to work around the chicken-or-the-egg problem of storing the tfStateBackupStack.tfState files on the tfStateBackupStack itself.

  10. Create AWS [SSM Parameter Store] SecureString Parameters (https://us-east-1.console.aws.amazon.com/systems-manager/parameters) for each of the following parameters:

    Use a dummy email address if response is not necessary:

    /global/parameters/testUsername = test@test.com
    /global/parameters/contactUsEmail-dev = testp+contactUsTest@test.com
    /global/parameters/contactUsEmail-live = test+production@test.com
    /global/parameters/testPassword = R123xyz123-!

    Google Recaptcha secret key see: https://blog.logrocket.com/implement-recaptcha-react-application/ , or just create an account here https://www.google.com/recaptcha/admin/create .

    /global/parameters/recaptchaSiteSecret-live = 6Lxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx

    For localhost captcha testing see: https://developers.google.com/recaptcha/docs/faq#id-like-to-run-automated-tests-with-recaptcha.-what-should-i-do

    /global/parameters/recaptchaSiteSecret-dev = 6LeIxAcTAAAAAGG-vFI1TnRWxMZNFuojJ4WifJWe

    Free plan id, can leave as is or can be customizable (eg: Free Plan see config.dataStack.yaml)

    /global/parameters/testFreeTrialPlanIdId = dev_business_plan"

    Paid plan id (eg: Pro Plan see config.dataStack.yaml)

    /global/parameters/testPaidPlanId = pro_plan

    free trial plan id (eg: Business Plan, see config.dataStack.yaml)

    /global/parameters/testFreeTrialPlanId = business_plan
  11. create emplty values for these parameters for now, we will poplulate them later once they have been created:

    /global/parameters/stripeToken-dev = " "
    /global/parameters/stripeToken-live = " "
    /global/parameters/stripeWebhookSigningSecret-dev = " "
    /global/parameters/stripeWebhookSigningSecret-live = " "
    /global/parameters/testUserPoolId = " "
    /global/parameters/testCognitoClientId = " "
    /global/parameters/testIdentityPoolId = " "

Lambda Layers

How to creat new node.js Lambda Layers: https://dev.to/afrazkhan/how-to-setup-aws-lambda-layers-nodejs-182 1) npm init -i 2) npm i {package_names} 3) add this snippet to package.json "scripts": { "build": "npm install && mkdir -p nodejs && cp -r node_modules nodejs/ && zip -r {file-name}.zip nodejs" } 4)npm run build

Upgrading

1) adjust package.json (cdktf, @cdktf/provider-*, @types/node) to latest versions then in root folder and run ```npm update```
2) run ```npm list -g``` to get a list of global npm packages and for each module in question (aws-cdk, cdktf-cli) run ```sudo npm install -g <module-name>```
3) ```deploy``` the stack. If delpying fails, then:
4) For each stack, you may need to upgrade each stack in the folder ```cdktf.out/stacks``` with ```cd cdktf.out/stacks/$nameofstack``` by running ```terraform init -upgrade```

Update notes for serverless v2

npm update sudo npm install cdktf-cli@0.13.0 -g cdktf provider add “aws@~>4.14” null kreuzwerker/docker archive cdktf get npm i -D @types/node //run this if main.ts cant find ‘fs’ or ‘path’ when you run cdktf deploy, it will prompt you to terraform init -upgrade for each stack (see Upgrading section above, step 3)

Potential Issues and Solutions

cdktf destroy webStackGreen webStackBlue webStackDev causes error with Appsync: “Error: error deleting Appsync Domain Name “<domain_name_here>”: BadRequestException: Domain name must be disassociated before it can be deleted.” Known issue here https://github.com/hashicorp/terraform-provider-aws/issues/25322.

cdktf destroy hostingStack causes error with stripe products not deleting. Since the Stripe API does not have a delete endpoint the products have to be manually deleted in the Stripe admin panel. The relevant objects in the terraform.hostingStack.state file needs to be deleted as well, or the cdktf destroy hostingStack command will continue to fail.

Resource tracking fails when manually deleting resources

The easiest way to no longer track resources that have been manually deleted is to simply delete the resources in the .tfstate and .tfstate.backup files. There are commands to do this but this way seems easier especially for multiple resources (like Stripe prices)