I created a module for Rest api that needs a different role dependens on the specification.
Currently I hardcoded a policy and allow sts:AssumeRole using this code:
data "aws_iam_policy_document" "lambda_role" {
statement {
actions = ["sts:AssumeRole"]
principals {
type = "Service"
identifiers = ["lambda.amazonaws.com"]
}
effect = "Allow"
}
}
resource "aws_iam_role" "lambda_function_role" {
name = "${var.lambda_function_name}_role"
assume_role_policy = data.aws_iam_policy_document.lambda_role.json
}
and in main.tf:
module "myModule" {
source = "../../modules/api"
lambda_function_name = "products"
}
I’m looking for passing a dynamic policy config to the module without hardcoding. Is there any possibility to pass a dynamic policy config as a variable to a module with Terraform?