# Terraform plan gives Unable to find remote state

**URL:** <https://discuss.hashicorp.com/t/terraform-plan-gives-unable-to-find-remote-state/41409>\
**Category:** Terraform\
**Created:** [June 29, 2022, 3:58pm UTC](https://discuss.hashicorp.com/t/terraform-plan-gives-unable-to-find-remote-state/41409 "2022-06-29T15:58:23Z")\
**Posts on this page:** 8\
**Page:** 1

<div class="post-metadata">

**Author:** ![Arc\_lag](https://sea2.discourse-cdn.com/hashicorp/user_avatar/discuss.hashicorp.com/arc_lag/32/27851_2.png) [@Arc\_lag](https://discuss.hashicorp.com/u/Arc_lag)\
**Post date:** [June 29, 2022, 3:58pm UTC](https://discuss.hashicorp.com/t/terraform-plan-gives-unable-to-find-remote-state/41409/1 "2022-06-29T15:58:23Z")

</div>

Hi Terraform team  
I made a thread two weeks ago regarding the project structure.

> [@Azurerm CDKTF C# general project structure tips](https://discuss.hashicorp.com/t/azurerm-cdktf-c-general-project-structure-tips/40740/2):
>
> You absolutely can (and should) split up your code. That’s really one of the most powerful aspects of cdk. You are free to divide and structure your infrastructure code using the same techniques you would use for application code. Take a look [here](https://www.terraform.io/cdktf/create-and-deploy/best-practices#application-architecture) for some more tips.

The final resulting structure are multiple resource stacks:

![image](https://global.discourse-cdn.com/hashicorp/original/3X/9/0/900477300161dbbc8ea4a12062fbbdee18733c38.png)  
There’s only one issue I’m having. If I try to run Terraform plan within the Kubernetes as well as Networking stack, I get the following error:

```auto
.\terraform.exe plan
data.terraform_remote_state.Kubernetes_crossstackreferenceinputNetwork_0E12A4F6: Reading...
data.terraform_remote_state.Kubernetes_crossstackreferenceinputResourceGroup_921D924C: Reading...
data.terraform_remote_state.Kubernetes_crossstackreferenceinputResourceGroup_921D924C: Still reading... [10s elapsed]
data.terraform_remote_state.Kubernetes_crossstackreferenceinputNetwork_0E12A4F6: Still reading... [10s elapsed]
╷
│ Error: Unable to find remote state
│
│ with data.terraform_remote_state.Kubernetes_crossstackreferenceinputNetwork_0E12A4F6,
│ on cdk.tf.json line 18, in data.terraform_remote_state.Kubernetes_crossstackreferenceinputNetwork_0E12A4F6:
│ 18: "workspace": "${terraform.workspace}"
│
│ No stored state was found for the given workspace in the given backend.
╵

```

The same error applies even after initialising and planning the ResourceGroup stack.  
What am I missing? The ResourceGroup stack pm its own is planning, same as the Storage stack but that’s obvious as those don’t have “dependencies”, unlike the Networking and Kubernetes stacks

Thank you as always!

---

<div class="post-metadata">

**Author:** ![Arc\_lag](https://sea2.discourse-cdn.com/hashicorp/user_avatar/discuss.hashicorp.com/arc_lag/32/27851_2.png) [@Arc\_lag](https://discuss.hashicorp.com/u/Arc_lag)\
**Post date:** [June 30, 2022, 12:55pm UTC](https://discuss.hashicorp.com/t/terraform-plan-gives-unable-to-find-remote-state/41409/2 "2022-06-30T12:55:32Z")

</div>

Bumping just in case

---

<div class="post-metadata">

**Author:** ![jsteinich](https://sea2.discourse-cdn.com/hashicorp/user_avatar/discuss.hashicorp.com/jsteinich/32/9502_2.png) [@jsteinich](https://discuss.hashicorp.com/u/jsteinich)\
**Post date:** [July 2, 2022, 7:25pm UTC](https://discuss.hashicorp.com/t/terraform-plan-gives-unable-to-find-remote-state/41409/3 "2022-07-02T19:25:03Z")

</div>

Which backend do you have configured?  
Are you intentionally using Terraform workspaces and if so, have you selected the workspace that is in use?

---

<div class="post-metadata">

**Author:** ![Arc\_lag](https://sea2.discourse-cdn.com/hashicorp/user_avatar/discuss.hashicorp.com/arc_lag/32/27851_2.png) [@Arc\_lag](https://discuss.hashicorp.com/u/Arc_lag)\
**Post date:** [July 3, 2022, 10:17am UTC](https://discuss.hashicorp.com/t/terraform-plan-gives-unable-to-find-remote-state/41409/4 "2022-07-03T10:17:29Z")

</div>

Thank you for replying @jsteinich ! I was losing my mind over this.  
I did not have a backend configured yet, I did not deem that necessary as this error is not unique to only StorageAccounts but my Kubernetes class as well (it references the networking resources).  
No, I am not using workspaces, there is no declaration of a workspace in any of my classes.  
I’ll try adding a backend config and see if that changes things!

---

<div class="post-metadata">

**Author:** ![Arc\_lag](https://sea2.discourse-cdn.com/hashicorp/user_avatar/discuss.hashicorp.com/arc_lag/32/27851_2.png) [@Arc\_lag](https://discuss.hashicorp.com/u/Arc_lag)\
**Post date:** [July 3, 2022, 12:25pm UTC](https://discuss.hashicorp.com/t/terraform-plan-gives-unable-to-find-remote-state/41409/5 "2022-07-03T12:25:31Z")

</div>

Okay, It seems to not give the “unable to read state” error (for now?)  
Instead I get an error that the value of the `ResourceGroup.Name` is too long (over 90 chars). This happens with the following declaration of the StorageAccount stack:

```auto
            AzurermBackend azurermBackend = new(this, new AzurermBackendProps
            {
                ResourceGroupName = DefaultVars.getResourceGroupName(),
...
            }

```

The `ResourceGroup.Name `is simply `"cas-sys-devtest"`. I originally referenced it through the name of the resource itself (`ResourceGroup.Name`). But that causes a value of over 200 chars to be generated, which bricks the interpreter.

(value of the 200 char long resourcegroup name:  
`"${data.terraform_remote_state.Storage_crossstackreferenceinputResourceGroup_C0FA14C2.outputs.ResourceGroup_crossstackoutputazurermresourcegroupResourceGroupazurermresourcegroupBD617C89name_8FD233F4}"`)

In order to try and fix it, I tried to assign a hardcoded value, and as such, directly bind `cas-sys-devtest` to the name.

This causes yet another error:

> Error: Failed to get existing workspaces: Error retrieving keys for Storage Account “authtickets”: storage.AccountsClient#ListKeys: Failure responding to request: StatusCode=404 – Original Error: autorest/azure: Service returned an error. Status=404 Code=“ResourceGroupNotFound” Message=“Resource group ‘cassys-we-devtest-rg’ could not be found.”

What is the appropriate way of passing the name of the resourcegroup here?

---

<div class="post-metadata">

**Author:** ![jsteinich](https://sea2.discourse-cdn.com/hashicorp/user_avatar/discuss.hashicorp.com/jsteinich/32/9502_2.png) [@jsteinich](https://discuss.hashicorp.com/u/jsteinich)\
**Post date:** [July 7, 2022, 1:42am UTC](https://discuss.hashicorp.com/t/terraform-plan-gives-unable-to-find-remote-state/41409/6 "2022-07-07T01:42:55Z")

</div>

Backends can’t reference other resources. Everything needs to be known at synth time. This means hardcoding, reading from a configuration file, or using more advanced Terraform workflows in addition to cdktf.

I’m not very familiar with the Azure backend, but from the looks of the error I have a few ideas:

- The resource group hasn’t been created yet.
- The name entered doesn’t match what it was created with.
- The credentials used to access to have access to the group.

---

<div class="post-metadata">

**Author:** ![faniemo](https://sea2.discourse-cdn.com/hashicorp/user_avatar/discuss.hashicorp.com/faniemo/32/34515_2.png) [@faniemo](https://discuss.hashicorp.com/u/faniemo)\
**Post date:** [March 15, 2023, 6:36am UTC](https://discuss.hashicorp.com/t/terraform-plan-gives-unable-to-find-remote-state/41409/7 "2023-03-15T06:36:43Z")

</div>

Hi, was this issue resolved? If so, please can you tell us how.

thanx

---

<div class="post-metadata">

**Author:** ![Arc\_lag](https://sea2.discourse-cdn.com/hashicorp/user_avatar/discuss.hashicorp.com/arc_lag/32/27851_2.png) [@Arc\_lag](https://discuss.hashicorp.com/u/Arc_lag)\
**Post date:** [March 15, 2023, 12:09pm UTC](https://discuss.hashicorp.com/t/terraform-plan-gives-unable-to-find-remote-state/41409/8 "2023-03-15T12:09:54Z")

</div>

Hey, I haven’t been able to spend too much time on the issue back then as I was in a time constraint.

What I did in order to fix it is to get rid of the file structure and just create one God file, structured with all the resources per category in the form of comments.

Not my proudest moment but I had to deliver results
