-
-
Notifications
You must be signed in to change notification settings - Fork 693
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
feat: Use inline instead of managed policies #615
feat: Use inline instead of managed policies #615
Conversation
d042c7d
to
f86cdf4
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
From the first look at this PR, it looks pretty good, but why are only some policy attachments changed? Should we update vpc
, tracing
, etc also?
Happy to change those as well but I was not sure because it looks like it they are copied from AWS-managed policies:
Apparently, there was an issue with only creating an |
@antonbabenko, or did you mean using the policy from the "copy" data block in a # Copying AWS managed policy to be able to attach the same policy with multiple roles without overwrites by another function
data "aws_iam_policy" "vpc" {
count = local.create_role && var.attach_network_policy ? 1 : 0
arn = "arn:${data.aws_partition.current.partition}:iam::aws:policy/service-role/AWSLambdaENIManagementAccess"
}
resource "aws_iam_policy" "vpc" {
count = local.create_role && var.attach_network_policy ? 1 : 0
name = "${local.policy_name}-vpc"
path = var.policy_path
policy = data.aws_iam_policy.vpc[0].policy
tags = var.tags
}
resource "aws_iam_role_policy_attachment" "vpc" {
count = local.create_role && var.attach_network_policy ? 1 : 0
role = aws_iam_role.lambda[0].name
policy_arn = aws_iam_policy.vpc[0].arn
} to # Copying AWS managed policy to be able to attach the same policy with multiple roles without overwrites by another function
data "aws_iam_policy" "vpc" {
count = local.create_role && var.attach_network_policy ? 1 : 0
arn = "arn:${data.aws_partition.current.partition}:iam::aws:policy/service-role/AWSLambdaENIManagementAccess"
}
resource "aws_iam_role_policy" "vpc" {
count = local.create_role && var.attach_network_policy ? 1 : 0
name = "${local.policy_name}-vpc"
role = aws_iam_role.lambda[0].name
policy = data.aws_iam_policy.vpc[0].policy
} |
This PR has been automatically marked as stale because it has been open 30 days |
f86cdf4
to
a1d27a7
Compare
@antonbabenko, I updated I don't think there is anything left, or is there? |
a1d27a7
to
42a3fb6
Compare
42a3fb6
to
d2f44e8
Compare
This PR has been automatically marked as stale because it has been open 30 days |
@antonbabenko Looking forward to your review 🙂 |
This PR has been automatically marked as stale because it has been open 30 days |
@antonbabenko ping 🙂 |
would be great if this gets merged! |
aws_iam_role_policy_attachment.logs, | ||
aws_iam_role_policy_attachment.dead_letter, | ||
aws_iam_role_policy_attachment.vpc, | ||
aws_iam_role_policy_attachment.tracing, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Should the lambda now require a depends_on for each of the new aws_iam_role_policy
?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think, yes. Do you agree, @RafaelWO ? If so, please fix it, and I will merge it very quickly.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Sounds good! I fixed it 🙂
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Minor correction is missing. I have already reviewed other dependencies and potential issues. Looks great! Sorry that it took so long for me to review it!
aws_iam_role_policy_attachment.logs, | ||
aws_iam_role_policy_attachment.dead_letter, | ||
aws_iam_role_policy_attachment.vpc, | ||
aws_iam_role_policy_attachment.tracing, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think, yes. Do you agree, @RafaelWO ? If so, please fix it, and I will merge it very quickly.
* Remove unused variable `policy_path`
06845fe
to
5fcc934
Compare
I guess I somehow messed up the PR by rebasing after the master was merged into my branch 😬
@antonbabenko do you want to merge master into this one before merging? |
5fcc934
to
ec01bf8
Compare
## [7.20.0](v7.19.0...v7.20.0) (2025-01-08) ### Features * Use inline instead of managed policies ([#615](#615)) ([394d337](394d337))
This PR is included in version 7.20.0 🎉 |
@RafaelWO Thank you a lot for this contribution! |
It was a pleasure 😊 |
Description
This PR replaces customer-managed policies with inline policies becuase the policies are only used for the Lambda function. See also Managed policies and inline policies.
Motivation and Context
Fixes #607
Breaking Changes
If users have attached the customer-managed policies to other resources, this change is breaking (in theory) since the new policies will be inline. But it is very unlikely that users did this.
How Has This Been Tested?
examples/*
to demonstrate and validate my change(s)examples/*
projectsI have tested this branch against on of my projects using this module. Below is the terraform plan output
Expand
I have executed
pre-commit run -a
on my pull request