@@ -11,7 +11,12 @@ resource "random_id" "id" {
1111 byte_length = 4
1212}
1313#
14- # Create the assume role policy document for the Lambda function.
14+ # Create a local variable for the Lambda function name, so it can be used in two places without causing a cycle.
15+ locals {
16+ lambdaName = " fsxn_rotate_secret-${ random_id . id . hex } "
17+ }
18+ #
19+ # Create the policy document for the assume role policy for the Lambda function role.
1520data "aws_iam_policy_document" "assume_role" {
1621 statement {
1722 effect = " Allow"
@@ -25,8 +30,8 @@ data "aws_iam_policy_document" "assume_role" {
2530 }
2631}
2732#
28- # Create the inline policy document for the Lambda function role.
29- data "aws_iam_policy_document" "inline_permissions " {
33+ # Create a policy document for the policy for the Lambda function role.
34+ data "aws_iam_policy_document" "lambda_permissions " {
3035 #
3136 # The frist two statements are required for the lambda function to write logs to CloudWatch.
3237 # While not required, are useful for debugging.
@@ -75,20 +80,18 @@ data "aws_iam_policy_document" "inline_permissions" {
7580 }
7681}
7782#
78- # Create a local variable for the Lambda function name, so it can be used in two places without causing a cycle.
79- locals {
80- lambdaName = " fsxn_rotate_secret-${ random_id . id . hex } "
81- }
82- #
8383# Create the IAM role for the Lambda function.
84- resource "aws_iam_role" "iam_for_lambda " {
85- name = " iam_for_lambda- ${ random_id . id . hex } "
84+ resource "aws_iam_role" "role_for_lambda " {
85+ name = " rotate_fsxn_secret_role_ ${ random_id . id . hex } "
8686 description = " IAM role for the Rotate FSxN Secret Lambda function."
8787 assume_role_policy = data. aws_iam_policy_document . assume_role . json
88- inline_policy {
89- name = " required_policy"
90- policy = data. aws_iam_policy_document . inline_permissions . json
91- }
88+ }
89+ #
90+ # Create the policy based on the policy document.
91+ resource "aws_iam_role_policy" "lambda_permissions" {
92+ name = " rotate_fsxn_secret_policy_${ random_id . id . hex } "
93+ role = aws_iam_role. role_for_lambda . name
94+ policy = data. aws_iam_policy_document . lambda_permissions . json
9295}
9396#
9497# Create the archive file for the Lambda function.
@@ -103,7 +106,7 @@ resource "aws_lambda_function" "rotateLambdaFunction" {
103106 provider = aws. secrets_provider
104107 function_name = local. lambdaName
105108 description = var. svm_id != " " ? " Lambda function to rotate the secret for SVM (${ var . svm_id } )." : " Lambda function to rotate the secret for FSxN File System (${ var . fsx_id } )."
106- role = aws_iam_role. iam_for_lambda . arn
109+ role = aws_iam_role. role_for_lambda . arn
107110 runtime = " python3.12"
108111 handler = " fsxn_rotate_secret.lambda_handler"
109112 filename = " fsxn_rotate_secret.zip"
0 commit comments