mirror of
https://github.com/ysoftdevs/terraform-aws-eks.git
synced 2026-03-17 23:13:46 +01:00
feat: Add support for custom IAM role policy (#3087)
This commit is contained in:
@@ -325,6 +325,7 @@ resource "aws_launch_template" "this" {
|
||||
# require permissions on create/destroy that depend on nodes
|
||||
depends_on = [
|
||||
aws_iam_role_policy_attachment.this,
|
||||
aws_iam_role_policy_attachment.additional,
|
||||
]
|
||||
|
||||
lifecycle {
|
||||
@@ -535,6 +536,68 @@ resource "aws_iam_role_policy_attachment" "additional" {
|
||||
role = aws_iam_role.this[0].name
|
||||
}
|
||||
|
||||
################################################################################
|
||||
# IAM Role Policy
|
||||
################################################################################
|
||||
|
||||
locals {
|
||||
create_iam_role_policy = local.create_iam_role && var.create_iam_role_policy && length(var.iam_role_policy_statements) > 0
|
||||
}
|
||||
|
||||
data "aws_iam_policy_document" "role" {
|
||||
count = local.create_iam_role_policy ? 1 : 0
|
||||
|
||||
dynamic "statement" {
|
||||
for_each = var.iam_role_policy_statements
|
||||
|
||||
content {
|
||||
sid = try(statement.value.sid, null)
|
||||
actions = try(statement.value.actions, null)
|
||||
not_actions = try(statement.value.not_actions, null)
|
||||
effect = try(statement.value.effect, null)
|
||||
resources = try(statement.value.resources, null)
|
||||
not_resources = try(statement.value.not_resources, null)
|
||||
|
||||
dynamic "principals" {
|
||||
for_each = try(statement.value.principals, [])
|
||||
|
||||
content {
|
||||
type = principals.value.type
|
||||
identifiers = principals.value.identifiers
|
||||
}
|
||||
}
|
||||
|
||||
dynamic "not_principals" {
|
||||
for_each = try(statement.value.not_principals, [])
|
||||
|
||||
content {
|
||||
type = not_principals.value.type
|
||||
identifiers = not_principals.value.identifiers
|
||||
}
|
||||
}
|
||||
|
||||
dynamic "condition" {
|
||||
for_each = try(statement.value.conditions, [])
|
||||
|
||||
content {
|
||||
test = condition.value.test
|
||||
values = condition.value.values
|
||||
variable = condition.value.variable
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
resource "aws_iam_role_policy" "this" {
|
||||
count = local.create_iam_role_policy ? 1 : 0
|
||||
|
||||
name = var.iam_role_use_name_prefix ? null : local.iam_role_name
|
||||
name_prefix = var.iam_role_use_name_prefix ? "${local.iam_role_name}-" : null
|
||||
policy = data.aws_iam_policy_document.role[0].json
|
||||
role = aws_iam_role.this[0].id
|
||||
}
|
||||
|
||||
################################################################################
|
||||
# Placement Group
|
||||
################################################################################
|
||||
|
||||
Reference in New Issue
Block a user