Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
630 views
in Technique[技术] by (71.8m points)

hashicorp - Cannot list or show state in Terraform 0.14.1 with Consul remote backend

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

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)
Waitting for answers

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...