-
Notifications
You must be signed in to change notification settings - Fork 9.4k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
state pull
command doesn't have a -config
flag
#17378
Comments
Hi @alexturek, It's a known issue that some of the commands that take positional arguments don't also take the legacy config path as an argument. Because Terraform is configured relative to the working directory, it's usually recommended to run it from the root of the config. Running Terraform on disparate configurations from the same directory can cause a number of confusing issues with state and providers. We are planning on cleaning up the cli UI in an upcoming release to address these issues. |
With regards to #20382 (comment) and to:
I see, but I disagree. The above assumes Terraform is the only tool to be used within a project. But a project may not be a Terraform project per-se. It could be made of different supporting tools. What if you are using Ansible and Terraform in the same project? What if you even add InSpec in the picture? Would you keep your project files as follows?
The above is a mess. I would rather keep files as follows instead (YMMV):
The above looks much more cleaner to me. Note how the root folder only contains base config stuff. I think this is a valid use case for being able to:
..from the root of the project. Then you can do things like:
And then:
...without having to [remember to] With regards to the following, specifically:
I am not sure. But I would expect providers or modules would stick to what is the "terraform base directory", which in the case above is I hope this gives enough information (that hopefully make sense) to build a case for not deprecating the PS: One thing I would probably not do or like to have is to have Terraform remember the "configuration directory" as stated in #15934. I am in favour of having to be explicit when it comes to running Terraform commands in general. |
I have this exact issue in azure devops pipeline, state file is stored in backend and when look to read it examines the root under .terraform folder after an init is ran |
The recommended way to run Terraform in the directory structure given above is:
Each working directory can only be initialized for one configuration at a time, so while these legacy compatibility arguments for setting the subdirectory can work as long as there's only one Terraform root module in your project, you'd run into problems if there were ever more than one because The change we're considering for the future is to make it so that only We do not plan to add configuration directory override arguments to any more commands, because real-world experience has shown that it is very error-prone to use Terraform in that way right now and easy to take bad actions that you didn't intend. |
Thanks for your attention on this issue @jbardin . In order to reduce the number of duplicated code and to simplify the the different environments maintenance, we are following this approach:
How we use this:
With this approach we are able to reduce the inconsistency between environments, and we avoid the problems of launching more than 1 environment from the same folder. But we are facing the issues with As far as we understand the docu this is a "good practice" (or at least not a "bad practice"),because we are facing the same issues like @alexturek and other posters we started to doubt it.
Thanks again for your help and your efforts!! |
Just want to chime in to +1 @uritau comments here. We independently came up with almost the exact same directory structure. The works well for us in most cases, but causes issues with If this sort of file layout will not be supported by terraform in the future it would be nice to have some guidance about another way to achieve the same goal of not repeating code between environments. |
We have a very similar structure & use case to @jonathangreen & @uritau as it's the only way we've found to avoid divergence between environments; one copy of the code parameterized per env. I think the suggestion in #17378 (comment) would work nicely for this setup though since terraform commands would always be executed from the "env" folders which contain the .terraform directories anyway. |
Is there any update or open issue for making |
Terraform Version
Terraform Configuration Files
Debug Output
Expected Behavior
I would hope (although this isn't documented) that
terraform state pull
would accept some sort of argument to tell it where to look for.tf
files, and output my state from S3.Actual Behavior
Terraform sees the disconnect between the seemingly unconfigured backend, and my
.terraform/terraform.tfstate
which says I have an S3 backend, and asks for aninit
.Steps to Reproduce
terraform init config
(should work if the S3 bucket/configuration is set up correctly)terraform state pull
(should fail with above error)References
terraform plan
works, it configures the backend with some options.terraform plan -config=config
works just fine for me)terraform state pull
works (and the other state commands), it doesn't seem to use anything to configure the backendThe text was updated successfully, but these errors were encountered: