Skip to content

HashiCorp's Cloud Development Kit for Terraform with Amazon ECS and Consul

License

Notifications You must be signed in to change notification settings

jcolemorrison/cdktf-ecs-consul

Repository files navigation

CDK for Terraform with Amazon ECS and Consul

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:

  1. Terraform with Amazon ECS and Consul
  • 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.
  1. Sentinel Policies for Terraform with Amazon ECS and Consul

The Architecture

Terraform with Amazon ECS and Consul

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.

Getting Started

For this you'll need 5 things:

  • AWS Account and Credentials
  • Terraform
  • Terraform Cloud Account
  • Node.js
  • CDKTF

Instructions below:

1. AWS Account and Credentials

AWS is used to host the infrastructure. Surprise.

  1. Have an AWS Account.

  2. Have the AWS CLI Installed.

  3. Create an AWS IAM User with Admin or Power User Permissions.

  • this user will only be used locally
  1. Configure the AWS CLI with the IAM User from Step 4.

2. Terraform, Terraform Cloud, and the CDK for Terraform

Terraform and CDKT for Terraform are used to provision the infrastructure. Terraform Cloud (free) is used to manage your state.

  1. Install HashiCorp Terraform.

  2. Install Node.js.

  3. Install the CDK for Terraform

  4. Sign up for Terraform Cloud

  • yo its free for 5 team members
  1. Create a Terraform Cloud Organization

  2. Log in to Terraform Cloud from the CLI

  • this will set the credentials locally for the CDKTF to work with it
  1. 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"

Deploying the Project

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:

  1. Create a Workspace in Terraform Cloud for this project named the same thing as your tfc_workspace in main.ts.

  2. Connect this Repository to the newly created workspace.

  3. Trigger a Run to Plan and Apply Infrastructure.

  4. Connect to the client_endpoint output in your Terraform with Amazon ECS and Consul Project deployment to see if the service is live.

For Local Development

  1. Run npm i to install all dependencies.

  2. Run cdktf get to grab all modules.

About

HashiCorp's Cloud Development Kit for Terraform with Amazon ECS and Consul

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published