forked from mongodb/terraform-aws-ecs-task-definition
-
Notifications
You must be signed in to change notification settings - Fork 0
/
ecs_update_service.tf
45 lines (38 loc) · 1.2 KB
/
ecs_update_service.tf
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
# This configuration demonstrates forcing the new deployment of an ECS
# service if there is a change to the ECS task definition. The
# configuration uses the `null_resource` provider to invoke the
# `local-exec` provisioner whenever the task definition ARN changes.
#
# To force a new deployment even if there are no changes made to the
# task definition, `taint` the resource:
#
# $ terraform taint null_resource.update-service
provider "aws" {
region = "us-east-1"
version = "~> 2.0"
}
module "mongo-task-definition" {
source = "github.com/mongodb/terraform-aws-ecs-task-definition"
family = "mongo"
image = "mongo:3.6"
memory = 512
name = "mongo"
portMappings = [
{
containerPort = 27017
},
]
}
resource "aws_ecs_service" "mongo" {
cluster = "mongo"
name = "mongo"
task_definition = module.mongo-task-definition.arn
}
resource "null_resource" "update-service" {
triggers = {
arn = module.mongo-task-definition.arn
}
provisioner "local-exec" {
command = "aws ecs update-service --cluster ${aws_ecs_service.mongo.cluster} --service ${aws_ecs_service.mongo.name} --task-definition ${module.mongo-task-definition.arn} --force-new-deployment"
}
}