Skip to content

Commit ef1ce4d

Browse files
committed
feat(examples): add complete example
1 parent 3ff28b8 commit ef1ce4d

File tree

5 files changed

+154
-0
lines changed

5 files changed

+154
-0
lines changed

examples/complete/README.md

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
# ECS EC2 Complete
2+
3+
Configuration in this directory creates:
4+
5+
- ECS Cluster using self-managed EC2
6+
- ECS Service configured for running Tasks on self-managed EC2
7+
8+
## Usage
9+
10+
To run this example, you will need to execute the commands:
11+
12+
```bash
13+
terraform init
14+
terraform plan
15+
terraform apply
16+
```
17+
18+
Please note that this example may create resources that can incur monetary charges on your AWS bill. You can run `terraform destroy` when you no longer need the resources.

examples/complete/main.tf

Lines changed: 69 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,69 @@
1+
provider "aws" {
2+
region = local.region
3+
4+
default_tags {
5+
tags = local.default_tags
6+
}
7+
}
8+
9+
locals {
10+
region = "ap-south-1"
11+
name_prefix = "ex-"
12+
13+
# VPC
14+
vpc_cidr = "10.0.0.0/16"
15+
vpc_azs = ["ap-south-1a", "ap-south-1b"]
16+
vpc_private_subnets = ["10.0.1.0/24", "10.0.2.0/24"]
17+
vpc_public_subnets = ["10.0.11.0/24", "10.0.12.0/24"]
18+
19+
# ECS Cluster
20+
cluster_name = "${local.name_prefix}my-cluster"
21+
22+
# ECS Service
23+
service_name = "${local.name_prefix}my-service"
24+
service_task_resource_allocation = {
25+
cpu = 512
26+
memory = 512
27+
}
28+
29+
default_tags = {
30+
Environment = "Dev"
31+
ManagedBy = "Terraform"
32+
}
33+
}
34+
35+
################################################################################
36+
# ECS EC2 Module
37+
################################################################################
38+
39+
module "ecs_ec2" {
40+
source = "../../"
41+
42+
# Cluster
43+
cluster_name = local.cluster_name
44+
45+
# Services
46+
service_name = local.service_name
47+
service_subnet_ids = flatten([module.vpc.private_subnets, module.vpc.public_subnets])
48+
service_cpu = local.service_task_resource_allocation.cpu
49+
service_memory = local.service_task_resource_allocation.memory
50+
}
51+
52+
################################################################################
53+
# Supporting Resources
54+
################################################################################
55+
56+
module "vpc" {
57+
source = "terraform-aws-modules/vpc/aws"
58+
version = "~> 5.9.0"
59+
60+
name = "${local.name_prefix}my-vpc"
61+
cidr = local.vpc_cidr
62+
63+
azs = local.vpc_azs
64+
private_subnets = local.vpc_private_subnets
65+
public_subnets = local.vpc_public_subnets
66+
67+
enable_nat_gateway = true
68+
enable_vpn_gateway = false
69+
}

examples/complete/outputs.tf

Lines changed: 57 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,57 @@
1+
################################################################################
2+
# VPC
3+
################################################################################
4+
5+
output "vpc_id" {
6+
description = "Identifier of the VPC"
7+
value = module.vpc.vpc_id
8+
}
9+
10+
output "vpc_cidr_block" {
11+
description = "CIDR Block of the VPC"
12+
value = module.vpc.vpc_cidr_block
13+
}
14+
15+
output "private_subnets" {
16+
description = "Identifiers of the Private Subnets"
17+
value = module.vpc.private_subnets
18+
}
19+
20+
output "private_subnets_arns" {
21+
description = "ARNs of the Private Subnets"
22+
value = module.vpc.private_subnet_arns
23+
}
24+
25+
output "private_subnets_cidr_blocks" {
26+
description = "CIDR Blocks of the Private Subnets"
27+
value = module.vpc.private_subnets_cidr_blocks
28+
}
29+
30+
output "public_subnets" {
31+
description = "Identifiers of the Public Subnets"
32+
value = module.vpc.public_subnets
33+
}
34+
35+
output "public_subnets_arns" {
36+
description = "ARNs of the Public Subnets"
37+
value = module.vpc.public_subnet_arns
38+
}
39+
40+
output "public_subnets_cidr_blocks" {
41+
description = "CIDR Blocks of the Public Subnets"
42+
value = module.vpc.public_subnets_cidr_blocks
43+
}
44+
45+
################################################################################
46+
# ECS EC2 Module
47+
################################################################################
48+
49+
output "ecs_cluster_arn" {
50+
description = "ARN of the ECS Cluster"
51+
value = module.ecs_ec2.cluster_arn
52+
}
53+
54+
output "ecs_service_id" {
55+
description = "Identifier of the ECS Service"
56+
value = module.ecs_ec2.service_id
57+
}

examples/complete/variables.tf

Whitespace-only changes.

examples/complete/versions.tf

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
terraform {
2+
required_version = ">= 1.4.6"
3+
4+
required_providers {
5+
aws = {
6+
source = "hashicorp/aws"
7+
version = ">= 5.57.0"
8+
}
9+
}
10+
}

0 commit comments

Comments
 (0)