Skip to content
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
2 changes: 2 additions & 0 deletions _test/main.tf
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,8 @@ module "lambda" {

source_dir = "lambda/src"

iam_role_permissions_boundary_name = "example-boundary"

default_tags = {
app = "example"
env = "production"
Expand Down
25 changes: 25 additions & 0 deletions main.tf
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,32 @@ resource "aws_iam_role" "this" {

assume_role_policy = data.aws_iam_policy_document.lambda-assume-role.json

permissions_boundary = local.iam_role_permissions_boundary

tags = merge(var.default_tags, var.iam_role_tags)

# The boundary is set when the role is created. A role created before
# `var.iam_role_permissions_boundary_name` was set keeps its boundary, or none, until it is
# replaced, so setting the variable never changes what a running function may do.
lifecycle {
ignore_changes = [permissions_boundary]
}
}

data "aws_caller_identity" "boundary" {
count = var.iam_role_permissions_boundary_name != null ? 1 : 0
}

data "aws_partition" "boundary" {
count = var.iam_role_permissions_boundary_name != null ? 1 : 0
}

locals {
iam_role_permissions_boundary = (
var.iam_role_permissions_boundary_name != null
? "arn:${data.aws_partition.boundary[0].partition}:iam::${data.aws_caller_identity.boundary[0].account_id}:policy/${var.iam_role_permissions_boundary_name}"
: null
)
}

data "aws_iam_policy_document" "lambda-assume-role" {
Expand Down
9 changes: 9 additions & 0 deletions variables.tf
Original file line number Diff line number Diff line change
Expand Up @@ -70,6 +70,15 @@ The name of the method within your code that Lambda calls to execute your functi
EOS
}

variable "iam_role_permissions_boundary_name" {
type = string
default = null

description = <<EOS
Name of the IAM policy set as permissions boundary of the IAM role used by the Lambda function created by this module. The policy must exist with this name in the role's account; the module builds its ARN from that account. It is only set when the role is created: changing it later doesn't change an existing role.
EOS
}

variable "iam_role_tags" {
type = map(string)
default = {}
Expand Down