Skip to content

Commit 76d7fd0

Browse files
authored
combine iam identity modules (#12)
* combine iam identity modules * Fix main.tf * comment out assignment temporarily
1 parent 31ff205 commit 76d7fd0

File tree

6 files changed

+76
-72
lines changed

6 files changed

+76
-72
lines changed

main.tf

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,4 +28,18 @@ module "permission_sets" {
2828
policy_attachments = ["arn:aws:iam::aws:policy/AdministratorAccess"]
2929
customer_managed_policy_attachments = []
3030
}]
31+
groups = ["administrators", "developers", "networking"]
32+
33+
users = {
34+
"Zach Rundle" = {
35+
first_name = "Zach"
36+
last_name = "Rundle"
37+
groups = "administrators"
38+
},
39+
"Maverick Dog" = {
40+
first_name = "Maverick"
41+
last_name = "Dog"
42+
groups = "developers"
43+
},
44+
}
3145
}

modules/iam_identity_center/main.tf

Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -64,3 +64,43 @@ resource "aws_ssoadmin_customer_managed_policy_attachment" "this" {
6464
path = coalesce(each.value.policy_path, "/")
6565
}
6666
}
67+
68+
resource "aws_identitystore_group" "this" {
69+
for_each = { for group_name in var.groups : group_name => group_name }
70+
display_name = each.value
71+
identity_store_id = tolist(data.aws_ssoadmin_instances.this.identity_store_ids)[0]
72+
}
73+
74+
resource "aws_identitystore_user" "this" {
75+
for_each = var.users
76+
identity_store_id = tolist(data.aws_ssoadmin_instances.this.identity_store_ids)[0]
77+
display_name = format("%s %s", each.value.first_name, each.value.last_name)
78+
user_name = format("%s%s", substr(lower(each.value.first_name), 0, 1), lower(each.value.last_name))
79+
80+
name {
81+
given_name = each.value.first_name
82+
family_name = each.value.last_name
83+
}
84+
85+
emails {
86+
value = join("@", [format("%s.%s", lower(each.value.first_name), lower(each.value.last_name)), var.email_domain])
87+
}
88+
}
89+
90+
resource "aws_identitystore_group_membership" "this" {
91+
for_each = var.users
92+
identity_store_id = tolist(data.aws_ssoadmin_instances.this.identity_store_ids)[0]
93+
group_id = aws_identitystore_group.this[each.value.groups].group_id
94+
member_id = aws_identitystore_user.this[each.key].user_id
95+
}
96+
97+
# resource "aws_ssoadmin_account_assignment" "this" {
98+
# instance_arn = tolist(data.aws_ssoadmin_instances.this.arns)[0]
99+
# permission_set_arn = data.aws_ssoadmin_permission_set.this.arn
100+
101+
# principal_id = data.aws_identitystore_group.this.group_id
102+
# principal_type = "GROUP"
103+
104+
# target_id = "123456789012"
105+
# target_type = "AWS_ACCOUNT"
106+
# }

modules/iam_identity_center/variables.tf

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,4 +14,26 @@ variable "permission_sets" {
1414
}))
1515

1616
default = []
17+
}
18+
19+
variable "users" {
20+
description = "Map of user identifiers to user details including their team."
21+
type = map(object({
22+
first_name = string
23+
last_name = string
24+
# TODO: add support in case a user needs to belong to multiple groups
25+
groups = string
26+
}))
27+
}
28+
29+
variable "email_domain" {
30+
description = "Domain used for user email accounts"
31+
type = string
32+
default = "example.com"
33+
}
34+
35+
variable "groups" {
36+
description = "List of IAM identity center groups to create"
37+
type = set(string)
38+
default = []
1739
}

modules/iam_identity_users/main.tf

Lines changed: 0 additions & 34 deletions
This file was deleted.

modules/iam_identity_users/variables.tf

Lines changed: 0 additions & 21 deletions
This file was deleted.

users.tf

Lines changed: 0 additions & 17 deletions
This file was deleted.

0 commit comments

Comments
 (0)