Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

terraform apply reporting backend configuration error with S3 after terraform init & terraform plan worked successfully

I am running terraform on my Linux instance and I am getting the terrors below.

+ /usr/local/bin/terraform workspace new test
enter code here[0m[0m[1m[33mBackend reinitialization required. Please run "terraform init".[0m

[33mReason: Initial configuration of the requested backend "s3"
The "backend" is the interface that Terraform uses to store state,
perform operations, etc. If this message is showing up, it means that the
Terraform configuration you're using is using a custom configuration for
the Terraform backend.

Changes to backend configurations require reinitialization. This allows
Terraform to setup the new configuration, copy existing state, etc. This is
only done during "terraform init". Please run that command now then try again.

If the change reason above is incorrect, please verify your configuration
hasn't changed and try again. At this point, no changes to your existing
configuration or state have been made.
[0m
[31mFailed to load backend: Initialization required. Please see the error message above.

Here is the Terraform configuration file.

provider "aws" {
  # don't touch below here
  access_key = "${var.aws_access_key}"
  secret_key = "${var.aws_secret_key}"
  region     = "us-west-2"
}

# Configure Terraform to store this in S3
terraform {
  backend "s3" {
    bucket = "nom-terraform"
    key    = "apps/onboarding/terraform.tfstate"
    region = "us-west-2"
  }
}

Before running terraform apply, I managed to run terraform plan successfully.

like image 379
Cool Eagle Avatar asked Sep 07 '25 09:09

Cool Eagle


2 Answers

Seems that you have added new s3 as backend. So terraform requires re-initialization. Just run terraform init, it will add s3 as backend and ask permission to transfer local statefile to s3.

like image 184
deepak Avatar answered Sep 09 '25 04:09

deepak


I would first delete any state file and the .terraform folder, many error exist sometimes due to corruption.

Afterwards I would run init and it should run.

I do not believe adding the backend was the issue as it should have tried to merge between the states

like image 36
Pixel Avatar answered Sep 09 '25 04:09

Pixel