"No stored state was found for the given workspace in the given backend" after `terraform init`

Hello community !

I’m following the GitLab-managed Terraform state documentation in order to create a new terraform repository on gitlab.com.

I have successfully ran terraform init like it is described so that I have a state file in my repository Terraform states page on gitlab.com.
Now running terraform plan show me the plan, but terraform exits with the following error:

Plan: 4 to add, 0 to change, 0 to destroy.

Changes to Outputs:
  + kubeconfig = (sensitive value)
│ Error: Unable to find remote state
│   with data.terraform_remote_state.default,
│   on remote_state.tf line 1, in data "terraform_remote_state" "default":
│    1: data "terraform_remote_state" "default" {
│ No stored state was found for the given workspace in the given backend.

Here is my file where I’m declaring the remote_state as described in the doc:

data "terraform_remote_state" "default" {
  backend = "http"

  config = {
    address  = "https://gitlab.com/api/v4/projects/${var.gitlab_project_id}/terraform/state/default"
    username = var.gitlab_username
    password = var.gitlab_access_token

Running TF_LOG=DEBUG terraform plan shows me that it uses the right URL, also it locks the file on gitlab.com so all seem fine from this point of view.

I have created a public minimal repository reproducing the issue and opened an issue.

Could you please help me to understand that error and fix it?


I was able to get it working following the 2 following steps:

  1. Remove the backend.tf and remote_state.tf files and run terraform init in order to create a local state file
  2. Use the Gitlab’s terraform init command which pushed the local file to the Gitlab remote state page