This project creates a microservice architecture on AWS ECS Fargate with Datadog monitoring using the CDK for Terraform. It seeks to follow a familiar pattern used by vanilla Terraform projects - flat file structure, declarative paradigm, and simplicity.
All services use Fake Service as placeholders. You can swap them out with your own containerized services. You will need to change around port configurations and security groups to afford your applications' needs.
For this you'll need 4 things:
- AWS Account and Credentials
- Terraform
- Terraform Cloud Account
- Node.js
- CDKTF
- Datadog Account and Credentials
Instructions below:
AWS is used to host the infrastructure. Surprise.
-
Have an AWS Account.
-
Have the AWS CLI Installed.
-
Create an AWS IAM User with Admin or Power User Permissions.
- this user will only be used locally
- Configure the AWS CLI with the IAM User from Step 4.
- Terraform will read your credentials via the AWS CLI
- Other Authentication Methods with AWS and Terraform
Terraform and CDKT for Terraform are used to provision the infrastructure. Terraform Cloud (free) is used to manage your state.
-
Install HashiCorp Terraform.
-
Install Node.js.
-
Install the CDK for Terraform
-
Sign up for Terraform Cloud
- yo its free for 5 team members
-
Create a Terraform Cloud Organization
-
Log in to Terraform Cloud from the CLI
- this will set the credentials locally for the CDKTF to work with it
- Export your Terraform Cloud Organization name as an environment variable:
# Don't forget to set this! Used in main.ts @line 153
$ export CDKTF_ECS_TFC_ORGANIZATION="your TFC organization name"
Datadog is used for monitoring and alerts across your ECS Cluster and Services.
-
Have a Datadog Account.
-
Export your Datadog API and APP Keys as Environment Variables.
# Keys found and created in app.datadoghq.com -> organization settings
# # -> api keys
# # -> application keys
$ export DD_API_KEY="<your_api_key>"
$ export DD_APP_KEY="<your_app_key>"
-
Clone this repo.
-
Run
npm i
to install all dependencies. -
Run
cdktf synth
to ensure no errors are occuring. -
Run
cdktf deploy
and accept the deployment. -
Grab the URL from your
client_service_endpoint
Terraform Output and visit it to see the application. -
Optionally add
/ui
to yourclient_service_endpoint
to see a visualization of your services. -
Optionally visit your Datadog account to see your monitor and dashboard for cluster CPU usage.