Skip to content
This repository was archived by the owner on Jul 11, 2023. It is now read-only.

Commit 30c9289

Browse files
committed
iam-group-with-membership: create a group, add a list of users as members
1 parent 64ae13b commit 30c9289

File tree

2 files changed

+47
-0
lines changed

2 files changed

+47
-0
lines changed

modules/iam-group/main.tf

+43
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,43 @@
1+
variable "group_name" {
2+
description = "The name of the group"
3+
type = string
4+
}
5+
6+
variable "members" {
7+
description = "List of strings, where each entry is the username for a user in IAM that should be a member of the group"
8+
type = list(string)
9+
}
10+
11+
variable "path" {
12+
default = "/"
13+
description = "string path in IAM, for the users created (all get the same path)"
14+
type = string
15+
}
16+
17+
variable "policy_arns" {
18+
default = []
19+
description = "List of strings, where each entry is the name of an IAM policy to attach to the group"
20+
type = list(string)
21+
}
22+
23+
resource "aws_iam_group" "g" {
24+
name = var.group_name
25+
}
26+
27+
### The list of users are each members of this group
28+
resource "aws_iam_group_membership" "main" {
29+
group = aws_iam_group.g.name
30+
name = var.group_name
31+
users = var.members
32+
}
33+
34+
resource "aws_iam_group_policy_attachment" "main" {
35+
count = length(var.policy_arns)
36+
group = aws_iam_group.g.name
37+
policy_arn = var.policy_arns[count.index]
38+
}
39+
40+
output "group" {
41+
description = "The IAM group object"
42+
value = aws_iam_group.g
43+
}

modules/iam-group/versions.tf

+4
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
2+
terraform {
3+
required_version = ">= 0.12"
4+
}

0 commit comments

Comments
 (0)