Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add tags to IAM roles #142

Merged
merged 2 commits into from
Oct 8, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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