Skip to content

Commit 425cd18

Browse files
authored
Merge pull request #13 from tbobm/feat/allow-custom-taskdef
feat(taskdef): allow to use external ECS task def
2 parents 61905be + debc9ac commit 425cd18

File tree

4 files changed

+25
-1
lines changed

4 files changed

+25
-1
lines changed

README.md

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -55,6 +55,23 @@ module "ecr" {
5555
}
5656
```
5757

58+
### Use an external ECS Task definition
59+
60+
```hcl
61+
module "ecr" {
62+
source = "tbobm/ecs/aws"
63+
# version = "" use latest version
64+
65+
ecs_values = {
66+
ecs_task_arn = "arn:aws:ecs:<region>:<aws_account_id>:task-definition/<task_family>:1"
67+
}
68+
networking = {
69+
vpc_id = "vpc-xxxxxxxx"
70+
subnet_ids = ["subnet-xxxxxxxx"]
71+
}
72+
}
73+
```
74+
5875
## Doc generation
5976

6077
Code formatting and documentation for variables and outputs is generated using

ecs.tf

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,8 @@ resource "aws_ecs_cluster" "this" {
99
}
1010

1111
resource "aws_ecs_task_definition" "this" {
12+
count = lookup(local.ecs, "ecs_task_arn", "") != "" ? 0 : 1
13+
1214
family = "service"
1315
requires_compatibilities = [
1416
"FARGATE",
@@ -36,7 +38,7 @@ resource "aws_ecs_task_definition" "this" {
3638
resource "aws_ecs_service" "this" {
3739
name = local.ecs.service_name
3840
cluster = aws_ecs_cluster.this.id
39-
task_definition = aws_ecs_task_definition.this.arn
41+
task_definition = lookup(local.ecs, "ecs_task_arn", "") != "" ? local.ecs.ecs_task_arn : aws_ecs_task_definition.this.0.arn
4042
desired_count = 1
4143

4244
network_configuration {

examples/main.tf

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,10 @@ module "ecs" {
1010
subnet_ids = data.aws_subnet_ids.this.ids
1111
}
1212

13+
ecs_values = {
14+
ecs_task_arn = ""
15+
}
16+
1317
addons = {
1418
loadbalancer = {
1519
enable = true

locals.tf

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ locals {
88
ecs_defaults = {
99
cluster_name = "ecs-cluster"
1010
service_name = "ecs-service"
11+
ecs_task_arn = null
1112
}
1213
ecs = merge(local.ecs_defaults, var.ecs_values)
1314

0 commit comments

Comments
 (0)