Hi Team,
I have 2 folders/directories where i have the code for each of them: app_dev1 and app_dev2
app_dev1 contains app_dev1.json file which defines the groups for dev1 app and it’s being used in app_dev1.tf code
app_dev2 contains app_dev2.json file which defines the groups for dev2 app and it’s being used in app_dev2.tf.
I also want to use the app_dev1.json file for group assignments in dev2 app. How can i refer app_dev1.json file in app_dev2.tf file.
I tried below code:
locals {
app_dev2_data = jsondecode(file("${path.module}/app_dev2.json"))
dev1_access_data = jsondecode(file("${path.module}/app_dev2/app_dev1.json"))
combined_data = concat(local.app_dev2_data, local.dev1_access_data)
}
resource "okta_group" "dev2_access_groups" {
for_each = {
for x in local.combined_data: x.name => x
}
name = each.value.name
description = "Terraform managed group from app_dev2.tf"
}
resource "okta_app_group_assignments" "dev2" {
app_id ="0oafialoynRTLysCg5d7"
lifecycle {
ignore_changes = [ group ]
create_before_destroy = true
}
for_each = {
for x in local.local.combined_data: x.name => x
}
group {
id = okta_group.dev2_access_groups [each.value.name].id
profile = jsonencode(each.value.profile)
}
}
output "groups" {
description = "List of access groups"
value = okta_group.dev2_access_groups
}
but, this one is giving below error message:
Error: Invalid function argument
│
│ on app_dev2_1.tf line 3, in locals:
│ 3: dev1_access_data = jsondecode(file(“${path.module}/app_dev2/app_dev1.json”))
│ ├────────────────
│ │ while calling file(path)
│ │ path.module is “.”
│
│ Invalid value for “path” parameter: no file exists at “./app_dev2/app_dev1.json”; this function
│ works only with files that are distributed as part of the configuration source code, so if this
│ file will be created by a resource in this configuration you must instead obtain this result from
│ an attribute of that resource.
Could you please help me on what is the best way to do this. Thanks in advance and appreciate your time in looking int this.
Thank you,