Skip to content

Commit bf013d2

Browse files
scholliiOliver Schoenborn
andauthored
feat: Enable override policy name iam-group-with-assumable-roles-policy (#468)
Co-authored-by: Oliver Schoenborn <[email protected]>
1 parent ec0484d commit bf013d2

File tree

5 files changed

+16
-7
lines changed

5 files changed

+16
-7
lines changed

examples/iam-group-with-assumable-roles-policy/main.tf

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -107,7 +107,8 @@ module "iam_group_with_assumable_roles_policy_production_readonly" {
107107
module "iam_group_with_assumable_roles_policy_production_admin" {
108108
source = "../../modules/iam-group-with-assumable-roles-policy"
109109

110-
name = "production-admin"
110+
name = "production-admin"
111+
assumable_roles_policy_name_suffix = "-assumable-roles"
111112

112113
assumable_roles = [module.iam_assumable_roles_in_prod.admin_iam_role_arn]
113114

modules/iam-group-with-assumable-roles-policy/README.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,7 @@ No modules.
3535
| Name | Description | Type | Default | Required |
3636
|------|-------------|------|---------|:--------:|
3737
| <a name="input_assumable_roles"></a> [assumable\_roles](#input\_assumable\_roles) | List of IAM roles ARNs which can be assumed by the group | `list(string)` | `[]` | no |
38+
| <a name="input_assumable_roles_policy_name_suffix"></a> [assumable\_roles\_policy\_name\_suffix](#input\_assumable\_roles\_policy\_name\_suffix) | Append this name to the policy name that will be created for assuming the given roles (default: null -- the policy name will be group name) | `string` | `""` | no |
3839
| <a name="input_group_users"></a> [group\_users](#input\_group\_users) | List of IAM users to have in an IAM group which can assume the role | `list(string)` | `[]` | no |
3940
| <a name="input_name"></a> [name](#input\_name) | Name of IAM policy and IAM group | `string` | n/a | yes |
4041
| <a name="input_path"></a> [path](#input\_path) | Path of IAM policy and IAM group | `string` | `"/"` | no |

modules/iam-group-with-assumable-roles-policy/main.tf

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ data "aws_iam_policy_document" "assume_role" {
77
}
88

99
resource "aws_iam_policy" "this" {
10-
name = var.name
10+
name = "${var.name}${var.assumable_roles_policy_name_suffix}"
1111
path = var.path
1212
description = "Allows to assume role in another AWS account"
1313
policy = data.aws_iam_policy_document.assume_role.json

modules/iam-group-with-assumable-roles-policy/variables.tf

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,12 @@ variable "assumable_roles" {
1515
default = []
1616
}
1717

18+
variable "assumable_roles_policy_name_suffix" {
19+
description = "Append this name to the policy name that will be created for assuming the given roles (default: null -- the policy name will be group name)"
20+
type = string
21+
default = ""
22+
}
23+
1824
variable "group_users" {
1925
description = "List of IAM users to have in an IAM group which can assume the role"
2026
type = list(string)

wrappers/iam-group-with-assumable-roles-policy/main.tf

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -3,9 +3,10 @@ module "wrapper" {
33

44
for_each = var.items
55

6-
assumable_roles = try(each.value.assumable_roles, var.defaults.assumable_roles, [])
7-
group_users = try(each.value.group_users, var.defaults.group_users, [])
8-
name = try(each.value.name, var.defaults.name)
9-
path = try(each.value.path, var.defaults.path, "/")
10-
tags = try(each.value.tags, var.defaults.tags, {})
6+
assumable_roles = try(each.value.assumable_roles, var.defaults.assumable_roles, [])
7+
assumable_roles_policy_name_suffix = try(each.value.assumable_roles_policy_name_suffix, var.defaults.assumable_roles_policy_name_suffix, "")
8+
group_users = try(each.value.group_users, var.defaults.group_users, [])
9+
name = try(each.value.name, var.defaults.name)
10+
path = try(each.value.path, var.defaults.path, "/")
11+
tags = try(each.value.tags, var.defaults.tags, {})
1112
}

0 commit comments

Comments
 (0)