File tree Expand file tree Collapse file tree 4 files changed +31
-4
lines changed
examples/iam-assumable-role
modules/iam-assumable-role Expand file tree Collapse file tree 4 files changed +31
-4
lines changed Original file line number Diff line number Diff line change @@ -53,6 +53,33 @@ module "iam_assumable_role_custom" {
53
53
custom_role_policy_arns = [
54
54
" arn:aws:iam::aws:policy/AmazonCognitoReadOnly" ,
55
55
" arn:aws:iam::aws:policy/AlexaForBusinessFullAccess" ,
56
+ module . iam_policy . arn
56
57
]
57
- number_of_custom_role_policy_arns = 2
58
+ # number_of_custom_role_policy_arns = 3
59
+ }
60
+
61
+ # ########################################
62
+ # IAM policy
63
+ # ########################################
64
+ module "iam_policy" {
65
+ source = " ../../modules/iam-policy"
66
+
67
+ name = " example"
68
+ path = " /"
69
+ description = " My example policy"
70
+
71
+ policy = << EOF
72
+ {
73
+ "Version": "2012-10-17",
74
+ "Statement": [
75
+ {
76
+ "Action": [
77
+ "ec2:Describe*"
78
+ ],
79
+ "Effect": "Allow",
80
+ "Resource": "*"
81
+ }
82
+ ]
83
+ }
84
+ EOF
58
85
}
Original file line number Diff line number Diff line change @@ -32,7 +32,7 @@ Trusted resources can be any [IAM ARNs](https://docs.aws.amazon.com/IAM/latest/U
32
32
| force\_ detach\_ policies | Whether policies should be detached from this role when destroying | ` bool ` | ` false ` | no |
33
33
| max\_ session\_ duration | Maximum CLI/API session duration in seconds between 3600 and 43200 | ` number ` | ` 3600 ` | no |
34
34
| mfa\_ age | Max age of valid MFA (in seconds) for roles which require MFA | ` number ` | ` 86400 ` | no |
35
- | number\_ of\_ custom\_ role\_ policy\_ arns | Number of IAM policies to attach to IAM role | ` number ` | ` 0 ` | no |
35
+ | number\_ of\_ custom\_ role\_ policy\_ arns | Number of IAM policies to attach to IAM role | ` number ` | ` null ` | no |
36
36
| poweruser\_ role\_ policy\_ arn | Policy ARN to use for poweruser role | ` string ` | ` "arn:aws:iam::aws:policy/PowerUserAccess" ` | no |
37
37
| readonly\_ role\_ policy\_ arn | Policy ARN to use for readonly role | ` string ` | ` "arn:aws:iam::aws:policy/ReadOnlyAccess" ` | no |
38
38
| role\_ description | IAM Role description | ` string ` | ` "" ` | no |
Original file line number Diff line number Diff line change @@ -72,7 +72,7 @@ resource "aws_iam_role" "this" {
72
72
}
73
73
74
74
resource "aws_iam_role_policy_attachment" "custom" {
75
- count = var. create_role ? var. number_of_custom_role_policy_arns : 0
75
+ count = var. create_role ? coalesce ( var. number_of_custom_role_policy_arns , length (var . custom_role_policy_arns )) : 0
76
76
77
77
role = aws_iam_role. this [0 ]. name
78
78
policy_arn = element (var. custom_role_policy_arns , count. index )
Original file line number Diff line number Diff line change @@ -79,7 +79,7 @@ variable "custom_role_policy_arns" {
79
79
variable "number_of_custom_role_policy_arns" {
80
80
description = " Number of IAM policies to attach to IAM role"
81
81
type = number
82
- default = 0
82
+ default = null
83
83
}
84
84
85
85
# Pre-defined policies
You can’t perform that action at this time.
0 commit comments