Skip to content

Commit

Permalink
Add tags to IAM roles (#142)
Browse files Browse the repository at this point in the history
  • Loading branch information
mbarrien authored Oct 8, 2019
1 parent 499fed7 commit d832ad1
Show file tree
Hide file tree
Showing 9 changed files with 40 additions and 40 deletions.
1 change: 1 addition & 0 deletions aws-ecs-job-fargate/iam.tf
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ data "aws_iam_policy_document" "execution_role" {
resource "aws_iam_role" "task_execution_role" {
name = "${local.name}-execution-role"
assume_role_policy = data.aws_iam_policy_document.execution_role.json
tags = local.tags
}

# TODO(mbarrien): We can probably narrow this down to allowing access to only
Expand Down
1 change: 1 addition & 0 deletions aws-ecs-job/iam.tf
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ resource "aws_iam_role" "task_execution_role" {
count = var.registry_secretsmanager_arn != null ? 1 : 0
name = "${local.name}-execution-role"
assume_role_policy = data.aws_iam_policy_document.execution_role.json
tags = local.tags
}

# TODO(mbarrien): We can probably narrow this down to allowing access to only
Expand Down
25 changes: 8 additions & 17 deletions aws-ecs-service-fargate/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -24,21 +24,12 @@ data "aws_route53_zone" "zone" {
private_zone = false
}
data "aws_iam_policy_document" "assume_role" {
statement {
principals {
type = "Service"
identifiers = ["ecs-tasks.amazonaws.com"]
}
actions = ["sts:AssumeRole"]
}
}
resource "aws_iam_role" "role" {
name = "${var.project}-${var.env}-myservice"
description = "Task role for myservice in ${var.env} environment"
assume_role_policy = data.aws_iam_policy_document.assume_role.json
module "role" {
source = "github.com/chanzuckerberg/cztack//aws-iam-ecs-task-role?ref=v0.21.3"
project = var.project
env = var.env
service = var.component
owner = var.owner
}
module "role-policy" {
Expand All @@ -47,7 +38,7 @@ module "role-policy" {
env = var.env
service = var.component
region = var.region
role_name = aws_iam_role.role.name
role_name = module.role.name
}
# This will define a task that runs this (example) container.
Expand Down Expand Up @@ -126,7 +117,7 @@ module "web-service" {
task_definition = local.template
# The task is given this role. Useful for services that need to make API calls to AWS.
task_role_arn = aws_iam_role.role.arn
task_role_arn = module.role.arn
cpu = 256
memory = 512
Expand Down
1 change: 1 addition & 0 deletions aws-ecs-service-fargate/iam.tf
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ data "aws_iam_policy_document" "execution_role" {
resource "aws_iam_role" "task_execution_role" {
name = "${local.name}-execution-role"
assume_role_policy = data.aws_iam_policy_document.execution_role.json
tags = local.tags
}

# TODO: Add support for giving permissions to ECR ARNs and possibly cloudwatch log group
Expand Down
25 changes: 8 additions & 17 deletions aws-ecs-service/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -20,21 +20,12 @@ data "aws_route53_zone" "zone" {
private_zone = false
}
data "aws_iam_policy_document" "assume_role" {
statement {
principals {
type = "Service"
identifiers = ["ecs-tasks.amazonaws.com"]
}
actions = ["sts:AssumeRole"]
}
}
resource "aws_iam_role" "role" {
name = "${var.project}-${var.env}-myservice"
description = "Task role for myservice in ${var.env} environment"
assume_role_policy = data.aws_iam_policy_document.assume_role.json
module "role" {
source = "github.com/chanzuckerberg/cztack//aws-iam-ecs-task-role?ref=v0.21.3"
project = var.project
env = var.env
service = var.component
owner = var.owner
}
module "role-policy" {
Expand All @@ -43,7 +34,7 @@ module "role-policy" {
env = var.env
service = var.component
region = var.region
role_name = aws_iam_role.role.name
role_name = module.role.name
}
# This will define a task that runs this (example) container.
Expand Down Expand Up @@ -121,7 +112,7 @@ module "web-service" {
task_definition = local.template
# The task is given this role. Useful for services that need to make API calls to AWS.
task_role_arn = aws_iam_role.role.arn
task_role_arn = module.role.arn
with_service_discovery = true
}
Expand Down
1 change: 1 addition & 0 deletions aws-ecs-service/iam.tf
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ resource "aws_iam_role" "task_execution_role" {
count = var.registry_secretsmanager_arn != null ? 1 : 0
name = "${local.name}-execution-role"
assume_role_policy = data.aws_iam_policy_document.execution_role.json
tags = local.tags
}

# TODO: Add support for giving permissions to ECR ARNs and possibly cloudwatch log group
Expand Down
16 changes: 14 additions & 2 deletions aws-iam-ecs-task-role/main.tf
Original file line number Diff line number Diff line change
@@ -1,3 +1,14 @@
locals {
tags = {
Name = "${var.project}-${var.env}-${var.service}"
project = var.project
env = var.env
service = var.service
owner = var.owner
managedBy = "terraform"
}
}

data "aws_iam_policy_document" "role" {
statement {
principals {
Expand All @@ -12,6 +23,7 @@ data "aws_iam_policy_document" "role" {
resource "aws_iam_role" "role" {
name = "${var.project}-${var.env}-${var.service}"
description = "Task role for ${var.service} task in ${var.project}-${var.env}. Owned by ${var.owner}."
assume_role_policy = "${data.aws_iam_policy_document.role.json}"
path = "${var.iam_path}"
assume_role_policy = data.aws_iam_policy_document.role.json
path = var.iam_path
tags = local.tags
}
3 changes: 2 additions & 1 deletion bless-ca/iam.tf
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,7 @@ resource "aws_iam_role" "bless" {
name_prefix = "${local.name}-"
path = "${var.iam_path}"
assume_role_policy = "${data.aws_iam_policy_document.assume_role.json}"
tags = local.tags
}

resource "aws_iam_role_policy" "lambda" {
Expand All @@ -68,7 +69,7 @@ resource "aws_iam_role_policy" "lambda" {
}

module "logs_policy" {
source = "github.com/chanzuckerberg/cztack//aws-iam-policy-cwlogs?ref=v0.14.0"
source = "../aws-iam-policy-cwlogs"
role_name = "${aws_iam_role.bless.name}"
iam_path = "${var.iam_path}"
}
7 changes: 4 additions & 3 deletions github-webhooks-to-s3/main.tf
Original file line number Diff line number Diff line change
Expand Up @@ -48,9 +48,10 @@ module "attach-logs" {
}

resource "aws_iam_role" "lambda" {
name = "${local.name}"
path = "${var.iam_path}"
assume_role_policy = "${data.aws_iam_policy_document.assume_role.json}"
name = local.name
path = var.iam_path
assume_role_policy = data.aws_iam_policy_document.assume_role.json
tags = local.tags
}

module "github_secret" {
Expand Down

0 comments on commit d832ad1

Please sign in to comment.