Guys, I'm trying to move the terraform.tfstate to gcp bucket but all the time wh . . .

Pyroass:
Guys, I’m trying to move the terraform.tfstate to gcp bucket but all the time when i do terraform init, will create the .terraform directory with providers into it and terraform.tfstate locally. how can I manage to repair this?

resource "google_storage_bucket" "xxx" {
  name = var.name
  location = var.region
  storage_class = var.storage_class
}
terraform {
  backend "gcs" {
    bucket  = "xxx"
    prefix  = "backend/terraform.tfstate"
  }
}

Cai Walkowiak:
The .terraform folder will still be created - this is how your local environment runs the providers it is using.
When you apply it should move the state file up to the bucket. There may be a backup file that remains

Mohamed Ayman:
You need to run the following commands:

  1. terraform init -backend-config="bucket=xxx" -backend-config="prefix=backend/terraform.tfstate"
  2. terraform state push
    This will move the Terraform state from the local disk to the Google Cloud Storage bucket.
    https://developer.hashicorp.com/terraform/cli/commands/state/push