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

Policy AWSLambdaExecute removed from existing roles when using terraform #259

Open
jocotton-ea opened this issue Sep 30, 2024 · 1 comment

Comments

@jocotton-ea
Copy link

AWS provider resource aws_iam_policy_attachment creates an exclusive relationship between the policy and roles defined. As this is almost never what you want, it is suggested to use aws_iam_role_policy_attachment to create an attachment between one policy and one role.

In context here, the policy AWSLambdaExecute policy is being attached to a set of roles created in the terraform module

resource "aws_iam_policy_attachment" "execute-attach" {
  name       = "execute-attachment"
  roles      = [aws_iam_role.analyzer_role.name, aws_iam_role.optimizer_role.name, aws_iam_role.executor_role.name, aws_iam_role.cleaner_role.name, aws_iam_role.initializer_role.name]
  policy_arn = data.aws_iam_policy.analyzer_policy.arn
}

Upon creating this resource, all roles that currently have policy AWSLambdaExecute attached will have that policy detached, resulting in resources that previously had permission to execute lambda functions no longer having that permission.

See https://registry.terraform.io/providers/hashicorp/aws/2.70.1/docs/resources/iam_policy_attachment

@alexcasalboni
Copy link
Owner

@jocotton-ea thanks for sharing!

We're in the process or moving all the Terraform definitions to this external module (already on the Terraform Registry): https://registry.terraform.io/modules/aws-ia/lambda-power-tuning/aws/latest

So I'd suggest opening the same issue on this repository: https://github.com/aws-ia/terraform-aws-lambda-power-tuning

FYI @sfloresk

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants