Terraform Error Resource Not Found During Apply

I’m trying to use a cloud storage backend to deploy tfe_variable resources to a Terraform Enterprise workspace. I have used the tfe provider in the configuration. I have been successfully able to run both plan and apply on my local machine, and I can see the variables being deployed to the Terraform Enterprise workspace I’m working with.

But when I try to run in CLI after deployment, the plan command runs successfully, creating the right plan but the apply fails with the following error: “Error creating terraform variable “variable_name”: resource not found” for all the variables. I have tried a lot of things to get to the root cause of it but to no avail. I’m using terraform 0.14.10 for my runs.

Any feedback here would be really appreciated.

Hello!

Happy to help! Could you share more details such as…

  • Some snippets of the configuration(s) you’re using?
  • Is the workspace that you’re provisioning tfe_variable resources with the same as the one you’re provisioning the variables to?
  • Are you using the remote backend in the CLI? What’s that configuration look like?

Thanks @chrisarcand !

terraform {
    backend "azurerm" {}
    # values passed to this at runtime using -backend-config
}

provider "tfe" {
    hostname = var.hostname_value
    token = var.token_value
}

resource "tfe_variable" "var1" {key, value, workspace_id.. so on}
resource "tfe_variable" "var2" {key, value, workspace_id.. so on}

The terraform version that I’m running is 0.14.10. I can run this locally on my machine and it successfully updates the state file at the Azure backend as well as provisions the variables into the Terraform Enterprise workspace.

I didn’t quite get what you meant by the second point. The terraform commands are run using Azure backend. The target for the deployment of tfe_variable resources is based on the workspace_id and hostname arguments.

But when I try to run in CLI after deployment

I’m not sure I understand this part, I mean - do you mean, when you try and do another plan on that same configuration locally, expecting an empty plan with no changes? Or maybe trying to run a plan in the TFE workspace you just provisioned to locally? Where and what are you trying to apply that second time after you’ve successfully provisioned variables to your TFE workspace from your local CLI?