Commit afc9ffa0 authored by Anton Babenko's avatar Anton Babenko Committed by GitHub

feat: Fixed number of policies everywhere (#121)

parent 70e7898c
...@@ -53,6 +53,33 @@ module "iam_assumable_role_custom" { ...@@ -53,6 +53,33 @@ module "iam_assumable_role_custom" {
custom_role_policy_arns = [ custom_role_policy_arns = [
"arn:aws:iam::aws:policy/AmazonCognitoReadOnly", "arn:aws:iam::aws:policy/AmazonCognitoReadOnly",
"arn:aws:iam::aws:policy/AlexaForBusinessFullAccess", "arn:aws:iam::aws:policy/AlexaForBusinessFullAccess",
module.iam_policy.arn
] ]
number_of_custom_role_policy_arns = 2 # number_of_custom_role_policy_arns = 3
}
#########################################
# IAM policy
#########################################
module "iam_policy" {
source = "../../modules/iam-policy"
name = "example"
path = "/"
description = "My example policy"
policy = <<EOF
{
"Version": "2012-10-17",
"Statement": [
{
"Action": [
"ec2:Describe*"
],
"Effect": "Allow",
"Resource": "*"
}
]
}
EOF
} }
...@@ -32,7 +32,7 @@ Trusted resources can be any [IAM ARNs](https://docs.aws.amazon.com/IAM/latest/U ...@@ -32,7 +32,7 @@ Trusted resources can be any [IAM ARNs](https://docs.aws.amazon.com/IAM/latest/U
| force\_detach\_policies | Whether policies should be detached from this role when destroying | `bool` | `false` | no | | force\_detach\_policies | Whether policies should be detached from this role when destroying | `bool` | `false` | no |
| max\_session\_duration | Maximum CLI/API session duration in seconds between 3600 and 43200 | `number` | `3600` | no | | max\_session\_duration | Maximum CLI/API session duration in seconds between 3600 and 43200 | `number` | `3600` | no |
| mfa\_age | Max age of valid MFA (in seconds) for roles which require MFA | `number` | `86400` | no | | mfa\_age | Max age of valid MFA (in seconds) for roles which require MFA | `number` | `86400` | no |
| number\_of\_custom\_role\_policy\_arns | Number of IAM policies to attach to IAM role | `number` | `0` | no | | number\_of\_custom\_role\_policy\_arns | Number of IAM policies to attach to IAM role | `number` | `null` | no |
| poweruser\_role\_policy\_arn | Policy ARN to use for poweruser role | `string` | `"arn:aws:iam::aws:policy/PowerUserAccess"` | no | | poweruser\_role\_policy\_arn | Policy ARN to use for poweruser role | `string` | `"arn:aws:iam::aws:policy/PowerUserAccess"` | no |
| readonly\_role\_policy\_arn | Policy ARN to use for readonly role | `string` | `"arn:aws:iam::aws:policy/ReadOnlyAccess"` | no | | readonly\_role\_policy\_arn | Policy ARN to use for readonly role | `string` | `"arn:aws:iam::aws:policy/ReadOnlyAccess"` | no |
| role\_description | IAM Role description | `string` | `""` | no | | role\_description | IAM Role description | `string` | `""` | no |
......
...@@ -72,7 +72,7 @@ resource "aws_iam_role" "this" { ...@@ -72,7 +72,7 @@ resource "aws_iam_role" "this" {
} }
resource "aws_iam_role_policy_attachment" "custom" { resource "aws_iam_role_policy_attachment" "custom" {
count = var.create_role ? var.number_of_custom_role_policy_arns : 0 count = var.create_role ? coalesce(var.number_of_custom_role_policy_arns, length(var.custom_role_policy_arns)) : 0
role = aws_iam_role.this[0].name role = aws_iam_role.this[0].name
policy_arn = element(var.custom_role_policy_arns, count.index) policy_arn = element(var.custom_role_policy_arns, count.index)
......
...@@ -79,7 +79,7 @@ variable "custom_role_policy_arns" { ...@@ -79,7 +79,7 @@ variable "custom_role_policy_arns" {
variable "number_of_custom_role_policy_arns" { variable "number_of_custom_role_policy_arns" {
description = "Number of IAM policies to attach to IAM role" description = "Number of IAM policies to attach to IAM role"
type = number type = number
default = 0 default = null
} }
# Pre-defined policies # Pre-defined policies
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment