-
Notifications
You must be signed in to change notification settings - Fork 9.9k
Description
Terraform Version
Terraform v1.11.3
on darwin_amd64
+ provider registry.terraform.io/hashicorp/local v2.1.0
+ provider registry.terraform.io/hashicorp/random v3.7.2
Your version of Terraform is out of date! The latest version
is 1.12.2. You can update by downloading from https://www.terraform.io/downloads.html
Terraform Configuration Files
...terraform config...
Debug Output
May not be relavent, but here is the output of terraform init
$ terraform init
Initializing the backend...
Initializing modules...
Downloading git::https://github.com/miguelhrocha/terraform-example-module for inner_example_complete...
- inner_example_complete in .terraform/modules/inner_example_complete/examples/complete
- inner_example_complete.example in .terraform/modules/inner_example_complete
Downloading registry.terraform.io/cloudposse/label/null 0.25.0 for inner_example_complete.example.this...
- inner_example_complete.example.this in .terraform/modules/inner_example_complete.example.this
Downloading registry.terraform.io/cloudposse/label/null 0.25.0 for inner_example_complete.this...
- inner_example_complete.this in .terraform/modules/inner_example_complete.this
Initializing provider plugins...
- Reusing previous version of hashicorp/local from the dependency lock file
- Reusing previous version of hashicorp/random from the dependency lock file
- Using previously-installed hashicorp/local v2.1.0
- Using previously-installed hashicorp/random v3.7.2
╷
│ Warning: Redundant empty provider block
│
│ on .terraform/modules/inner_example_complete/examples/complete/providers.tf line 1:
│ 1: provider "local" {
│
│ Earlier versions of Terraform used empty provider blocks ("proxy provider configurations") for child modules to declare their need to be passed a provider
│ configuration by their callers. That approach was ambiguous and is now deprecated.
│
│ If you control this module, you can migrate to the new declaration syntax by removing all of the empty provider "local" blocks and then adding or updating an entry
│ like the following to the required_providers block of module.inner_example_complete:
│ local = {
│ source = "hashicorp/local"
│ }
│
│ (and one more similar warning elsewhere)
╵
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.
Expected Behavior
When I use source
with a git repo in a module block I expect that the local copy of the git repo will have the original name of the git repo NOT the name of the module. When specifying a sub-module in a git repo using the double slash notation "//" I expect that the local copy of the git repo and the sub-module to both have their original names. IF either the git repo or the sub-module were going to be renamed, it would only make sense to rename the sub-module because that corresponds to the named module block.
Actual Behavior
The local copy of the git repo is renamed to whatever is used for the module name. Worse, when you specify a sub-module within a git repo in the source
using the double slash notation the local copy of the top level repo is renamed to the module block name and the specified sub-module is not renamed.
Notice in the "Steps to Reproduce" that complete
is the sub-module being referenced in the source
block in main.tf
The local directory has the original name from the git repo. But the outer git repo has been renamed to match the name of the module
block "inner_example_complete". This is very confusing and misleading.
Steps to Reproduce
Here is an example with a publicly available sub-module. Note this public example has "//examples" instead of "//modules"
- Create this main.tf:
module "inner_example_complete" {
source = "git::https://github.com/miguelhrocha/terraform-example-module//examples/complete"
}
$ terraform init
- Look at the local directory structure:
"""
$ ls -lA .terraform/modules/
total 8
drwxr-xr-x@ 18 tbye staff 576 Jul 21 11:42 inner_example_complete
drwxr-xr-x@ 18 tbye staff 576 Jul 21 11:42 inner_example_complete.example.this
drwxr-xr-x@ 15 tbye staff 480 Jul 21 11:42 inner_example
$ ls -lA .terraform/modules/inner_example_complete
total 160
-rw-r--r--@ 1 tbye staff 464 Jul 21 11:42 .editorconfig
drwxr-xr-x@ 12 tbye staff 384 Jul 21 11:42 .git
drwxr-xr-x@ 9 tbye staff 288 Jul 21 11:42 .github
-rw-r--r--@ 1 tbye staff 313 Jul 21 11:42 .gitignore
-rw-r--r--@ 1 tbye staff 11346 Jul 21 11:42 LICENSE
-rw-r--r--@ 1 tbye staff 389 Jul 21 11:42 Makefile
-rw-r--r--@ 1 tbye staff 17615 Jul 21 11:42 README.md
-rw-r--r--@ 1 tbye staff 6730 Jul 21 11:42 README.yaml
-rw-r--r--@ 1 tbye staff 10056 Jul 21 11:42 context.tf
drwxr-xr-x@ 4 tbye staff 128 Jul 21 11:42 docs
drwxr-xr-x@ 3 tbye staff 96 Jul 21 11:42 examples
-rw-r--r--@ 1 tbye staff 244 Jul 21 11:42 main.tf
-rw-r--r--@ 1 tbye staff 399 Jul 21 11:42 outputs.tf
drwxr-xr-x@ 6 tbye staff 192 Jul 21 11:42 test
-rw-r--r--@ 1 tbye staff 216 Jul 21 11:42 variables.tf
-rw-r--r--@ 1 tbye staff 222 Jul 21 11:42 versions.tf
"""
Notice in the above the directory "inner_example_complete" is the OUTER module / git repo.
"""
$ ls -lA .terraform/modules/inner_example_complete/examples/complete/
total 72
-rw-r--r--@ 1 tbye staff 10101 Jul 21 11:42 context.tf
-rw-r--r--@ 1 tbye staff 95 Jul 21 11:42 fixtures.us-east-2.tfvars
-rw-r--r--@ 1 tbye staff 98 Jul 21 11:42 main.tf
-rw-r--r--@ 1 tbye staff 327 Jul 21 11:42 outputs.tf
-rw-r--r--@ 1 tbye staff 47 Jul 21 11:42 providers.tf
-rw-r--r--@ 1 tbye staff 117 Jul 21 11:42 variables.tf
-rw-r--r--@ 1 tbye staff 150 Jul 21 11:42 versions.tf
"""
Additional Context
No response
References
No response
Generative AI / LLM assisted development?
No response