-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathmain.tf
47 lines (37 loc) · 1.19 KB
/
main.tf
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
terraform {
required_providers {
dataminded = {
source = "hashicorp.com/dev/dataminded"
}
}
}
provider "dataminded" {
host = "http://localhost"
port = 3000
}
locals {
chapter_config = yamldecode(file("${path.module}/chapter_config.yaml"))
chapters = keys(local.chapter_config)
users = toset(flatten([for users in values(local.chapter_config) : [for user in users : user.name]]))
chapter_roles = merge([
for chapter, users in local.chapter_config : {
for user in users : "${chapter}-${user.name}" => {
user = user.name
role = try(user.role, "Contributor")
chapter = chapter
}
}]...) // Bleh, this is ugly... Let's use a provider-defined function instead!
}
resource "dataminded_user" "user" {
for_each = local.users
name = each.key
}
resource "dataminded_chapter" "chapter" {
for_each = local.chapters
name = each.key
}
resource "dataminded_chapter_member" "chapter_member" {
for_each = provider::dataminded::chapter_config_parser(file("${path.module}/chapter_config.yaml"))
chapter = dataminded_chapter.chapter[each.value.chapter].id
member = dataminded_user.user[each.value.user].id
}