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

Updates iam role module to use new exclusive pattern for inline policies #205

Draft
wants to merge 1 commit into
base: master
Choose a base branch
from
Draft
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
21 changes: 13 additions & 8 deletions modules/role/main.tf
Original file line number Diff line number Diff line change
Expand Up @@ -10,14 +10,6 @@ resource "aws_iam_role" "this" {
path = var.path
permissions_boundary = var.permissions_boundary

dynamic "inline_policy" {
for_each = var.inline_policies
content {
name = inline_policy.value.name
policy = inline_policy.value.policy
}
}

tags = merge(
{
Name = var.name
Expand All @@ -33,6 +25,19 @@ resource "aws_iam_role" "this" {
}
}

resource "aws_iam_role_policy" "this" {
for_each = { for policy in var.inline_policies : policy.name => policy }

name = each.value.name
policy = each.value.policy
role = aws_iam_role.this.name
}

resource "aws_iam_role_policies_exclusive" "this" {
role_name = aws_iam_role.this.name
policy_names = [for name, policy in aws_iam_role_policy.this : policy.name]
}

# attach an instance profile to the IAM role
resource "aws_iam_instance_profile" "this" {
count = var.instance_profile != null ? 1 : 0
Expand Down
2 changes: 1 addition & 1 deletion modules/role/versions.tf
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ terraform {
required_providers {
aws = {
source = "hashicorp/aws"
version = ">= 3.35.0"
version = ">= 5.68.0"
}
}
}
Loading