-
Notifications
You must be signed in to change notification settings - Fork 24
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
tf_module access_control and examples
- Loading branch information
Showing
7 changed files
with
183 additions
and
4 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
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,69 @@ | ||
data "codefresh_idps" "idps" { | ||
for_each = var.default_idps | ||
_id = lookup(each.value, "_id", "") | ||
display_name = lookup(each.value, "display_name", "") | ||
client_name = lookup(each.value, "client_name", "") | ||
client_type = lookup(each.value, "client_type", "") | ||
} | ||
|
||
resource "codefresh_account" "acc" { | ||
for_each = var.accounts | ||
name = each.key | ||
|
||
features = var.default_account_features | ||
|
||
limits { | ||
collaborators = lookup(var.default_acccount_limits, "collaborators", 10) | ||
} | ||
|
||
build { | ||
parallel = lookup(var.default_acccount_limits, "parallel_builds", 1) | ||
} | ||
|
||
} | ||
|
||
resource "codefresh_idp_accounts" "acc_idp" { | ||
for_each = var.default_idps | ||
idp_id = data.codefresh_idps.idps[each.key].id | ||
account_ids = values(codefresh_account.acc)[*].id | ||
} | ||
|
||
resource "codefresh_user" "users" { | ||
for_each = var.users | ||
user_name = each.key | ||
email = each.value.email | ||
|
||
accounts = [ | ||
for acc_name in each.value.accounts: codefresh_account.acc[acc_name].id | ||
] | ||
|
||
activate = true | ||
|
||
roles = each.value.global_admin ? ["Admin","User"] : ["User"] | ||
|
||
dynamic "login" { | ||
for_each = var.default_idps | ||
content { | ||
idp_id = data.codefresh_idps.idps[login.key].id | ||
sso = login.value.sso | ||
} | ||
} | ||
|
||
personal { | ||
first_name = each.value.personal.first_name | ||
last_name = each.value.personal.last_name | ||
} | ||
} | ||
|
||
resource "codefresh_account_admins" "acc_admins" { | ||
for_each = toset(flatten([ | ||
for u in var.users: | ||
u.admin_of_accounts if length(u.admin_of_accounts) > 0 | ||
])) | ||
|
||
account_id = codefresh_account.acc[each.value].id | ||
users = [ | ||
for k, u in var.users: | ||
codefresh_user.users[k].id if contains(u.admin_of_accounts, each.key) | ||
] | ||
} |
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,14 @@ | ||
output "idps" { | ||
value = { | ||
for idp in data.codefresh_idps.idps: | ||
idp.id => { client_name = idp.client_name, | ||
display_name = idp.display_name | ||
} | ||
} | ||
} | ||
output "accounts" { | ||
value = { | ||
for acc in codefresh_account.acc: | ||
acc.id => acc.name | ||
} | ||
} |
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,4 @@ | ||
provider "codefresh" { | ||
api_url = var.api_url | ||
token = var.token | ||
} |
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,81 @@ | ||
variable api_url { | ||
type = string | ||
} | ||
|
||
# | ||
variable token { | ||
type = string | ||
default = "" | ||
} | ||
|
||
variable default_account_features { | ||
type = map(any) | ||
default = { | ||
OfflineLogging = true, | ||
ssoManagement = true, | ||
teamsManagement = true, | ||
abac = true, | ||
customKubernetesCluster = true, | ||
launchDarklyManagement = false, | ||
} | ||
} | ||
|
||
variable default_acccount_limits { | ||
type = map(any) | ||
default = { | ||
collaborators = 100 | ||
parallel_builds = 10 | ||
} | ||
} | ||
|
||
variable default_idps { | ||
type = map(any) | ||
default = { | ||
local = { | ||
display_name = "local" | ||
sso = false | ||
} | ||
} | ||
} | ||
|
||
# map of accounts indexed by unique account name | ||
# accounts = { | ||
# acc1 = { | ||
# } | ||
# acc2 = { | ||
# limits = { | ||
# collaborators = 50 | ||
# parallel_builds = 5 | ||
# } | ||
# } | ||
# } | ||
variable accounts { | ||
type = map(any) | ||
} | ||
|
||
# map of users: | ||
# users = { | ||
# user1 = { | ||
# email = "[email protected]" | ||
# personal = { | ||
# first_name = "Q" | ||
# last_name = "D" | ||
# } | ||
# accounts = ["acc1", "acc2"] | ||
# global_admin = false | ||
# } | ||
# user2 = { | ||
|
||
# email = "[email protected]" | ||
# personal = { | ||
# first_name = "Q" | ||
# last_name = "D" | ||
# } | ||
# accounts = ["acc1", "acc2"] | ||
# global_admin = true | ||
# } | ||
# } | ||
variable users { | ||
//type = map(any) | ||
} | ||
|