This repository was created for demo purposes and will not be kept up-to-date with future releases of CDK for Terraform (CDKTF); as such, it has been archived and is no longer supported in any way by HashiCorp. You are welcome to try out the archived version of the code in this example project, but there are no guarantees that it will continue to work with newer versions of CDKTF. We do not recommend directly using this sample code in production projects without extensive testing, and HashiCorp disclaims any and all liability resulting from use of this code.
This project creates a microservice architecture on AWS ECS Fargate using the CDK for Terraform. It seeks to follow a familiar pattern used by vanilla Terraform projects - flat file structure, declarative paradigm, and simplicity.
Note: The architecture mentions DataDog for monitoring which was removed from this example for simplicity reasons – you can find this in the source repository.
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
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"
-
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.