-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #10 from FriedCircuits/feature/JumpCloud-User-Grou…
…p-Module JumpCloud Module
- Loading branch information
Showing
6 changed files
with
106 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
# JumpCloud User and Group Management Module | ||
|
||
Using the JumpCloud provider this module will create users and groups, and assign them appropriately. | ||
|
||
|
||
## Users and Groups Variable Format | ||
|
||
```hcl | ||
groups = ["group1", "group2"] | ||
users = { | ||
user1 = { | ||
email = "[email protected]" | ||
lastname = "smith" | ||
firstname = "john" | ||
groups = ["group1","group2"] | ||
mfa = true | ||
}, | ||
user2 = { | ||
email = "[email protected]" | ||
lastname = "smith" | ||
firstname = "jane" | ||
groups = ["group1"] | ||
mfa = false | ||
} | ||
} | ||
} | ||
``` |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,39 @@ | ||
provider "jumpcloud" { | ||
org_id = var.jumpcloud_org_id | ||
api_key = var.jumpcloud_api | ||
} | ||
|
||
resource "jumpcloud_user" "users" { | ||
for_each = var.users | ||
|
||
username = each.key | ||
email = each.value["email"] | ||
firstname = title(each.value["firstname"]) | ||
lastname = title(each.value["lastname"]) | ||
enable_mfa = each.value["mfa"] | ||
} | ||
|
||
resource "jumpcloud_user_group" "groups" { | ||
for_each = toset(var.groups) | ||
name = each.value | ||
} | ||
|
||
locals { | ||
group_matrix = [ for user in keys(var.users) : | ||
setproduct([jumpcloud_user.users[user].id], [for group in var.users[user].groups : jumpcloud_user_group.groups[group].id] ) | ||
] | ||
group_flat = flatten([ | ||
for sets in local.group_matrix : [ | ||
for set in sets : { | ||
user = set[0] | ||
group = set[1] | ||
} | ||
] | ||
]) | ||
} | ||
|
||
resource "jumpcloud_user_group_membership" "members" { | ||
for_each = { for index, set in local.group_flat: index => set } | ||
user_id = each.value.user | ||
group_id = each.value.group | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
output "groups" { | ||
value =[for value in jumpcloud_user_group.groups : {(value.name)=value.id}] | ||
} | ||
|
||
output "users" { | ||
value = [for value in jumpcloud_user.users : {(value.username)=value.id}] | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
variable "jumpcloud_org_id" { | ||
description = "JumpCloud Orginzation ID found in the console." | ||
type = string | ||
} | ||
|
||
variable "jumpcloud_api" { | ||
description = "JumpCloud API key found in the console." | ||
type = string | ||
} | ||
|
||
variable "groups" { | ||
description = "Map of groups to create." | ||
type = any | ||
} | ||
|
||
variable "users" { | ||
description = "Map of users and their groups to create." | ||
type = any | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
terraform { | ||
required_version = ">= 1.0" | ||
|
||
required_providers { | ||
jumpcloud = { | ||
source = "sagewave/jumpcloud" | ||
version = "~> 0.2" | ||
} | ||
} | ||
} |