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
Running terraform init on a subdirectory with s3 backend causes terraform workspace command to fail with uninitialized backend error #18030
Comments
Hi @sverchdotgov, Thanks for filing this with the complete example. For now the recommended workflow is to always run terraform from the root of the configuration for consistency, which also has the benefit of making it explicit which configuration the working directory has been initialized for. We are planning to refactor the UI in an future release to improve the consistency of the various operations. |
Thanks for the response @jbardin! So it sounds like running terraform against a directory that isn't the current directory is effectively not fully supported until you refactor the UI. Is that right? I think kitchen-terraform depends on that as a core part of how it works, so that's good to know explicitly. See newcontext-oss/kitchen-terraform#237. |
…ctable name for the s3 bucket # Change 1: Workaround Terraform problem when using a remote state Terraform assumes it is running from within the root directory of the modules (where `main.tf` is located) on many of its commands. This problem does not show up when using a local state as we were doing before, however, when using remote state (S3) then the problem shows up. The bug has been reported multiple times to Terraform: - hashicorp/terraform#18030 - hashicorp/terraform#16723 To which their answer is: > running terraform against a directory that isn't the current directory > is not fully supported # Change 2: Make the name of the s3 bucket to be predictable It is better to have a predictable s3 bucket name because it allows "importing" the state on a new machine. This required moving the `region` parameter handling into the baictl, out of terraform because the region name is in the bucket name. This is not strictly required, but it will allow us to create multiple clusters in the same account later on. It also keeps the bucket within the same region as specified by the user.
Run Terraform the deployment folder due to hashicorp/terraform#18030 Update GitHub release file location Use base64 sha256 hash to check if deployment is required Fix delete subscription filter test Update the readme with Terraform deployment steps
This is a real issue when running automated builds with sub-folders.
|
Looks like a shift of the software consistency responsibility from developers to users. A documented bug is a feature (c). What's the problem to support setting the "working directory" from a command-line parameter? |
BTW, I don't understand what's the benefit of using the "per-directory" design pattern instead of the explicit setting of "entry points" and explicit file relations. Save 3 lines of code in a 5,000-line configuration and add 100 lines of workarounds in CI/CD scripts managing "correct" working directories of multiple TF configs and transforming relative file and dir paths to the "terraform current directory"? |
This is a feature I am also missing - and I would really ask for consistency here in the cli as @speller already explained. |
Hi, @jbardin. It would be nice to have this behaviour documented somewhere in bold: basically it means that if you're initializing Terraform in a subdirectory, you have limited functionality in case of remote backend. I've just imported some resource and I can't unimport ( Also, if I try to explicitly define state file for My Terraform version is 0.12.28. |
For 0.14 we are planning to move to a global |
I want to apologize for the slow response time on this issue, and also let you know that I am bulk-closing all issues exclusively reported against Terraform 0.11.x, including this issue, because we are no longer investigating issues reported against Terraform 0.11.x. In most cases, when we try to reproduce issues reported against 0.11, we either can't reproduce them anymore, or the reporter has moved on, so we believe we can better support the Terraform user community by prioritizing more recent issues. Terraform 0.12 has been available since May of 2019, and there are really significant benefits to adopting it. I know that migrating from 0.11 to versions past 0.12 can require a bit of effort, but it really is worth it, and the upgrade path is pretty well understood in the community by now. 0.14 is available and stable, and we are quickly approaching an 0.15 release. We have made a significant effort in the last year to stay on top of bug reports; we have triaged almost all new bug reports within 1-2 weeks for 6+ months now. If you are still experiencing this problem, please submit a new bug report with a reproduction case that works on 0.14.x, link this old issue for context, and we will triage it. |
I'm going to lock this issue because it has been closed for 30 days ⏳. This helps our maintainers find and focus on the active issues. If you have found a problem that seems similar to this, please open a new issue and complete the issue template so we can capture all the details necessary to investigate further. |
Terraform Version
Terraform Configuration Files
Expected Behavior
After running terraform init I can run terraform workspace commands against that remote s3 state, even if I run terraform init on a subdirectory.
Actual Behavior
When I run terraform init on a subdirectory terraform workspace things I haven't initialized the state.
Running terraform init pointing to the current directory:
Running terraform init on a subdirectory:
Steps to Reproduce
See above. Create a basic terraform configuration and run terraform init on a subdirectory.
References
newcontext-oss/kitchen-terraform#237
The text was updated successfully, but these errors were encountered: