File tree Expand file tree Collapse file tree 8 files changed +130
-0
lines changed
Expand file tree Collapse file tree 8 files changed +130
-0
lines changed Original file line number Diff line number Diff line change @@ -6,6 +6,7 @@ Currently supported type of Roles are:
662 . Role for IAM User
773 . Role for External AWS Account
884 . Role for Instance Profile
9+ 5 . Role for Lambda
910
1011
1112Usage
@@ -23,6 +24,7 @@ Modules
2324* [ IAM User] ( https://github.com/traveloka/terraform-aws-iam-role/tree/master/modules/user )
2425* [ External AWS Account] ( https://github.com/traveloka/terraform-aws-iam-role/tree/master/modules/external )
2526* [ Instance Profile] ( https://github.com/traveloka/terraform-aws-iam-role/tree/master/modules/instance )
27+ * [ Lambda] ( https://github.com/traveloka/terraform-aws-iam-role/tree/master/modules/lambda )
2628
2729
2830Examples
@@ -31,6 +33,7 @@ Examples
3133* [ IAM Role for User] ( https://github.com/traveloka/terraform-aws-iam-role/tree/master/examples/user-iam )
3234* [ IAM Role for 3rd Party AWS Account] ( https://github.com/traveloka/terraform-aws-iam-role/tree/master/examples/external-account )
3335* [ IAM Role for Instance Profile] ( https://github.com/traveloka/terraform-aws-iam-role/tree/master/examples/instance-profile )
36+ * [ IAM Role for Lambda] ( https://github.com/traveloka/terraform-aws-iam-role/tree/master/examples/lambda-role )
3437
3538
3639Tests
Original file line number Diff line number Diff line change 1+ example/lambda_role
2+ ===================
3+
4+ This example will create an IAM Role for AWS Lambda.
Original file line number Diff line number Diff line change 1+ provider "aws" {
2+ region = " ap-southeast-1"
3+ }
4+
5+ module "this" {
6+ # In actual use case, you have to replace the following line (line 8) with:
7+ # source = "github.com/traveloka/terraform-aws-iam-role.git//modules/lambda?ref=v0.4.0"
8+ source = " ../../modules/lambda"
9+
10+ product_domain = " txt"
11+ service_name = " txtjobs"
12+ descriptive_name = " Periodic Scheduler"
13+ }
Original file line number Diff line number Diff line change 1+ terraform-aws-iam-role/lambda
2+ =============================
3+ This module allows you to create an IAM Role for AWS Lambda resource.
4+
5+
6+ Usage
7+ -----
8+ You can open this example: [ IAM Role for Lambda] ( https://github.com/traveloka/terraform-aws-iam-role/tree/master/examples/lambda-role )
Original file line number Diff line number Diff line change 1+ locals {
2+ descriptive_name = " ${ join (" -" , split (" " , lower (var. descriptive_name )))} "
3+ role_identifier = " ${ var . service_name == " " ? var . product_domain : var . service_name } -${ local . descriptive_name } "
4+ name_prefix = " LambdaRole_${ local . role_identifier } "
5+ }
6+
7+ module "random" {
8+ source = " github.com/traveloka/terraform-aws-resource-naming.git?ref=v0.4.0"
9+
10+ name_prefix = " ${ local . name_prefix } "
11+ resource_type = " iam_role"
12+ }
13+
14+ # Trust relationship policy document for AWS Service.
15+ data "aws_iam_policy_document" "this" {
16+ statement {
17+ actions = [" sts:AssumeRole" ]
18+ effect = " Allow"
19+
20+ principals {
21+ type = " Service"
22+ identifiers = [" lambda.amazonaws.com" ]
23+ }
24+ }
25+ }
26+
27+ # Module, the parent module.
28+ module "this" {
29+ source = " ../../"
30+
31+ role_name = " ${ module . random . name } "
32+ role_path = " /lambda-role/"
33+ role_description = " Lambda Role for ${ local . role_identifier } "
34+
35+ role_assume_policy = " ${ data . aws_iam_policy_document . this . json } "
36+ role_force_detach_policies = " ${ var . role_force_detach_policies } "
37+ role_max_session_duration = " ${ var . role_max_session_duration } "
38+ }
Original file line number Diff line number Diff line change 1+ output "aws_account_id" {
2+ description = " The AWS Account ID number of the account that owns or contains the calling entity."
3+ value = " ${ module . this . aws_account_id } "
4+ }
5+
6+ output "aws_caller_arn" {
7+ description = " The AWS ARN associated with the calling entity."
8+ value = " ${ module . this . aws_caller_arn } "
9+ }
10+
11+ output "aws_caller_user_id" {
12+ description = " The unique identifier of the calling entity."
13+ value = " ${ module . this . aws_caller_user_id } "
14+ }
15+
16+ output "role_name" {
17+ description = " The name of the role."
18+ value = " ${ module . this . role_name } "
19+ }
20+
21+ output "role_arn" {
22+ description = " The Amazon Resource Name (ARN) specifying the role."
23+ value = " ${ module . this . role_arn } "
24+ }
25+
26+ output "role_description" {
27+ description = " The description of the role."
28+ value = " ${ module . this . role_description } "
29+ }
30+
31+ output "role_create_date" {
32+ description = " The creation date of the IAM role."
33+ value = " ${ module . this . role_create_date } "
34+ }
35+
36+ output "role_unique_id" {
37+ description = " The stable and unique string identifying the role."
38+ value = " ${ module . this . role_unique_id } "
39+ }
Original file line number Diff line number Diff line change 1+ variable "product_domain" {
2+ description = " Product domain these resources belong to."
3+ type = " string"
4+ }
5+
6+ variable "service_name" {
7+ description = " The name of the service that going to assume this role."
8+ type = " string"
9+ default = " "
10+ }
11+
12+ variable "descriptive_name" {
13+ description = " Brief description of Lambda Function. It will be added to the role name. Example value: 'Periodic Scheduler'"
14+ type = " string"
15+ }
16+
17+ variable "role_force_detach_policies" {
18+ description = " Specifies to force detaching any policies the role has before destroying it."
19+ default = false
20+ }
21+
22+ variable "role_max_session_duration" {
23+ description = " The maximum session duration (in seconds) that you want to set for the specified role. If you do not specify a value for this setting, the default maximum of one hour is applied. This setting can have a value from 1 hour to 12 hours."
24+ default = 3600
25+ }
You can’t perform that action at this time.
0 commit comments