-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* ecs cluster * ecs test code * version
- Loading branch information
Showing
7 changed files
with
184 additions
and
43 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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. | |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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")) |