Skip to content

Commit c5e6cb5

Browse files
committed
combine iam identity modules
1 parent 31ff205 commit c5e6cb5

File tree

4 files changed

+68
-55
lines changed

4 files changed

+68
-55
lines changed

modules/iam_identity_center/main.tf

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

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.

0 commit comments

Comments
 (0)