# How to reference a file from different directory in current terraform code

**URL:** <https://devforum.okta.com/t/how-to-reference-a-file-from-different-directory-in-current-terraform-code/27117>\
**Category:** API\
**Tags:** terraform\
**Created:** [March 4, 2024, 7:07am UTC](https://devforum.okta.com/t/how-to-reference-a-file-from-different-directory-in-current-terraform-code/27117 "2024-03-04T07:07:48Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![suren424](https://avatars.discourse-cdn.com/v4/letter/s/ed655f/32.png) [@suren424](https://devforum.okta.com/u/suren424)\
**Post date:** [March 4, 2024, 7:07am UTC](https://devforum.okta.com/t/how-to-reference-a-file-from-different-directory-in-current-terraform-code/27117/1 "2024-03-04T07:07:48Z")

</div>

Hi Team,

I have 2 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.

My requirement is to use the app\_dev1.json file for group assignments in dev2 app. the group defined in app\_dev1.json file is already created in Okta org. How can i refer app\_dev1.json file in app\_dev2.tf file so that it can be used for dev2 app group assignments along with the groups mentioned in app\_dev2.json file. groups in app\_dev2.json file will be created when the app\_dev2.tf code is executed.

I tried this code:

```auto
locals {
    app_dev2_data = values(jsondecode(file("${path.module}/app_dev2.json")))
    dev1_access_data = values(jsondecode(file("${path.module}/../app_dev1/app_dev1.json")))
   
}

resource "okta_group" "dev2_access_groups" {
    for_each = {
     for x in local.app_dev2_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.app_dev2_data: x.name => x 
    }

    group {
        id = okta_group.dev2_access_groups[each.value.name].id
        profile = jsonencode(each.value.profile)
    }
  
}

resource "okta_app_group_assignments" "dev2_1" {
    app_id ="0oafialoynRTLysCg5d7"
  
  lifecycle {
      ignore_changes = [group]
      create_before_destroy = true
    }

    for_each = {
       for x in local.dev1_access_data: x.name => x 
    }

    group {
        id = each.value.name
        profile = jsonencode(each.value.profile)
    }
}

```

This is the error from above code:

```auto
  Enter a value: yes

okta_app_group_assignments.dev2_1["SG_SSO_Dev1_Access"]: Creating...
okta_group.dev2_access_groups["SG_SSO_Dev2_Access"]: Creating...
okta_group.dev2_access_groups["SG_SSO_Dev2_Access"]: Creation complete after 0s [id=00gfidevfm24mGtT25d7]
okta_app_group_assignments.dev2["SG_SSO_Dev2_Access"]: Creating...
okta_app_group_assignments.dev2["SG_SSO_Dev2_Access"]: Creation complete after 0s [id=0oafialoynRTLysCg5d7]
╷
│ Error: failed to create application group assignment: the API returned an error: Not found: Resource not found: SG_SSO_Dev1_Access (UserGroup)
│ 
│ with okta_app_group_assignments.dev2_1["SG_SSO_Dev1_Access"],
│ on app_dev2.tf line 37, in resource "okta_app_group_assignments" "dev2_1":
│ 37: resource "okta_app_group_assignments" "dev2_1" {

```

Am i missing anything in the code. Could you please guide me in the right direction. Thanks in advance.

Thanks,

---

<div class="post-metadata">

**Author:** ![piyusha](https://avatars.discourse-cdn.com/v4/letter/p/91b2a8/32.png) [@piyusha](https://devforum.okta.com/u/piyusha)\
**Post date:** [March 8, 2024, 7:53pm UTC](https://devforum.okta.com/t/how-to-reference-a-file-from-different-directory-in-current-terraform-code/27117/2 "2024-03-08T19:53:58Z")

</div>

Hello! This question is more about Terraform in general, rather than Okta specifically.

I did some research and found these options:

- [Call a terraform variable from a different directory - Terraform - HashiCorp Discuss](https://discuss.hashicorp.com/t/call-a-terraform-variable-from-a-different-directory/25044)
- [Read locals from another folder - #4 by nnv - Terraform - HashiCorp Discuss](https://discuss.hashicorp.com/t/read-locals-from-another-folder/39713/4)

One of the suggestions mentioned above might work for you.

---

<div class="post-metadata">

**Author:** ![suren424](https://avatars.discourse-cdn.com/v4/letter/s/ed655f/32.png) [@suren424](https://devforum.okta.com/u/suren424)\
**Post date:** [March 9, 2024, 12:14am UTC](https://devforum.okta.com/t/how-to-reference-a-file-from-different-directory-in-current-terraform-code/27117/3 "2024-03-09T00:14:12Z")

</div>

Hi Piyusha,

Thank you very much for providing those reference links. First link worked for us. Thanks again.

Regards,

---

<div class="post-metadata">

**Author:** ![system](https://global.discourse-cdn.com/oktadev/original/1X/589c4c5f80de422d01f47cee7185a7fb8227835c.png) [@system](https://devforum.okta.com/u/system)\
**Post date:** [March 10, 2024, 12:15am UTC](https://devforum.okta.com/t/how-to-reference-a-file-from-different-directory-in-current-terraform-code/27117/4 "2024-03-10T00:15:12Z")

</div>

This topic was automatically closed 24 hours after the last reply. New replies are no longer allowed.
