This repository was archived by the owner on Jul 3, 2023. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 419
/
Copy pathmain.tf
114 lines (94 loc) · 2.54 KB
/
main.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
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
/**
* The worker module creates an ECS service that has no ELB attached.
*
* Usage:
*
* module "my_worker" {
* source = "github.com/segmentio/stack"
* environment = "prod"
* name = "worker"
* image = "worker"
* cluster = "default"
* }
*
*/
/**
* Required Variables.
*/
variable "environment" {
description = "Environment tag, e.g prod"
}
variable "image" {
description = "The docker image name, e.g nginx"
}
variable "name" {
description = "The worker name, if empty the service name is defaulted to the image name"
default = ""
}
variable "version" {
description = "The docker image version"
default = "latest"
}
variable "cluster" {
description = "The cluster name or ARN"
}
/**
* Options.
*/
variable "command" {
description = "The raw json of the task command"
default = "[]"
}
variable "env_vars" {
description = "The raw json of the task env vars"
default = "[]"
}
variable "desired_count" {
description = "The desired count"
default = 1
}
variable "memory" {
description = "The number of MiB of memory to reserve for the container"
default = 512
}
variable "cpu" {
description = "The number of cpu units to reserve for the container"
default = 512
}
variable "deployment_minimum_healthy_percent" {
description = "lower limit (% of desired_count) of # of running tasks during a deployment"
default = 100
}
variable "deployment_maximum_percent" {
description = "upper limit (% of desired_count) of # of running tasks during a deployment"
default = 200
}
variable "log_driver" {
description = "The log driver to use use for the container"
default = "journald"
}
/**
* Resources.
*/
resource "aws_ecs_service" "main" {
name = "${module.task.name}"
cluster = "${var.cluster}"
task_definition = "${module.task.arn}"
desired_count = "${var.desired_count}"
deployment_minimum_healthy_percent = "${var.deployment_minimum_healthy_percent}"
deployment_maximum_percent = "${var.deployment_maximum_percent}"
lifecycle {
create_before_destroy = true
}
}
module "task" {
source = "../task"
name = "${coalesce(var.name, var.image)}"
image = "${var.image}"
image_version = "${var.version}"
command = "${var.command}"
env_vars = "${var.env_vars}"
memory = "${var.memory}"
cpu = "${var.cpu}"
log_driver = "${var.log_driver}"
}