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

fix: Fixed IAM policy attachment with multiple functions #26

Merged
merged 1 commit into from
Jun 16, 2020
Merged
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
32 changes: 30 additions & 2 deletions iam.tf
Original file line number Diff line number Diff line change
Expand Up @@ -108,24 +108,52 @@ resource "aws_iam_policy_attachment" "dead_letter" {
# VPC
######

// Copying AWS managed policy to be able to attach the same policy with multiple roles without overwrites by another function
data "aws_iam_policy" "vpc" {
count = local.create_role && var.attach_network_policy ? 1 : 0

arn = "arn:aws:iam::aws:policy/service-role/AWSLambdaENIManagementAccess"
}

resource "aws_iam_policy" "vpc" {
count = local.create_role && var.attach_network_policy ? 1 : 0

name = "${var.function_name}-vpc"
policy = data.aws_iam_policy.vpc[0].policy
}

resource "aws_iam_policy_attachment" "vpc" {
count = local.create_role && var.attach_network_policy ? 1 : 0

name = "${var.function_name}-vpc"
roles = [aws_iam_role.lambda[0].name]
policy_arn = "arn:aws:iam::aws:policy/service-role/AWSLambdaENIManagementAccess"
policy_arn = aws_iam_policy.vpc[0].arn
}

#####################
# Tracing with X-Ray
#####################

// Copying AWS managed policy to be able to attach the same policy with multiple roles without overwrites by another function
data "aws_iam_policy" "tracing" {
count = local.create_role && var.attach_tracing_policy ? 1 : 0

arn = "arn:aws:iam::aws:policy/AWSXrayWriteOnlyAccess"
}

resource "aws_iam_policy" "tracing" {
count = local.create_role && var.attach_tracing_policy ? 1 : 0

name = "${var.function_name}-tracing"
policy = data.aws_iam_policy.tracing[0].policy
}

resource "aws_iam_policy_attachment" "tracing" {
count = local.create_role && var.attach_tracing_policy ? 1 : 0

name = "${var.function_name}-tracing"
roles = [aws_iam_role.lambda[0].name]
policy_arn = "arn:aws:iam::aws:policy/AWSXrayWriteOnlyAccess"
policy_arn = aws_iam_policy.tracing[0].arn
}

###############################
Expand Down