This repository demonstrates setting up an Amazon ECS microservices architecture with HashiCorp's Cloud Development Kit for Terraform (CDKTF) and Consul. It also goes along with two other repositories:
- deploys the core infrastructure that supports this project. It's referenced as teh "parent workspace" or "parent" project throughout this code.
- you must deploy this FIRST before using this project...or else....
- ...nothing will happen.
- creates HashiCorp Sentinel Policies to guard both projects in Terraform Cloud
All services use Fake Service as for demonstration purposes. 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 5 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
- Change the TFC Variables in
main.ts
to reflect the names of your Organization and Workspaces:
// Change these to match your Terraform Cloud Org and Workspaces
const tfc_organization = "jcolemorrison"
// parent workspace with main Terraform configuration
const tfc_parent_workspace = "tf-ecs-consul"
// this workspace
const tfc_workspace = "cdktf-ecs-consul"
First and foremost, you MUST deploy the associated Terraform with Amazon ECS and Consul Project before deploying this one as this project depends on it. Have you done that? Good, now you can deploy this project:
-
Create a Workspace in Terraform Cloud for this project named the same thing as your
tfc_workspace
inmain.ts
. -
Connect to the
client_endpoint
output in your Terraform with Amazon ECS and Consul Project deployment to see if the service is live.
-
Run
npm i
to install all dependencies. -
Run
cdktf get
to grab all modules.