1 year ago
#385906
Baracha
Nested variable - problem with getting appropriate data - terraform
I have a problem with getting appropriate data from my object variable. My variable definition looks as follows:
variable "auth0_org" {
description = "List of organizations"
default = []
type = list(object({
name = string
display_name = string
db_name = list(string)
logo_url = string
colors_primary = string
colors_page_background = string
enable_auto_membership = bool
saml_config = list(object({
connection_name = string
strategy = string
sign_in_endpoint = string
sign_out_endpoint = string
sign_saml_request = bool
user_id_attribute = string
debug = bool
signing_cert = string
enable_auto_membership = bool
fields_map = object({
email = string
nickname = string
given_name = string
family_name = string
})
}))
openid_config = list(object({
connection_name = string
strategy = string
client_id = string
client_secret = string
scopes = list(string)
discovery_url = string
type = string
allowed_applications = list(string)
}))
}))
}
Example data:
auth0_org = [
{
name = "abc"
display_name = "abc"
db_name = []
logo_url = "logo.png"
colors_primary = "#303EFA"
colors_page_background = "#0C204A"
enable_auto_membership = true
saml_config = []
openid_config = [
{
connection_name = "test-oidc"
strategy = "oidc"
client_id = "1234"
client_secret = "abc456"
scopes = ["openid", "profile", "email"]
discovery_url = "https://okta.com/.well-known/openid-configuration"
type = "front_channel"
allowed_applications = ["app01", "app02"]
},
{
connection_name = "test-oidc2"
strategy = "oidc"
client_id = "5678"
client_secret = "abc123"
scopes = ["openid", "profile", "email"]
discovery_url = "https://okta.com/.well-known/openid-configuration"
type = "front_channel"
allowed_applications = ["app01"]
}
]
}
]
I want to create OpenID connection in auth0:
resource "auth0_connection" "oidc" {
for_each = {
for item in local.openid_configs : item.connection_name => item
}
enabled_clients = ????
options {
client_id = each.value.client_id
client_secret = each.value.client_secret
scopes = each.value.scopes
discovery_url = each.value.discovery_url
type = each.value.type
}
}
locals {
openid_configs = flatten([
for org in var.auth0_org: [
for openid in org.openid_config: {
connection_name = openid.connection_name
strategy = openid.strategy
client_id = openid.client_id
client_secret = openid.client_secret
scopes = openid.scopes
discovery_url = openid.discovery_url
type = openid.type
allowed_applications = openid.allowed_applications
}
]
])
allowed_apps = flatten([
for app in local.openid_configs: app["allowed_applications"]
]
}
To be able to do that I need to specify applications IDs list in enabled_clients
.
So far I have application names in my variable: openid_config.allowed_applications
for example:
allowed_applications = ["app01", "app02"]
Do you have any suggestion how can I do that? I was trying to get this using data source like this:
data "auth0_client" "application" {
for_each = toset(local.allowed_apps)
name = each.value
}
But I don't know how to use this data source in enabled_clients
.
Any suggestions are more than welcome.
(Update)
I've made few different attempts. It's working from code perspective but it's logically wrong. I think I should simplify my question.
In the code as a enabled_clients
I can use each.value.allowed_applications
like:
resource "auth0_connection" "oidc" {
for_each = {
for item in local.openid_configs : item.connection_name => item
}
enabled_clients = each.value.allowed_applications
options {
client_id = each.value.client_id
client_secret = each.value.client_secret
scopes = each.value.scopes
discovery_url = each.value.discovery_url
type = each.value.type
}
}
But this give me list of app names instead of its IDs: ["app01", "app02"]
.
Let's say also I have this kind of data structure:
allowed_apps_id = {
app01 = "cbsdibcscbb2323"
app02 = "cjsbsbsbxy666sa"
}
How to change the line:
enabled_clients = each.value.allowed_applications
to get IDs instead of names?
terraform
nested-loops
0 Answers
Your Answer