forked from DNXLabs/terraform-aws-ecs-app
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathdeployment.tf
49 lines (42 loc) · 1.61 KB
/
deployment.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
46
47
48
49
# The primary use-case for the null resource is as a do-nothing container
# for arbitrary actions taken by a provisioner.
resource "null_resource" "codedeploy_deployment" {
count = var.deployment_controller == "CODE_DEPLOY" ? 1 : 0
depends_on = [aws_codedeploy_app.ecs, aws_ecs_task_definition.default]
# Changes to any instance of the cluster requires re-provisioning
triggers = {
image = var.image
task_definition_arn = aws_ecs_task_definition.default[0].arn
}
provisioner "local-exec" {
command = <<-EOT
aws configure set default.region ${data.aws_region.current.name} && \
aws deploy create-deployment \
--application-name ${aws_codedeploy_app.ecs[0].name} \
--deployment-group-name ${var.name} \
--deployment-config-name CodeDeployDefault.ECSAllAtOnce \
--description DeploymentFromTerraform || \
echo "Deployment already in progress"
EOT
}
}
resource "null_resource" "fargate_deployment" {
count = var.deployment_controller == "ECS" ? 1 : 0
depends_on = [aws_ecs_task_definition.default]
# Changes to any instance of the cluster requires re-provisioning
triggers = {
image = var.image
task_definition_arn = aws_ecs_task_definition.default[0].arn
}
provisioner "local-exec" {
command = <<-EOT
aws configure set default.region ${data.aws_region.current.name} && \
aws ecs update-service \
--service ${var.name} \
--cluster ${var.cluster_name} \
--task-definition ${aws_ecs_task_definition.default[0].arn} \
--force-new-deployment || \
echo "Deployment already in progress"
EOT
}
}