Skip to content

Commit 1042da0

Browse files
Merge pull request #73 from sourcefuse/ecs-service
Adding an EC2 instance type to the ECS module
2 parents 701d52a + 211fc7c commit 1042da0

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

47 files changed

+1438
-791
lines changed

.gitignore

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
.terraform
22
terraform.tfstate
33
*.tfstate*
4-
terraform.tfvars
54
*.backup
65
secrets.tfvars
76
.idea

README.md

Lines changed: 50 additions & 33 deletions
Large diffs are not rendered by default.

docs/module-usage-guide/README.md

Lines changed: 25 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -27,11 +27,33 @@ Before using this module, ensure you have the following:
2727
To use the module in your Terraform configuration, include the following source block:
2828

2929
```hcl
30+
31+
##########################################
32+
## ecs cluster with ec2
33+
##########################################
3034
module "arc-ecs" {
3135
source = "sourcefuse/arc-ecs/aws"
3236
version = "1.5.0"
33-
# insert the 6 required variables here
37+
ecs_cluster = local.ecs_cluster
38+
capacity_provider = local.capacity_provider
39+
ecs_service = local.ecs_service
40+
launch_template = local.launch_template
41+
asg = local.asg
42+
tags = module.tags.tags
43+
}
44+
45+
##########################################
46+
## ecs cluster with fargate
47+
##########################################
48+
module "ecs_cluster" {
49+
source = "sourcefuse/arc-ecs/aws"
50+
version = "1.5.0"
51+
ecs_cluster = local.ecs_cluster
52+
capacity_provider = local.capacity_provider
53+
ecs_service = local.ecs_service
54+
tags = module.tags.tags
3455
}
56+
3557
```
3658

3759
Refer to the [Terraform Registry](https://registry.terraform.io/modules/sourcefuse/arc-ecs/aws/latest) for the latest version.
@@ -41,7 +63,7 @@ Refer to the [Terraform Registry](https://registry.terraform.io/modules/sourcefu
4163
Integrate the module with your existing Terraform mono repo configuration, follow the steps below:
4264

4365
1. Create a new folder in `terraform/` named `ecs`.
44-
2. Create the required files, see the [examples](https://github.com/sourcefuse/terraform-aws-arc-ecs/tree/main/example) to base off of.
66+
2. Create the required files, see the [examples](https://github.com/sourcefuse/terraform-aws-arc-ecs/tree/main/examples) to base off of.
4567
3. Configure with your backend
4668
- Create the environment backend configuration file: `config.<environment>.hcl`
4769
- **region**: Where the backend resides
@@ -74,7 +96,7 @@ For a list of outputs, see the README [Outputs](https://github.com/sourcefuse/te
7496

7597
### Basic Usage
7698

77-
For basic usage, see the [example](https://github.com/sourcefuse/terraform-aws-arc-ecs/tree/main/example) folder.
99+
For basic usage, see the [example](https://github.com/sourcefuse/terraform-aws-arc-ecs/tree/main/examples) folder.
78100

79101
This example will create:
80102

example/main.tf

Lines changed: 0 additions & 112 deletions
This file was deleted.

examples/ecs-ec2/.terraform.lock.hcl

Lines changed: 25 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.
Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
[
2+
{
3+
"name": "${service_name_full}",
4+
"image": "${repository_name}:${environment}",
5+
"essential": true,
6+
"portMappings": [
7+
{
8+
"hostPort": ${alb_port},
9+
"protocol": "tcp",
10+
"containerPort": ${container_port}
11+
}
12+
],
13+
"healthCheck": {
14+
"command": [
15+
"CMD-SHELL",
16+
"curl --fail http://localhost:80 || exit 1"
17+
],
18+
"interval": 30,
19+
"timeout": 5,
20+
"retries": 3,
21+
"startPeriod": 15
22+
},
23+
"environment": ${environment_vars},
24+
"secrets" : ${secrets},
25+
"compatibilities": [
26+
"EC2"
27+
],
28+
"logConfiguration": {
29+
"logDriver": "awslogs",
30+
"options": {
31+
"awslogs-group": "${log_group_name}",
32+
"awslogs-region": "${aws_region}",
33+
"awslogs-stream-prefix" : "ecs"
34+
}
35+
}
36+
}
37+
]

examples/ecs-ec2/data.tf

Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
# network
2+
data "aws_vpc" "default" {
3+
filter {
4+
name = "tag:Name"
5+
values = var.vpc_name != null ? [var.vpc_name] : ["${var.namespace}-${var.environment}-vpc"]
6+
}
7+
}
8+
9+
data "aws_subnets" "private" {
10+
filter {
11+
name = "tag:Name"
12+
13+
## try the created subnets from the upstream network module, or override with custom names
14+
values = length(var.subnet_names) > 0 ? var.subnet_names : [
15+
"${var.namespace}-${var.environment}-private-subnet-private-${var.region}a",
16+
"${var.namespace}-${var.environment}-private-subnet-private-${var.region}b"
17+
]
18+
}
19+
filter {
20+
name = "vpc-id"
21+
values = [data.aws_vpc.default.id]
22+
}
23+
}
24+
25+
data "aws_ami" "amazon_linux" {
26+
most_recent = true
27+
28+
filter {
29+
name = "name"
30+
values = ["amzn2-ami-hvm-*-x86_64-gp2"]
31+
}
32+
33+
filter {
34+
name = "virtualization-type"
35+
values = ["hvm"]
36+
}
37+
38+
owners = ["amazon"]
39+
}

0 commit comments

Comments
 (0)