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

feat: Add policy_path variable for IAM policies #202

Merged
merged 3 commits into from
Oct 12, 2021
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 README.md
Original file line number Diff line number Diff line change
Expand Up @@ -726,6 +726,7 @@ No modules.
| <a name="input_policy"></a> [policy](#input\_policy) | An additional policy document ARN to attach to the Lambda Function role | `string` | `null` | no |
| <a name="input_policy_json"></a> [policy\_json](#input\_policy\_json) | An additional policy document as JSON to attach to the Lambda Function role | `string` | `null` | no |
| <a name="input_policy_jsons"></a> [policy\_jsons](#input\_policy\_jsons) | List of additional policy documents as JSON to attach to Lambda Function role | `list(string)` | `[]` | no |
| <a name="input_policy_path"></a> [policy\_path](#input\_policy\_path) | Path of policies to that should be added to IAM role for Lambda Function | `string` | `null` | no |
| <a name="input_policy_statements"></a> [policy\_statements](#input\_policy\_statements) | Map of dynamic policy statements to attach to Lambda Function role | `any` | `{}` | no |
| <a name="input_provisioned_concurrent_executions"></a> [provisioned\_concurrent\_executions](#input\_provisioned\_concurrent\_executions) | Amount of capacity to allocate. Set to 1 or greater to enable, or set to 0 to disable provisioned concurrency. | `number` | `-1` | no |
| <a name="input_publish"></a> [publish](#input\_publish) | Whether to publish creation/change as new Lambda Function Version. | `bool` | `false` | no |
Expand Down
3 changes: 3 additions & 0 deletions examples/complete/main.tf
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,9 @@ module "lambda_function" {
Serverless = "Terraform"
}

role_path = "/tf-managed/"
policy_path = "/tf-managed/"

attach_dead_letter_policy = true
dead_letter_target_arn = aws_sqs_queue.dlq.arn

Expand Down
8 changes: 8 additions & 0 deletions iam.tf
Original file line number Diff line number Diff line change
Expand Up @@ -133,6 +133,7 @@ resource "aws_iam_policy" "logs" {
count = local.create_role && var.attach_cloudwatch_logs_policy ? 1 : 0

name = "${local.role_name}-logs"
path = var.policy_path
policy = data.aws_iam_policy_document.logs[0].json
tags = var.tags
}
Expand Down Expand Up @@ -169,6 +170,7 @@ resource "aws_iam_policy" "dead_letter" {
count = local.create_role && var.attach_dead_letter_policy ? 1 : 0

name = "${local.role_name}-dl"
path = var.policy_path
policy = data.aws_iam_policy_document.dead_letter[0].json
tags = var.tags
}
Expand All @@ -195,6 +197,7 @@ resource "aws_iam_policy" "vpc" {
count = local.create_role && var.attach_network_policy ? 1 : 0

name = "${local.role_name}-vpc"
path = var.policy_path
policy = data.aws_iam_policy.vpc[0].policy
tags = var.tags
}
Expand All @@ -221,6 +224,7 @@ resource "aws_iam_policy" "tracing" {
count = local.create_role && var.attach_tracing_policy ? 1 : 0

name = "${local.role_name}-tracing"
path = var.policy_path
policy = data.aws_iam_policy.tracing[0].policy
tags = var.tags
}
Expand Down Expand Up @@ -257,6 +261,7 @@ resource "aws_iam_policy" "async" {
count = local.create_role && var.attach_async_event_policy ? 1 : 0

name = "${local.role_name}-async"
path = var.policy_path
policy = data.aws_iam_policy_document.async[0].json
tags = var.tags
}
Expand All @@ -276,6 +281,7 @@ resource "aws_iam_policy" "additional_json" {
count = local.create_role && var.attach_policy_json ? 1 : 0

name = local.role_name
path = var.policy_path
policy = var.policy_json
tags = var.tags
}
Expand All @@ -295,6 +301,7 @@ resource "aws_iam_policy" "additional_jsons" {
count = local.create_role && var.attach_policy_jsons ? var.number_of_policy_jsons : 0

name = "${local.role_name}-${count.index}"
path = var.policy_path
policy = var.policy_jsons[count.index]
tags = var.tags
}
Expand Down Expand Up @@ -378,6 +385,7 @@ resource "aws_iam_policy" "additional_inline" {
count = local.create_role && var.attach_policy_statements ? 1 : 0

name = "${local.role_name}-inline"
path = var.policy_path
policy = data.aws_iam_policy_document.additional_inline[0].json
tags = var.tags
}
Expand Down
6 changes: 6 additions & 0 deletions variables.tf
Original file line number Diff line number Diff line change
Expand Up @@ -429,6 +429,12 @@ variable "attach_policies" {
default = false
}

variable "policy_path" {
description = "Path of policies to that should be added to IAM role for Lambda Function"
type = string
default = null
}

variable "number_of_policy_jsons" {
description = "Number of policies JSON to attach to IAM role for Lambda Function"
type = number
Expand Down