Installation and Setup - Cloud
Requirements
- Domain Name
- npm
- CDKTF
- An Amazon AWS account with a ~/.aws configuration and credential file settings
- a Stripe Account with api key
- Google Recaptcha key
Full deployment time will take roughly an hour with manual steps between (required for most error free/seamless experience)
Installation
-
clone the project
git clone git@github.com:bmiles-development/s6pack-cloud.git
and cd into the project diractory. -
run
npm update
-
Install AWS, Stripe and dependant CDKTF providers. run
cdktf get
to install the providers. -
Copy and rename the following files:
-
(Optional) If you don’t want to use Payment Plans, you can set
useStripePaymentPlans: false
in the .config.datStack.yaml file. deafault is set to true. -
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. -
In your
.config.hostingStack.yaml
file, change theuseS3TfState
value to true. -
run
cd cdktf.out/stacks/tfStateBackupStack && terraform init -migrate-state
then answeryes
at the prompt -
run
cd ../../../
-
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. -
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:
Google Recaptcha secret key see: https://blog.logrocket.com/implement-recaptcha-react-application/ , or just create an account here https://www.google.com/u/1/recaptcha/admin/create .
For localhost captcha testing see: https://developers.google.com/recaptcha/docs/faq#id-like-to-run-automated-tests-with-recaptcha.-what-should-i-do
-
Create emplty values for these parameters for now, we will poplulate them later once they have been created:
-
If you are using payment plans with stripe, add these parameters below as well: Free trial plan id (eg: Business Plan, see config.dataStack.yaml)
Paid plan id (eg: Pro Plan see config.dataStack.yaml)
Dummy parameters to populate later:
Lambda Layers
How to creat new node.js Lambda Layers: https://dev.to/afrazkhan/how-to-setup-aws-lambda-layers-nodejs-182
npm init -i
npm i {package_names}
- 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
- adjust package.json (cdktf, @cdktf/provider-*, @types/node) to latest versions then in root folder and run
npm update
- run
npm list -g
to get a list of global npm packages and for each module in question (aws-cdk, cdktf-cli) runsudo npm install -g <module-name>
deploy
the stack. If delpying fails, then:- For each stack, you may need to upgrade each stack in the folder
cdktf.out/stacks
withcd cdktf.out/stacks/$nameofstack
by runningterraform 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)