Skip to content

Commit 9c346e7

Browse files
authored
fix(terraform): update IAM configuration for ECS deployment (#2675)
1 parent 61af2a4 commit 9c346e7

File tree

3 files changed

+29
-4
lines changed

3 files changed

+29
-4
lines changed

Diff for: terraform/README.md

+1-1
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ There's an example tfvars file to start you off; rename this with your own prefe
1616

1717
Authenticate yourself with your own AWS account as with any aws commandline tool.
1818

19-
If you wish, add a specific section to your aws credentials file and set that profile name in `terraform.tfvars`.
19+
If you wish, add a specific section to your aws credentials file and set that profile name in `terraform.tfvars`. More information on how to configure the AWS credentials file can be found in <a href="https://docs.aws.amazon.com/cli/latest/userguide/cli-configure-files.html">here</a>.
2020

2121
Then you can:
2222

Diff for: terraform/resource-ecs.tf

+23-3
Original file line numberDiff line numberDiff line change
@@ -16,8 +16,28 @@ resource "aws_ecs_service" "main" {
1616
launch_type = "FARGATE"
1717
}
1818

19-
data "aws_iam_role" "ecs_task_execution_role" {
20-
name = "ecsTaskExecutionRole"
19+
data "aws_iam_policy_document" "ecs_task_execution_role" {
20+
version = "2012-10-17"
21+
statement {
22+
sid = ""
23+
effect = "Allow"
24+
actions = ["sts:AssumeRole"]
25+
26+
principals {
27+
type = "Service"
28+
identifiers = ["ecs-tasks.amazonaws.com"]
29+
}
30+
}
31+
}
32+
33+
resource "aws_iam_role" "ecs_task_execution_role" {
34+
name = var.ecs_task_execution_role_name
35+
assume_role_policy = data.aws_iam_policy_document.ecs_task_execution_role.json
36+
}
37+
38+
resource "aws_iam_role_policy_attachment" "ecs_task_execution_role" {
39+
role = aws_iam_role.ecs_task_execution_role.name
40+
policy_arn = "arn:aws:iam::aws:policy/service-role/AmazonECSTaskExecutionRolePolicy"
2141
}
2242

2343
locals {
@@ -38,5 +58,5 @@ resource "aws_ecs_task_definition" "main" {
3858
network_mode = "awsvpc"
3959
cpu = var.cpu
4060
memory = var.memory
41-
execution_role_arn = data.aws_iam_role.ecs_task_execution_role.arn
61+
execution_role_arn = aws_iam_role.ecs_task_execution_role.arn
4262
}

Diff for: terraform/variables.tf

+5
Original file line numberDiff line numberDiff line change
@@ -38,3 +38,8 @@ variable "streetmerchant_env" {
3838
description = "name/value pairs for .env values"
3939
default = {}
4040
}
41+
42+
variable "ecs_task_execution_role_name" {
43+
description = "ECS task execution role name"
44+
default = "myEcsTaskExecutionRole"
45+
}

0 commit comments

Comments
 (0)