Skip to content

Commit d832ad1

Browse files
authored
Add tags to IAM roles (#142)
1 parent 499fed7 commit d832ad1

File tree

9 files changed

+40
-40
lines changed

9 files changed

+40
-40
lines changed

aws-ecs-job-fargate/iam.tf

+1
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@ data "aws_iam_policy_document" "execution_role" {
1313
resource "aws_iam_role" "task_execution_role" {
1414
name = "${local.name}-execution-role"
1515
assume_role_policy = data.aws_iam_policy_document.execution_role.json
16+
tags = local.tags
1617
}
1718

1819
# TODO(mbarrien): We can probably narrow this down to allowing access to only

aws-ecs-job/iam.tf

+1
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@ resource "aws_iam_role" "task_execution_role" {
1313
count = var.registry_secretsmanager_arn != null ? 1 : 0
1414
name = "${local.name}-execution-role"
1515
assume_role_policy = data.aws_iam_policy_document.execution_role.json
16+
tags = local.tags
1617
}
1718

1819
# TODO(mbarrien): We can probably narrow this down to allowing access to only

aws-ecs-service-fargate/README.md

+8-17
Original file line numberDiff line numberDiff line change
@@ -24,21 +24,12 @@ data "aws_route53_zone" "zone" {
2424
private_zone = false
2525
}
2626
27-
data "aws_iam_policy_document" "assume_role" {
28-
statement {
29-
principals {
30-
type = "Service"
31-
identifiers = ["ecs-tasks.amazonaws.com"]
32-
}
33-
34-
actions = ["sts:AssumeRole"]
35-
}
36-
}
37-
38-
resource "aws_iam_role" "role" {
39-
name = "${var.project}-${var.env}-myservice"
40-
description = "Task role for myservice in ${var.env} environment"
41-
assume_role_policy = data.aws_iam_policy_document.assume_role.json
27+
module "role" {
28+
source = "github.com/chanzuckerberg/cztack//aws-iam-ecs-task-role?ref=v0.21.3"
29+
project = var.project
30+
env = var.env
31+
service = var.component
32+
owner = var.owner
4233
}
4334
4435
module "role-policy" {
@@ -47,7 +38,7 @@ module "role-policy" {
4738
env = var.env
4839
service = var.component
4940
region = var.region
50-
role_name = aws_iam_role.role.name
41+
role_name = module.role.name
5142
}
5243
5344
# This will define a task that runs this (example) container.
@@ -126,7 +117,7 @@ module "web-service" {
126117
task_definition = local.template
127118
128119
# The task is given this role. Useful for services that need to make API calls to AWS.
129-
task_role_arn = aws_iam_role.role.arn
120+
task_role_arn = module.role.arn
130121
131122
cpu = 256
132123
memory = 512

aws-ecs-service-fargate/iam.tf

+1
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@ data "aws_iam_policy_document" "execution_role" {
1313
resource "aws_iam_role" "task_execution_role" {
1414
name = "${local.name}-execution-role"
1515
assume_role_policy = data.aws_iam_policy_document.execution_role.json
16+
tags = local.tags
1617
}
1718

1819
# TODO: Add support for giving permissions to ECR ARNs and possibly cloudwatch log group

aws-ecs-service/README.md

+8-17
Original file line numberDiff line numberDiff line change
@@ -20,21 +20,12 @@ data "aws_route53_zone" "zone" {
2020
private_zone = false
2121
}
2222
23-
data "aws_iam_policy_document" "assume_role" {
24-
statement {
25-
principals {
26-
type = "Service"
27-
identifiers = ["ecs-tasks.amazonaws.com"]
28-
}
29-
30-
actions = ["sts:AssumeRole"]
31-
}
32-
}
33-
34-
resource "aws_iam_role" "role" {
35-
name = "${var.project}-${var.env}-myservice"
36-
description = "Task role for myservice in ${var.env} environment"
37-
assume_role_policy = data.aws_iam_policy_document.assume_role.json
23+
module "role" {
24+
source = "github.com/chanzuckerberg/cztack//aws-iam-ecs-task-role?ref=v0.21.3"
25+
project = var.project
26+
env = var.env
27+
service = var.component
28+
owner = var.owner
3829
}
3930
4031
module "role-policy" {
@@ -43,7 +34,7 @@ module "role-policy" {
4334
env = var.env
4435
service = var.component
4536
region = var.region
46-
role_name = aws_iam_role.role.name
37+
role_name = module.role.name
4738
}
4839
4940
# This will define a task that runs this (example) container.
@@ -121,7 +112,7 @@ module "web-service" {
121112
task_definition = local.template
122113
123114
# The task is given this role. Useful for services that need to make API calls to AWS.
124-
task_role_arn = aws_iam_role.role.arn
115+
task_role_arn = module.role.arn
125116
126117
with_service_discovery = true
127118
}

aws-ecs-service/iam.tf

+1
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@ resource "aws_iam_role" "task_execution_role" {
1313
count = var.registry_secretsmanager_arn != null ? 1 : 0
1414
name = "${local.name}-execution-role"
1515
assume_role_policy = data.aws_iam_policy_document.execution_role.json
16+
tags = local.tags
1617
}
1718

1819
# TODO: Add support for giving permissions to ECR ARNs and possibly cloudwatch log group

aws-iam-ecs-task-role/main.tf

+14-2
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,14 @@
1+
locals {
2+
tags = {
3+
Name = "${var.project}-${var.env}-${var.service}"
4+
project = var.project
5+
env = var.env
6+
service = var.service
7+
owner = var.owner
8+
managedBy = "terraform"
9+
}
10+
}
11+
112
data "aws_iam_policy_document" "role" {
213
statement {
314
principals {
@@ -12,6 +23,7 @@ data "aws_iam_policy_document" "role" {
1223
resource "aws_iam_role" "role" {
1324
name = "${var.project}-${var.env}-${var.service}"
1425
description = "Task role for ${var.service} task in ${var.project}-${var.env}. Owned by ${var.owner}."
15-
assume_role_policy = "${data.aws_iam_policy_document.role.json}"
16-
path = "${var.iam_path}"
26+
assume_role_policy = data.aws_iam_policy_document.role.json
27+
path = var.iam_path
28+
tags = local.tags
1729
}

bless-ca/iam.tf

+2-1
Original file line numberDiff line numberDiff line change
@@ -59,6 +59,7 @@ resource "aws_iam_role" "bless" {
5959
name_prefix = "${local.name}-"
6060
path = "${var.iam_path}"
6161
assume_role_policy = "${data.aws_iam_policy_document.assume_role.json}"
62+
tags = local.tags
6263
}
6364

6465
resource "aws_iam_role_policy" "lambda" {
@@ -68,7 +69,7 @@ resource "aws_iam_role_policy" "lambda" {
6869
}
6970

7071
module "logs_policy" {
71-
source = "github.com/chanzuckerberg/cztack//aws-iam-policy-cwlogs?ref=v0.14.0"
72+
source = "../aws-iam-policy-cwlogs"
7273
role_name = "${aws_iam_role.bless.name}"
7374
iam_path = "${var.iam_path}"
7475
}

github-webhooks-to-s3/main.tf

+4-3
Original file line numberDiff line numberDiff line change
@@ -48,9 +48,10 @@ module "attach-logs" {
4848
}
4949

5050
resource "aws_iam_role" "lambda" {
51-
name = "${local.name}"
52-
path = "${var.iam_path}"
53-
assume_role_policy = "${data.aws_iam_policy_document.assume_role.json}"
51+
name = local.name
52+
path = var.iam_path
53+
assume_role_policy = data.aws_iam_policy_document.assume_role.json
54+
tags = local.tags
5455
}
5556

5657
module "github_secret" {

0 commit comments

Comments
 (0)