Skip to content

Commit 2e88a0d

Browse files
committed
feat: allow additional custom IAM policy to attached EC2 role
1 parent ce0441b commit 2e88a0d

File tree

2 files changed

+20
-0
lines changed

2 files changed

+20
-0
lines changed

main.tf

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -139,6 +139,14 @@ resource "aws_iam_role_policy" "session_logging" {
139139
policy = join("", data.aws_iam_policy_document.session_logging.*.json)
140140
}
141141

142+
resource "aws_iam_role_policy" "custom" {
143+
count = length(var.custom_policy_document) > 0 ? 1 : 0
144+
145+
name = "${module.role_label.id}-${var.custom_policy_name}"
146+
role = aws_iam_role.default.name
147+
policy = var.custom_policy_document
148+
}
149+
142150
resource "aws_iam_instance_profile" "default" {
143151
name = module.role_label.id
144152
role = aws_iam_role.default.name

variables.tf

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -212,3 +212,15 @@ variable "scale_in_protected_instances" {
212212
error_message = "scale_in_protected_instances must be one of Refresh, Ignore, or Wait"
213213
}
214214
}
215+
216+
variable "custom_policy_document" {
217+
description = "JSON policy document for custom permissions to attach to the SSM Agent role. If not provided, no custom policy will be attached."
218+
type = string
219+
default = ""
220+
}
221+
222+
variable "custom_policy_name" {
223+
description = "Name for the custom policy. Only used if custom_policy_document is provided."
224+
type = string
225+
default = "custom-policy"
226+
}

0 commit comments

Comments
 (0)