profile
viewpoint

Ask questions`terraform show <plan>` "Backend reinitialization required" within subfolder

NOTE: This ticket is when terraform is initialized above a subfolder

Terraform Version

Terraform v0.12.3
+ provider.aws v2.17.0

Terraform Configuration Files

terraform {
  backend "local" {
  }
}
provider "aws" {
}
resource "aws_sns_topic" "test" {
    name = "test"
}

Debug Output

N/A

Crash Output

N/A

Expected Behavior

The plan is show:

$ terraform show "test.plan"
  + aws_sns_topic.test
      id:     <computed>
      arn:    <computed>
      name:   "test"
      policy: <computed>

Actual Behavior

Error stating that

Backend reinitialization required

Steps to Reproduce

  1. terraform init ./subfolder-terraform
$ terraform init ./subfolder-terraform

Initializing the backend...

Successfully configured the backend "local"! Terraform will automatically
use this backend unless the backend configuration changes.

Initializing provider plugins...
- Checking for available provider plugins...
- Downloading plugin for provider "aws" (terraform-providers/aws) 2.17.0...

The following providers do not have any version constraints in configuration,
so the latest version was installed.

To prevent automatic upgrades to new major versions that may contain breaking
changes, it is recommended to add version = "..." constraints to the
corresponding provider blocks in configuration, with the constraint strings
suggested below.

* provider.aws: version = "~> 2.17"

Terraform has been successfully initialized!

You may now begin working with Terraform. Try running "terraform plan" to see
any changes that are required for your infrastructure. All Terraform commands
should now work.

If you ever set or change modules or backend configuration for Terraform,
rerun this command to reinitialize your working directory. If you forget, other
commands will detect it and remind you to do so if necessary.
  1. terraform validate ./subfolder-terraform
$ terraform validate ./subfolder-terraform`
Success! The configuration is valid.
  1. terraform plan -out=test.plan ./subfolder-terraform
$ terraform plan -out=test.plan ./subfolder-terraform
Acquiring state lock. This may take a few moments...
Refreshing Terraform state in-memory prior to plan...
The refreshed state will be used to calculate this plan, but will not be
persisted to local or remote state storage.

------------------------------------------------------------------------

An execution plan has been generated and is shown below.
Resource actions are indicated with the following symbols:
  + create

Terraform will perform the following actions:

  # aws_sns_topic.test will be created
  + resource "aws_sns_topic" "test" {
      + arn    = (known after apply)
      + id     = (known after apply)
      + name   = "test"
      + policy = (known after apply)
    }

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

------------------------------------------------------------------------

This plan was saved to: test.plan

To perform exactly these actions, run the following command to apply:
    terraform apply "test.plan"
  1. terraform show "test.plan"
Backend reinitialization required. Please run "terraform init".
Reason: Unsetting the previously set backend "local"

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.


Error: Initialization required. Please see the error message above.

Additional Context

  • This behavior works as expected with terraform version 0.11
  • The plan can still be executed with terraform plan "test.plan" successfully

References

  • https://www.terraform.io/docs/commands/show.html
hashicorp/terraform

Answer questions pecigonzalo

I believe this also affects terraform output when you have remote state unfortunately

terraform output ./terraform/
Backend reinitialization required. Please run "terraform init".
Reason: Unsetting the previously set 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.


Error: Initialization required. Please see the error message above.```
useful!

Related questions

The argument "host" is required, but no definition was found. hot 3
Unable to run 0.12upgrade hot 3
Module cannot find alias AWS provider in 0.12.0 hot 3
failed to save provider manifest: open .terraform/plugins/linux_amd64/lock.json: permission denied hot 3
Error: Invalid template interpolation value hot 2
Terraform v0.11.1 : Error downloading modules: Error loading modules: open .terraform/modules/3f10921295c292995128e9e36eb: no such file or directory hot 2
MalformedPolicyDocument: Policy document should not specify a principal. hot 2
Error in Terraform 0.12.0: This object has no argument, nested block, or exported attribute hot 2
Feature Request - Allow list/array in 'query' in 'external' data source hot 2
Terraform provider downloads fail with TLS handshake timeout hot 2
'terraform init' failed with 'Registry service unreachable.' error hot 2
for_each attribute for creating multiple resources based on a map hot 2
`Unreadable module directory` error is not clear for nested modules hot 2
Provider Development: Expected type 'string', got unconvertible type '[]interface {}' - with complicated block hot 2
Error loading state: state snapshot was created by Terraform v0.12.7, which is newer than current v0.12.6 hot 2
Github User Rank List