Skip to content

Commit

Permalink
Jumpcloud user and group management module
Browse files Browse the repository at this point in the history
  • Loading branch information
FriedCircuits committed Mar 10, 2022
1 parent 03ffce7 commit 7a682b8
Show file tree
Hide file tree
Showing 6 changed files with 106 additions and 0 deletions.
3 changes: 3 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -9,3 +9,6 @@ Hodgepodge of Terraform modules.
* K8s-At-Home - Deploy a chart from the k8s-at-home helm repo
* Traefik Ingress - Creats Ingress CRDs for host based routing
* Helm Chart - Deploy any helm chart

* JumpCloud
* Users and Groups - Manage users and group membership
28 changes: 28 additions & 0 deletions modules/jumpcloud/users-groups/README.md
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
}
}
}
```
39 changes: 39 additions & 0 deletions modules/jumpcloud/users-groups/main.tf
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
}
7 changes: 7 additions & 0 deletions modules/jumpcloud/users-groups/outputs.tf
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}]
}
19 changes: 19 additions & 0 deletions modules/jumpcloud/users-groups/variables.tf
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
}
10 changes: 10 additions & 0 deletions modules/jumpcloud/users-groups/versions.tf
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"
}
}
}

0 comments on commit 7a682b8

Please sign in to comment.