Skip to content

Commit c139343

Browse files
authored
Add support for inline IAM policy (#68)
1 parent d97dbac commit c139343

File tree

3 files changed

+26
-0
lines changed

3 files changed

+26
-0
lines changed

examples/complete/main.tf

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -90,6 +90,19 @@ module "lambda" {
9090
# aws_iam_policy.inside[0].id, # This will result in an error message and is why we use local.policy_name_inside
9191
]
9292

93+
inline_iam_policy = <<-JSON
94+
{
95+
"Version": "2012-10-17",
96+
"Statement": [
97+
{
98+
"Effect": "Deny",
99+
"Action": "ec2:DescribeInstanceTypes",
100+
"Resource": "*"
101+
}
102+
]
103+
}
104+
JSON
105+
93106
context = module.this.context
94107

95108
depends_on = [aws_iam_policy.inside]

iam-role.tf

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -91,3 +91,10 @@ resource "aws_iam_role_policy_attachment" "custom" {
9191
role = aws_iam_role.this[0].name
9292
policy_arn = each.value
9393
}
94+
95+
resource "aws_iam_role_policy" "inline" {
96+
count = try((local.enabled && var.inline_iam_policy != null), false) ? 1 : 0
97+
98+
role = aws_iam_role.this[0].name
99+
policy = var.inline_iam_policy
100+
}

variables.tf

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -233,3 +233,9 @@ variable "iam_policy_description" {
233233
description = "Description of the IAM policy for the Lambda IAM role"
234234
default = "Provides minimum SSM read permissions."
235235
}
236+
237+
variable "inline_iam_policy" {
238+
type = string
239+
description = "Inline policy document (JSON) to attach to the lambda role"
240+
default = null
241+
}

0 commit comments

Comments
 (0)