I have a Terraform 0.14.1 project with a Consul remote backend, and having troubles viewing or modifying state with terraform state
.
The project has a tree structure as follows,
.
└── environments
?? ├── production
?? │?? └── main.tf
?? └── test
?? └── main.tf
I'm able to run the following commands (from the root of the project that contains the directory environments
) without issue,
terraform init environments/test
terraform plan -out test.tfplan environments/test
terraform apply test.tfplan
However when I want to view state with the following command,
terraform state show module.foo
I get the error,
Backend reinitialization required. Please run "terraform init".
Reason: Unsetting the previously set backend "consul"
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.
I can run init
again but I still get this message.
It doesn't look like the state
command has an option for pointing to a particular config directory like some of the other commands.
As a workaround when I want to work with state I change directories to environments/test
and run terraform init .
. Then I can view and modify state.
Am I overlooking something, or is the terraform state
command just lacking the ability to work with custom config directories? Thanks
question from:
https://stackoverflow.com/questions/65672224/cannot-list-or-show-state-in-terraform-0-14-1-with-consul-remote-backend 与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…