Skip to content

Commit eae3ea3

Browse files
fix destructive no-op updates and update README
1 parent 62cd0af commit eae3ea3

File tree

15 files changed

+96
-35
lines changed

15 files changed

+96
-35
lines changed

modules/aws_ecs/workflows_aws_ecs/README.md renamed to modules/aws_ecs/README.md

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -50,7 +50,8 @@ To configure the EC instance size, set the `instance_type` input variable (e.g.
5050
To configure the RDS instance class, set the `instance_class` input variable (e.g. `db.m6g.large`).
5151

5252
## Advanced Configuration
53-
53+
**Bring your own Temporal Cluster**
54+
To configure your own Temporal cluster, set the `use_existing_temporal_cluster` to `true` and configure your Temporal Cluster's Frontend service endpoint (and TLS if needed) using `temporal_cluster_config`. If configuring mTLS, we expect the cert and key values to be base64-encoded strings.
5455
### Security Groups
5556

5657
To customize the ingress and egress rules on the security groups, you can override specific input variable defaults.

modules/aws_ecs/workflows_aws_ecs/ecs.tf renamed to modules/aws_ecs/ecs.tf

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -9,15 +9,14 @@ resource "aws_ecs_cluster" "this" {
99

1010
# Fargate capacity provider
1111
resource "aws_ecs_cluster_capacity_providers" "this" {
12-
count = var.launch_type == "FARGATE" ? 1 : 0
1312
cluster_name = aws_ecs_cluster.this.name
1413

15-
capacity_providers = ["FARGATE"]
14+
capacity_providers = var.launch_type == "FARGATE" ? ["FARGATE"] : [aws_ecs_capacity_provider.this[0].name]
1615

1716
default_capacity_provider_strategy {
1817
base = 1
1918
weight = 100
20-
capacity_provider = "FARGATE"
19+
capacity_provider = var.launch_type == "FARGATE" ? "FARGATE" : aws_ecs_capacity_provider.this[0].name
2120
}
2221
}
2322

modules/aws_ecs/workflows_aws_ecs/loadbalancers.tf renamed to modules/aws_ecs/loadbalancers.tf

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,7 @@ resource "aws_lb_target_group" "this" {
4646
path = "/api/checkHealth"
4747
protocol = "HTTP"
4848
timeout = 60
49-
healthy_threshold = 4
49+
healthy_threshold = 3
5050
unhealthy_threshold = 2
5151
}
5252
}

modules/aws_ecs/workflows_aws_ecs/main.tf renamed to modules/aws_ecs/main.tf

Lines changed: 50 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -48,6 +48,14 @@ resource "aws_ecs_service" "retool" {
4848
container_name = "retool"
4949
container_port = 3000
5050
}
51+
52+
# Need to explictly set this in aws_ecs_service to avoid destructive behavior: https://github.com/hashicorp/terraform-provider-aws/issues/22823
53+
capacity_provider_strategy {
54+
base = 1
55+
weight = 100
56+
capacity_provider = var.launch_type == "FARGATE" ? "FARGATE" : aws_ecs_capacity_provider.this[0].name
57+
}
58+
5159
dynamic "network_configuration" {
5260
for_each = var.launch_type == "FARGATE" ? toset([1]) : toset([])
5361

@@ -66,6 +74,14 @@ resource "aws_ecs_service" "jobs_runner" {
6674
cluster = aws_ecs_cluster.this.id
6775
desired_count = 1
6876
task_definition = aws_ecs_task_definition.retool_jobs_runner.arn
77+
78+
# Need to explictly set this in aws_ecs_service to avoid destructive behavior: https://github.com/hashicorp/terraform-provider-aws/issues/22823
79+
capacity_provider_strategy {
80+
base = 1
81+
weight = 100
82+
capacity_provider = var.launch_type == "FARGATE" ? "FARGATE" : aws_ecs_capacity_provider.this[0].name
83+
}
84+
6985
dynamic "network_configuration" {
7086

7187
for_each = var.launch_type == "FARGATE" ? toset([1]) : toset([])
@@ -87,6 +103,13 @@ resource "aws_ecs_service" "workflows_backend" {
87103
desired_count = 1
88104
task_definition = aws_ecs_task_definition.retool_workflows_backend[0].arn
89105

106+
# Need to explictly set this in aws_ecs_service to avoid destructive behavior: https://github.com/hashicorp/terraform-provider-aws/issues/22823
107+
capacity_provider_strategy {
108+
base = 1
109+
weight = 100
110+
capacity_provider = var.launch_type == "FARGATE" ? "FARGATE" : aws_ecs_capacity_provider.this[0].name
111+
}
112+
90113
service_registries {
91114
registry_arn = aws_service_discovery_service.retool_workflow_backend_service[0].arn
92115
}
@@ -110,6 +133,13 @@ resource "aws_ecs_service" "workflows_worker" {
110133
cluster = aws_ecs_cluster.this.id
111134
desired_count = 1
112135
task_definition = aws_ecs_task_definition.retool_workflows_worker[0].arn
136+
137+
# Need to explictly set this in aws_ecs_service to avoid destructive behavior: https://github.com/hashicorp/terraform-provider-aws/issues/22823
138+
capacity_provider_strategy {
139+
base = 1
140+
weight = 100
141+
capacity_provider = var.launch_type == "FARGATE" ? "FARGATE" : aws_ecs_capacity_provider.this[0].name
142+
}
113143
dynamic "network_configuration" {
114144

115145
for_each = var.launch_type == "FARGATE" ? toset([1]) : toset([])
@@ -130,16 +160,16 @@ resource "aws_ecs_task_definition" "retool_jobs_runner" {
130160
execution_role_arn = var.launch_type == "FARGATE" ? aws_iam_role.execution_role[0].arn : null
131161
requires_compatibilities = var.launch_type == "FARGATE" ? ["FARGATE"] : null
132162
network_mode = var.launch_type == "FARGATE" ? "awsvpc" : "bridge"
133-
cpu = var.launch_type == "FARGATE" ? var.ecs_task_cpu : null
134-
memory = var.launch_type == "FARGATE" ? var.ecs_task_memory : null
163+
cpu = var.launch_type == "FARGATE" ? var.ecs_task_resource_map["jobs_runner"]["cpu"] : null
164+
memory = var.launch_type == "FARGATE" ? var.ecs_task_resource_map["jobs_runner"]["memory"] : null
135165
container_definitions = jsonencode(
136166
[
137167
{
138168
name = "retool-jobs-runner"
139169
essential = true
140170
image = var.ecs_retool_image
141-
cpu = var.launch_type == "EC2" ? var.ecs_task_cpu : null
142-
memory = var.launch_type == "EC2" ? var.ecs_task_memory : null
171+
cpu = var.launch_type == "EC2" ? var.ecs_task_resource_map["jobs_runner"]["cpu"] : null
172+
memory = var.launch_type == "EC2" ? var.ecs_task_resource_map["jobs_runner"]["memory"] : null
143173
command = [
144174
"./docker_scripts/start_api.sh"
145175
]
@@ -180,16 +210,16 @@ resource "aws_ecs_task_definition" "retool" {
180210
execution_role_arn = var.launch_type == "FARGATE" ? aws_iam_role.execution_role[0].arn : null
181211
requires_compatibilities = var.launch_type == "FARGATE" ? ["FARGATE"] : null
182212
network_mode = var.launch_type == "FARGATE" ? "awsvpc" : "bridge"
183-
cpu = var.launch_type == "FARGATE" ? var.ecs_task_cpu : null
184-
memory = var.launch_type == "FARGATE" ? var.ecs_task_memory : null
213+
cpu = var.launch_type == "FARGATE" ? var.ecs_task_resource_map["main"]["cpu"] : null
214+
memory = var.launch_type == "FARGATE" ? var.ecs_task_resource_map["main"]["memory"] : null
185215
container_definitions = jsonencode(
186216
[
187217
{
188218
name = "retool"
189219
essential = true
190220
image = var.ecs_retool_image
191-
cpu = var.launch_type == "EC2" ? var.ecs_task_cpu : null
192-
memory = var.launch_type == "EC2" ? var.ecs_task_memory : null
221+
cpu = var.launch_type == "EC2" ? var.ecs_task_resource_map["main"]["cpu"] : null
222+
memory = var.launch_type == "EC2" ? var.ecs_task_resource_map["main"]["memory"] : null
193223
command = [
194224
"./docker_scripts/start_api.sh"
195225
]
@@ -236,16 +266,16 @@ resource "aws_ecs_task_definition" "retool_workflows_backend" {
236266
execution_role_arn = var.launch_type == "FARGATE" ? aws_iam_role.execution_role[0].arn : null
237267
requires_compatibilities = var.launch_type == "FARGATE" ? ["FARGATE"] : null
238268
network_mode = var.launch_type == "FARGATE" ? "awsvpc" : "bridge"
239-
cpu = var.launch_type == "FARGATE" ? var.ecs_task_cpu : null
240-
memory = var.launch_type == "FARGATE" ? var.ecs_task_memory : null
269+
cpu = var.launch_type == "FARGATE" ? var.ecs_task_resource_map["workflows_backend"]["cpu"] : null
270+
memory = var.launch_type == "FARGATE" ? var.ecs_task_resource_map["workflows_backend"]["memory"] : null
241271
container_definitions = jsonencode(
242272
[
243273
{
244-
name = "retool"
274+
name = "retool-workflows-backend"
245275
essential = true
246276
image = var.ecs_retool_image
247-
cpu = var.launch_type == "EC2" ? var.ecs_task_cpu : null
248-
memory = var.launch_type == "EC2" ? var.ecs_task_memory : null
277+
cpu = var.launch_type == "EC2" ? var.ecs_task_resource_map["workflows_backend"]["cpu"] : null
278+
memory = var.launch_type == "EC2" ? var.ecs_task_resource_map["workflows_backend"]["memory"] : null
249279
command = [
250280
"./docker_scripts/start_api.sh"
251281
]
@@ -291,16 +321,16 @@ resource "aws_ecs_task_definition" "retool_workflows_worker" {
291321
execution_role_arn = var.launch_type == "FARGATE" ? aws_iam_role.execution_role[0].arn : null
292322
requires_compatibilities = var.launch_type == "FARGATE" ? ["FARGATE"] : null
293323
network_mode = var.launch_type == "FARGATE" ? "awsvpc" : "bridge"
294-
cpu = var.launch_type == "FARGATE" ? var.ecs_task_cpu : null
295-
memory = var.launch_type == "FARGATE" ? var.ecs_task_memory : null
324+
cpu = var.launch_type == "FARGATE" ? var.ecs_task_resource_map["workflows_worker"]["cpu"] : null
325+
memory = var.launch_type == "FARGATE" ? var.ecs_task_resource_map["workflows_worker"]["memory"] : null
296326
container_definitions = jsonencode(
297327
[
298328
{
299-
name = "retool"
329+
name = "retool-workflows-worker"
300330
essential = true
301331
image = var.ecs_retool_image
302-
cpu = var.launch_type == "EC2" ? var.ecs_task_cpu : null
303-
memory = var.launch_type == "EC2" ? var.ecs_task_memory : null
332+
cpu = var.launch_type == "EC2" ? var.ecs_task_resource_map["workflows_worker"]["cpu"] : null
333+
memory = var.launch_type == "EC2" ? var.ecs_task_resource_map["workflows_worker"]["memory"] : null
304334
command = [
305335
"./docker_scripts/start_api.sh"
306336
]
@@ -372,7 +402,7 @@ resource "aws_service_discovery_service" "retool_workflow_backend_service" {
372402
}
373403

374404
module "temporal" {
375-
count = var.workflows_enabled ? 1 : 0
405+
count = var.workflows_enabled && !var.use_exising_temporal_cluster ? 1 : 0
376406
source = "./temporal"
377407

378408
deployment_name = "${var.deployment_name}-temporal"
@@ -384,4 +414,5 @@ module "temporal" {
384414
aws_ecs_cluster_id = aws_ecs_cluster.this.id
385415
launch_type = var.launch_type
386416
container_sg_id = aws_security_group.containers.id
417+
aws_ecs_capacity_provider_name = var.launch_type == "EC2" ? aws_ecs_capacity_provider.this[0].name : null
387418
}
File renamed without changes.

modules/aws_ecs/workflows_aws_ecs/temporal/locals.tf renamed to modules/aws_ecs/temporal/locals.tf

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,10 @@ locals {
4141
{
4242
"name": "DYNAMIC_CONFIG_FILE_PATH",
4343
"value": "/etc/temporal/ecs/dynamic_config/dynamicconfig-sql.yaml"
44+
},
45+
{
46+
"name": "ECS_DEPLOYED",
47+
"value": "true"
4448
}
4549
]
4650
)

0 commit comments

Comments
 (0)