-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #48 from sourcefuse/arc-cdk-template
feat(core): add arc-cdk-templates for sl cli
- Loading branch information
Showing
22 changed files
with
855 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1 +1 @@ | ||
1.1.0 | ||
1.2.0 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,166 @@ | ||
# Logs | ||
logs | ||
*.log | ||
npm-debug.log* | ||
yarn-debug.log* | ||
yarn-error.log* | ||
lerna-debug.log* | ||
|
||
# Diagnostic reports (https://nodejs.org/api/report.html) | ||
report.[0-9]*.[0-9]*.[0-9]*.[0-9]*.json | ||
|
||
# Runtime data | ||
pids | ||
*.pid | ||
*.seed | ||
*.pid.lock | ||
|
||
# Directory for instrumented libs generated by jscoverage/JSCover | ||
lib-cov | ||
|
||
# Coverage directory used by tools like istanbul | ||
coverage | ||
*.lcov | ||
|
||
# nyc test coverage | ||
.nyc_output | ||
|
||
# Grunt intermediate storage (https://gruntjs.com/creating-plugins#storing-task-files) | ||
.grunt | ||
|
||
# Bower dependency directory (https://bower.io/) | ||
bower_components | ||
|
||
# node-waf configuration | ||
.lock-wscript | ||
|
||
# Compiled binary addons (https://nodejs.org/api/addons.html) | ||
build/Release | ||
|
||
# Dependency directories | ||
node_modules/ | ||
jspm_packages/ | ||
|
||
# Snowpack dependency directory (https://snowpack.dev/) | ||
web_modules/ | ||
|
||
# TypeScript cache | ||
*.tsbuildinfo | ||
|
||
# Optional npm cache directory | ||
.npm | ||
|
||
# Optional eslint cache | ||
.eslintcache | ||
|
||
# Microbundle cache | ||
.rpt2_cache/ | ||
.rts2_cache_cjs/ | ||
.rts2_cache_es/ | ||
.rts2_cache_umd/ | ||
|
||
# Optional REPL history | ||
.node_repl_history | ||
|
||
# Output of 'npm pack' | ||
*.tgz | ||
|
||
# Yarn Integrity file | ||
.yarn-integrity | ||
|
||
# dotenv environment variables file | ||
.env | ||
.env.test | ||
|
||
# parcel-bundler cache (https://parceljs.org/) | ||
.cache | ||
.parcel-cache | ||
|
||
# Next.js build output | ||
.next | ||
out | ||
.idea | ||
# Nuxt.js build / generate output | ||
.nuxt | ||
dist | ||
|
||
# Gatsby files | ||
.cache/ | ||
# Comment in the public line in if your project uses Gatsby and not Next.js | ||
# https://nextjs.org/blog/next-9-1#public-directory-support | ||
# public | ||
|
||
# vuepress build output | ||
.vuepress/dist | ||
|
||
# Serverless directories | ||
.serverless/ | ||
|
||
# FuseBox cache | ||
.fusebox/ | ||
|
||
# DynamoDB Local files | ||
.dynamodb/ | ||
|
||
# TernJS port file | ||
.tern-port | ||
|
||
# Stores VSCode versions used for testing VSCode extensions | ||
.vscode-test | ||
|
||
# yarn v2 | ||
.yarn/cache | ||
.yarn/unplugged | ||
.yarn/build-state.yml | ||
.yarn/install-state.gz | ||
.pnp.* | ||
|
||
####################################################################################### | ||
## terraform | ||
####################################################################################### | ||
# Local .terraform directories | ||
**/.terraform/* | ||
|
||
# .tfstate files | ||
*.tfstate | ||
*.tfstate.* | ||
|
||
# Crash log files | ||
crash.log | ||
crash.*.log | ||
|
||
# Exclude all .tfvars files, which are likely to contain sensitive data, such as | ||
# password, private keys, and other secrets. These should not be part of version | ||
# control as they are data points which are potentially sensitive and subject | ||
# to change depending on the environment. | ||
*.tfvars | ||
*.tfvars.json | ||
|
||
# Ignore override files as they are usually used to override resources locally and so | ||
# are not checked in | ||
override.tf | ||
override.tf.json | ||
*_override.tf | ||
*_override.tf.json | ||
|
||
# Include override files you do wish to add to version control using negated pattern | ||
# !example_override.tf | ||
|
||
# Include tfplan files to ignore the plan output of command: terraform plan -out=tfplan | ||
# example: *tfplan* | ||
|
||
# Ignore CLI configuration files | ||
.terraformrc | ||
terraform.rc | ||
|
||
# Mac make this file | ||
.DS_Store | ||
|
||
|
||
layers | ||
cdktf.out | ||
cdktf.log | ||
.gen | ||
tsconfig.tsbuildinfo | ||
!jest.config.js | ||
!setup.js |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
# arc-cdk-template | ||
|
||
This repository holds files that will be scaffolded by sourceloop cli on `sl cdk --iac={iac_name} --dir={dir_name} --pj={package_json_name}` |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
AWS_REGION= | ||
AWS_ACCESS_KEY_ID= | ||
AWS_SECRET_ACCESS_KEY= | ||
AWS_ROLE_ARN= | ||
AWS_PROFILE= | ||
SUBNET_IDS= | ||
SECURITY_GROUPS= | ||
ACM_CERTIFICATE_ARN= | ||
HOSTED_ZONE_ID= | ||
DOMAIN_NAME= | ||
NAMESPACE= | ||
ENV= | ||
S3_BUCKET= |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,47 @@ | ||
# Stage 1: Build Stage | ||
FROM node:18 AS BUILD_STAGE | ||
|
||
# Set to a non-root built-in user `node` | ||
USER node | ||
|
||
# Create app directory (with user `node`) | ||
RUN mkdir -p /home/node/app | ||
|
||
# Set the working directory | ||
WORKDIR /home/node/app | ||
|
||
# Install app dependencies | ||
# A wildcard is used to ensure both package.json AND package-lock.json are copied | ||
# where available (npm@5+) | ||
COPY --chown=node package*.json ./ | ||
|
||
# Installing all dependencies | ||
RUN npm install | ||
|
||
# Copy files needed for the app build | ||
COPY --chown=node src ./src | ||
COPY --chown=node public ./public | ||
COPY --chown=node tsconfig.json ./ | ||
|
||
# Run Build Command | ||
RUN npm run build | ||
|
||
# Run node-prune | ||
RUN npm prune --production | ||
|
||
# Stage 2: Final Image | ||
|
||
# Check out https://hub.docker.com/_/node to select a new base image | ||
FROM public.ecr.aws/lambda/nodejs:18-x86_64 | ||
|
||
# Create app directory | ||
RUN mkdir -p ${LAMBDA_TASK_ROOT} | ||
|
||
WORKDIR ${LAMBDA_TASK_ROOT} | ||
|
||
# Copy runtime artifacts from the build stage | ||
COPY --from=BUILD_STAGE /home/node/app/node_modules ./node_modules | ||
COPY --from=BUILD_STAGE /home/node/app/dist ./dist | ||
COPY --from=BUILD_STAGE /home/node/app/public ./public | ||
|
||
CMD [ "./dist/lambda.handler" ] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,71 @@ | ||
# CDK Module For Lambda | ||
|
||
We can use the Cloud Development Kit for Terraform (CDKTF) to define advanced deployment configurations. | ||
|
||
CDKTF stacks let us manage multiple Terraform configurations in the same CDKTF application. They can save us from writing repetitive CDKTF code, while allowing us to independently manage the resources in each stack. we can also use the outputs of one stack as inputs for another. | ||
|
||
## Getting Started | ||
|
||
1. Create a dot env file: | ||
|
||
```shell | ||
touch .env | ||
``` | ||
|
||
3. Configure the following keys in the `.env` file: | ||
|
||
- **AWS_REGION**: _aws_region_ | ||
- **AWS_ACCESS_KEY_ID**: _aws_access_key_ | ||
- **AWS_SECRET_ACCESS_KEY**: _aws_secret_key_ | ||
- **AWS_ROLE_ARN**: _role_arn_ | ||
- **AWS_PROFILE**: _aws_profile_ | ||
- **SUBNET_IDS**: _subnet ids eg ["subnet-012", "subnet-123"]_ | ||
- **SECURITY_GROUPS**: _security group ids eg ["sg-123"]_ | ||
- **DB_HOST**: _Postgres Database host_ | ||
- **DB_PORT**: _Postgres Database port_ | ||
- **DB_USER**: _database username_ | ||
- **DB_PASSWORD**: _database password_ | ||
- **DB_DATABASE**: _database name_ | ||
- **DB_SCHEMA**: _database schema_ | ||
- **JWT_SECRET**: _For JWT token_ | ||
- **ACM_CERTIFICATE_ARN**: _ARN for ACM certificate_ | ||
- **HOSTED_ZONE_ID**: _Route53 hosted zone id_ | ||
- **DOMAIN_NAME**: _custom domain name for api gateway_ | ||
|
||
Note: if You want to use _ **AWS_ACCESS_KEY_ID** and _ **AWS_SECRET_ACCESS_KEY** then keep | ||
|
||
- **AWS_PROFILE** as blank. | ||
|
||
3. Run _npm install_ to install the dependency packages for cdktf. Now you are ready to go with cdktf commands. | ||
|
||
## How to Run | ||
|
||
This module gives us several commands for the aws lambda function. | ||
|
||
- Download all required providers and modules. | ||
```shell | ||
cdktf get | ||
``` | ||
- List all the stacks defined in your CDKTF application. | ||
```shell | ||
cdktf list | ||
``` | ||
- To deploy the sourceloop audit in lambda on aws and remember to confirm the deploy with a yes._(Make sure to run npm run build:layers in root folder to create required lambda layers and npm run build to build the project)_ | ||
```shell | ||
cdktf deploy lambda | ||
``` | ||
- To deploy and run the migration for sourceloop audit in lambda on aws and remember to confirm the deploy with a yes._(Make sure to run npm run build:migrations in root folder to create required migrations files)_ | ||
|
||
```shell | ||
cdktf deploy migration | ||
``` | ||
|
||
- To deploy lambda and migration stack on aws and remember to confirm the deploy with a yes. | ||
```shell | ||
cdktf deploy '*' | ||
``` | ||
- To destroy the Infrastructure that you deployed on aws. | ||
```shell | ||
cdktf destroy lambda | ||
cdktf destroy migration | ||
``` |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
{ | ||
"language": "typescript", | ||
"app": "npx ts-node src/main.ts", | ||
"codeMakerOutput": "src/.gen", | ||
"projectId": "7da9330e-d08e-43cb-967a-62f41d6fac01", | ||
"sendCrashReports": "false", | ||
"terraformProviders": [], | ||
"terraformModules": [], | ||
"context": { | ||
"excludeStackIdFromLogicalIds": "true", | ||
"allowSepCharsInLogicalIds": "true" | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,51 @@ | ||
======================================================================================================== | ||
|
||
Your cdktf typescript project is ready! | ||
|
||
cat help Print this message | ||
|
||
Compile: | ||
npm run get Import/update Terraform providers and modules (you should check-in this directory) | ||
npm run compile Compile typescript code to javascript (or "npm run watch") | ||
npm run watch Watch for changes and compile typescript in the background | ||
npm run build Compile typescript | ||
|
||
Synthesize: | ||
cdktf synth [stack] Synthesize Terraform resources from stacks to cdktf.out/ (ready for 'terraform apply') | ||
|
||
Diff: | ||
cdktf diff [stack] Perform a diff (terraform plan) for the given stack | ||
|
||
Deploy: | ||
cdktf deploy [stack] Deploy the given stack | ||
|
||
Destroy: | ||
cdktf destroy [stack] Destroy the stack | ||
|
||
Test: | ||
npm run test Runs unit tests (edit __tests__/main-test.ts to add your own tests) | ||
npm run test:watch Watches the tests and reruns them on change | ||
|
||
Upgrades: | ||
npm run upgrade Upgrade cdktf modules to latest version | ||
npm run upgrade:next Upgrade cdktf modules to latest "@next" version (last commit) | ||
|
||
Use Providers: | ||
|
||
You can add prebuilt providers (if available) or locally generated ones using the add command: | ||
|
||
cdktf provider add "aws@~>3.0" null kreuzwerker/docker | ||
|
||
You can find all prebuilt providers on npm: https://www.npmjs.com/search?q=keywords:cdktf | ||
You can also install these providers directly through npm: | ||
|
||
npm install @cdktf/provider-aws | ||
npm install @cdktf/provider-google | ||
npm install @cdktf/provider-azurerm | ||
npm install @cdktf/provider-docker | ||
npm install @cdktf/provider-github | ||
npm install @cdktf/provider-null | ||
|
||
You can also build any module or provider locally. Learn more https://cdk.tf/modules-and-providers | ||
|
||
======================================================================================================== |
Oops, something went wrong.