Skip to content

Commit

Permalink
ECS Cluster (#9)
Browse files Browse the repository at this point in the history
* ecs cluster

* ecs test code

* version
  • Loading branch information
AJarombek authored Jan 13, 2024
1 parent 86db7e9 commit ef8c8fc
Show file tree
Hide file tree
Showing 7 changed files with 184 additions and 43 deletions.
53 changes: 30 additions & 23 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -96,32 +96,39 @@ repositories are referenced in separate directories and README.md files.

### Directories

| Directory Name | Description |
|----------------------|-----------------------------------------------------------------------------|
| `.github` | GitHub Actions for CI/CD pipelines. |
| `acm` | HTTPS certificates for the `jarombek.io` applications. |
| `api-gateway` | Global API Gateway configuration. |
| `apps` | Infrastructure for individual applications. |
| `backend` | The Terraform backend, consisting of an S3 bucket. |
| `budgets` | Terraform scripts for setting AWS account budgets. |
| `cloud-trail` | Terraform scripts for AWS account auditing with CloudTrail. |
| `config` | Terraform scripts for AWS Config. |
| `dockerfiles` | Reusable dockerfiles used throughout my infrastructure. |
| `eks-v2` | Terraform and Kubernetes configuration for an EKS v2 cluster. |
| `file-vault` | Terraform scripts for an S3 bucket that serves as a vault for secure files. |
| `lambda` | Terraform scripts for AWS Lambda functions. |
| `lambda-layers` | AWS Lambda Layer source code and Terraform scripts. |
| `parameter-store` | Terraform scripts for System Manager Parameter Store secrets. |
| `root` | Root Terraform scripts for creating the accounts VPCs. |
| `route53` | Terraform scripts for creating DNS records for the account. |
| `s3` | Terraform scripts for global S3 assets. |
| `secrets-manager` | Terraform scripts for global secrets stored in Secrets Manager. |
| `sns` | Terraform scripts for AWS SNS notifications. |
| `test` | Python AWS infrastructure test suite. |
| `test-k8s` | Go Kubernetes infrastructure test suite. |
| Directory Name | Description |
|-------------------|-----------------------------------------------------------------------------|
| `.github` | GitHub Actions for CI/CD pipelines. |
| `acm` | HTTPS certificates for the `jarombek.io` applications. |
| `api-gateway` | Global API Gateway configuration. |
| `apps` | Infrastructure for individual applications. |
| `backend` | The Terraform backend, consisting of an S3 bucket. |
| `budgets` | Terraform scripts for setting AWS account budgets. |
| `cloud-trail` | Terraform scripts for AWS account auditing with CloudTrail. |
| `config` | Terraform scripts for AWS Config. |
| `dockerfiles` | Reusable dockerfiles used throughout my infrastructure. |
| `ecs` | Terraform configuration for an ECS cluster. |
| `eks-v2` | Terraform and Kubernetes configuration for an EKS v2 cluster. |
| `file-vault` | Terraform scripts for an S3 bucket that serves as a vault for secure files. |
| `lambda` | Terraform scripts for AWS Lambda functions. |
| `lambda-layers` | AWS Lambda Layer source code and Terraform scripts. |
| `parameter-store` | Terraform scripts for System Manager Parameter Store secrets. |
| `root` | Root Terraform scripts for creating the accounts VPCs. |
| `route53` | Terraform scripts for creating DNS records for the account. |
| `s3` | Terraform scripts for global S3 assets. |
| `secrets-manager` | Terraform scripts for global secrets stored in Secrets Manager. |
| `sns` | Terraform scripts for AWS SNS notifications. |
| `test` | Python AWS infrastructure test suite. |
| `test-k8s` | Go Kubernetes infrastructure test suite. |

### Versions

**[v2.1.4](https://github.com/AJarombek/global-aws-infrastructure/tree/v2.1.4) - ECS Cluster**

> Release Date: January 13th, 2024
+ Added an ECS Cluster and corresponding tests.

**[v2.1.3](https://github.com/AJarombek/global-aws-infrastructure/tree/v2.1.3) - Remove Jenkins Infrastructure**

> Release Date: December 23rd, 2023
Expand Down
25 changes: 25 additions & 0 deletions ecs/.terraform.lock.hcl

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

25 changes: 25 additions & 0 deletions ecs/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
### Overview

Terraform infrastructure for building an ECS cluster.

### Commands

**Build the Infrastructure**

```bash
# Create the infrastructure.
terraform init
terraform validate
terraform plan -detailed-exitcode -out=terraform-prod.tfplan
terraform apply -auto-approve terraform-prod.tfplan

# Destroy the infrastructure.
terraform plan -destroy
terraform destroy -auto-approve
```

### Files

| Filename | Description |
|------------|----------------------------------------------|
| `main.tf` | Terraform configuration for the ECS cluster. |
44 changes: 44 additions & 0 deletions ecs/main.tf
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
/**
* Infrastructure for creating an ECS cluster for my small applications.
* Author: Andrew Jarombek
* Date: 1/13/2024
*/

provider "aws" {
region = "us-east-1"
}

terraform {
required_version = "~> 1.6.6"

required_providers {
aws = "~> 5.32.1"
}

backend "s3" {
bucket = "andrew-jarombek-terraform-state"
encrypt = true
key = "global-aws-infrastructure/ecs"
region = "us-east-1"
}
}

locals {
terraform_tag = "global-aws-infrastructure/ecs"
}

resource "aws_ecs_cluster" "andrew-jarombek" {
name = "andrew-jarombek-cluster"

setting {
name = "containerInsights"
value = "enabled"
}

tags = {
Name = "andrew-jarombek-cluster"
Application = "all"
Environment = "all"
Terraform = local.terraform_tag
}
}
7 changes: 4 additions & 3 deletions eks-v2/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -37,9 +37,10 @@ kubectl logs -f my-pod-name -n my-namespace

### Files

| Filename | Description |
|------------|------------------------------------------------|
| `main.tf` | Terraform configuration for the EKS cluster. |
| Filename | Description |
|----------------------------|----------------------------------------------|
| `main.tf` | Terraform configuration for the EKS cluster. |
| `external-dns-policy.json` | AWS IAM Policy for External DNS. |

### Resources

Expand Down
35 changes: 18 additions & 17 deletions test/suites/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,20 +5,21 @@ repository.

### Files

| Filename | Description |
|----------------------------|--------------------------------------------------------------------------------------|
| `testApplicationVPC.py` | Test suite for the Application VPC. |
| `testBackend.py` | Test suite for the Terraform S3 Backend. |
| `testBudgets.py` | Test suite for AWS cost management budgets. |
| `testCloudTrail.py` | Test suite for AWS CloudTrail configuration. |
| `testConfig.py` | Test suite for AWS Config infrastructure. |
| `testEKS.py` | Test suite for the EKS cluster. |
| `testFileVault.py` | Test suite for a file vault S3 bucket. |
| `testJarombekComApp.py` | Test suite for the Amazon HTTPS certificates. |
| `testLambda.py` | Test suite for AWS Lambda functions. |
| `testLambdaLayers.py` | Test suite for reusable AWS Lambda layers. |
| `testRoot.py` | Test suite for the Root infrastructure for my AWS cloud. |
| `testRoute53.py` | Test suite for Route53 records used globally. |
| `testS3.py` | Test suite for a global S3 bucket. |
| `testSecretsManager.py` | Test suite for credentials stored in Secrets Manager. |
| `testSNS.py` | Test suite for SNS topics and subscriptions. |
| Filename | Description |
|-------------------------|----------------------------------------------------------|
| `testApplicationVPC.py` | Test suite for the Application VPC. |
| `testBackend.py` | Test suite for the Terraform S3 Backend. |
| `testBudgets.py` | Test suite for AWS cost management budgets. |
| `testCloudTrail.py` | Test suite for AWS CloudTrail configuration. |
| `testConfig.py` | Test suite for AWS Config infrastructure. |
| `testECS.py` | Test suite for the ECS cluster. |
| `testEKS.py` | Test suite for the EKS cluster. |
| `testFileVault.py` | Test suite for a file vault S3 bucket. |
| `testJarombekComApp.py` | Test suite for the Amazon HTTPS certificates. |
| `testLambda.py` | Test suite for AWS Lambda functions. |
| `testLambdaLayers.py` | Test suite for reusable AWS Lambda layers. |
| `testRoot.py` | Test suite for the Root infrastructure for my AWS cloud. |
| `testRoute53.py` | Test suite for Route53 records used globally. |
| `testS3.py` | Test suite for a global S3 bucket. |
| `testSecretsManager.py` | Test suite for credentials stored in Secrets Manager. |
| `testSNS.py` | Test suite for SNS topics and subscriptions. |
38 changes: 38 additions & 0 deletions test/suites/testECS.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
"""
Unit tests for the ECS cluster.
Author: Andrew Jarombek
Date: 1/13/2024
"""

import unittest

import boto3
from boto3_type_annotations.ecs import Client as ECSClient
from boto3_type_annotations.sts import Client as STSClient


class TestECS(unittest.TestCase):
def setUp(self) -> None:
"""
Perform set-up logic before executing any unit tests
"""
self.ecs: ECSClient = boto3.client("ecs")
self.sts: STSClient = boto3.client("sts")

def test_eks_cluster_exists(self) -> None:
"""
Determine if the EKS cluster exists as expected.
"""
cluster_name = "andrew-jarombek-ecs-cluster"
account_id = self.sts.get_caller_identity().get("Account")
clusters = self.ecs.describe_clusters(clusters=[cluster_name])

self.assertEqual(1, len(clusters.get("clusters")))

cluster = clusters.get("clusters")[0]

self.assertEqual(
f"arn:aws:ecs:us-east-1:{account_id}:cluster/{cluster_name}",
cluster.get("clusterArn"),
)
self.assertEqual(cluster_name, cluster.get("clusterName"))

0 comments on commit ef8c8fc

Please sign in to comment.